Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1 | ---------------------- |
Willy Tarreau | 8317b28 | 2014-04-23 01:49:41 +0200 | [diff] [blame] | 2 | HAProxy |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 3 | Configuration Manual |
| 4 | ---------------------- |
Willy Tarreau | 15480d7 | 2014-06-19 21:10:58 +0200 | [diff] [blame] | 5 | version 1.6 |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 6 | willy tarreau |
Willy Tarreau | a02e8a6 | 2015-09-14 12:23:10 +0200 | [diff] [blame] | 7 | 2015/09/14 |
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 | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13 | The summary below is meant to help you search sections by name and navigate |
| 14 | through the document. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 15 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 16 | Note to documentation contributors : |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 17 | This document is formatted with 80 columns per line, with even number of |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 18 | spaces for indentation and without tabs. Please follow these rules strictly |
| 19 | so that it remains easily printable everywhere. If a line needs to be |
| 20 | printed verbatim and does not fit, please end each line with a backslash |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 21 | ('\') and continue on next line, indented by two characters. It is also |
| 22 | sometimes useful to prefix all output lines (logs, console outs) with 3 |
| 23 | closing angle brackets ('>>>') in order to help get the difference between |
| 24 | inputs and outputs when it can become ambiguous. If you add sections, |
| 25 | please update the summary below for easier searching. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 26 | |
| 27 | |
| 28 | Summary |
| 29 | ------- |
| 30 | |
| 31 | 1. Quick reminder about HTTP |
| 32 | 1.1. The HTTP transaction model |
| 33 | 1.2. HTTP request |
| 34 | 1.2.1. The Request line |
| 35 | 1.2.2. The request headers |
| 36 | 1.3. HTTP response |
| 37 | 1.3.1. The Response line |
| 38 | 1.3.2. The response headers |
| 39 | |
| 40 | 2. Configuring HAProxy |
| 41 | 2.1. Configuration file format |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 42 | 2.2. Quoting and escaping |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 43 | 2.3. Environment variables |
| 44 | 2.4. Time format |
| 45 | 2.5. Examples |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 46 | |
| 47 | 3. Global parameters |
| 48 | 3.1. Process management and security |
| 49 | 3.2. Performance tuning |
| 50 | 3.3. Debugging |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 51 | 3.4. Userlists |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 52 | 3.5. Peers |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 53 | |
| 54 | 4. Proxies |
| 55 | 4.1. Proxy keywords matrix |
| 56 | 4.2. Alphabetically sorted keywords reference |
| 57 | |
Willy Tarreau | 086fbf5 | 2012-09-24 20:34:51 +0200 | [diff] [blame] | 58 | 5. Bind and Server options |
| 59 | 5.1. Bind options |
| 60 | 5.2. Server and default-server options |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 61 | 5.3. Server DNS resolution |
| 62 | 5.3.1. Global overview |
| 63 | 5.3.2. The resolvers section |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 64 | |
| 65 | 6. HTTP header manipulation |
| 66 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 67 | 7. Using ACLs and fetching samples |
| 68 | 7.1. ACL basics |
| 69 | 7.1.1. Matching booleans |
| 70 | 7.1.2. Matching integers |
| 71 | 7.1.3. Matching strings |
| 72 | 7.1.4. Matching regular expressions (regexes) |
| 73 | 7.1.5. Matching arbitrary data blocks |
| 74 | 7.1.6. Matching IPv4 and IPv6 addresses |
| 75 | 7.2. Using ACLs to form conditions |
| 76 | 7.3. Fetching samples |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 77 | 7.3.1. Converters |
| 78 | 7.3.2. Fetching samples from internal states |
| 79 | 7.3.3. Fetching samples at Layer 4 |
| 80 | 7.3.4. Fetching samples at Layer 5 |
| 81 | 7.3.5. Fetching samples from buffer contents (Layer 6) |
| 82 | 7.3.6. Fetching HTTP samples (Layer 7) |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 83 | 7.4. Pre-defined ACLs |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 84 | |
| 85 | 8. Logging |
| 86 | 8.1. Log levels |
| 87 | 8.2. Log formats |
| 88 | 8.2.1. Default log format |
| 89 | 8.2.2. TCP log format |
| 90 | 8.2.3. HTTP log format |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 91 | 8.2.4. Custom log format |
Willy Tarreau | 5f51e1a | 2012-12-03 18:40:10 +0100 | [diff] [blame] | 92 | 8.2.5. Error log format |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 93 | 8.3. Advanced logging options |
| 94 | 8.3.1. Disabling logging of external tests |
| 95 | 8.3.2. Logging before waiting for the session to terminate |
| 96 | 8.3.3. Raising log level upon errors |
| 97 | 8.3.4. Disabling logging of successful connections |
| 98 | 8.4. Timing events |
| 99 | 8.5. Session state at disconnection |
| 100 | 8.6. Non-printable characters |
| 101 | 8.7. Capturing HTTP cookies |
| 102 | 8.8. Capturing HTTP headers |
| 103 | 8.9. Examples of logs |
| 104 | |
| 105 | 9. Statistics and monitoring |
| 106 | 9.1. CSV format |
| 107 | 9.2. Unix Socket commands |
| 108 | |
| 109 | |
| 110 | 1. Quick reminder about HTTP |
| 111 | ---------------------------- |
| 112 | |
| 113 | When haproxy is running in HTTP mode, both the request and the response are |
| 114 | fully analyzed and indexed, thus it becomes possible to build matching criteria |
| 115 | on almost anything found in the contents. |
| 116 | |
| 117 | However, it is important to understand how HTTP requests and responses are |
| 118 | formed, and how HAProxy decomposes them. It will then become easier to write |
| 119 | correct rules and to debug existing configurations. |
| 120 | |
| 121 | |
| 122 | 1.1. The HTTP transaction model |
| 123 | ------------------------------- |
| 124 | |
| 125 | The HTTP protocol is transaction-driven. This means that each request will lead |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 126 | to one and only one response. Traditionally, a TCP connection is established |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 127 | from the client to the server, a request is sent by the client on the |
| 128 | connection, the server responds and the connection is closed. A new request |
| 129 | will involve a new connection : |
| 130 | |
| 131 | [CON1] [REQ1] ... [RESP1] [CLO1] [CON2] [REQ2] ... [RESP2] [CLO2] ... |
| 132 | |
| 133 | In this mode, called the "HTTP close" mode, there are as many connection |
| 134 | establishments as there are HTTP transactions. Since the connection is closed |
| 135 | by the server after the response, the client does not need to know the content |
| 136 | length. |
| 137 | |
| 138 | Due to the transactional nature of the protocol, it was possible to improve it |
| 139 | to avoid closing a connection between two subsequent transactions. In this mode |
| 140 | however, it is mandatory that the server indicates the content length for each |
| 141 | response so that the client does not wait indefinitely. For this, a special |
| 142 | header is used: "Content-length". This mode is called the "keep-alive" mode : |
| 143 | |
| 144 | [CON] [REQ1] ... [RESP1] [REQ2] ... [RESP2] [CLO] ... |
| 145 | |
| 146 | Its advantages are a reduced latency between transactions, and less processing |
| 147 | power required on the server side. It is generally better than the close mode, |
| 148 | but not always because the clients often limit their concurrent connections to |
Patrick Mezard | 9ec2ec4 | 2010-06-12 17:02:45 +0200 | [diff] [blame] | 149 | a smaller value. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 150 | |
| 151 | A last improvement in the communications is the pipelining mode. It still uses |
| 152 | keep-alive, but the client does not wait for the first response to send the |
| 153 | second request. This is useful for fetching large number of images composing a |
| 154 | page : |
| 155 | |
| 156 | [CON] [REQ1] [REQ2] ... [RESP1] [RESP2] [CLO] ... |
| 157 | |
| 158 | This can obviously have a tremendous benefit on performance because the network |
| 159 | latency is eliminated between subsequent requests. Many HTTP agents do not |
| 160 | correctly support pipelining since there is no way to associate a response with |
| 161 | the corresponding request in HTTP. For this reason, it is mandatory for the |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 162 | server to reply in the exact same order as the requests were received. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 163 | |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 164 | By default HAProxy operates in keep-alive mode with regards to persistent |
| 165 | connections: for each connection it processes each request and response, and |
| 166 | leaves the connection idle on both sides between the end of a response and the |
| 167 | start of a new request. |
Patrick Mezard | 9ec2ec4 | 2010-06-12 17:02:45 +0200 | [diff] [blame] | 168 | |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 169 | HAProxy supports 5 connection modes : |
| 170 | - keep alive : all requests and responses are processed (default) |
| 171 | - tunnel : only the first request and response are processed, |
| 172 | everything else is forwarded with no analysis. |
| 173 | - passive close : tunnel with "Connection: close" added in both directions. |
| 174 | - server close : the server-facing connection is closed after the response. |
| 175 | - forced close : the connection is actively closed after end of response. |
| 176 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 177 | |
| 178 | 1.2. HTTP request |
| 179 | ----------------- |
| 180 | |
| 181 | First, let's consider this HTTP request : |
| 182 | |
| 183 | Line Contents |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 184 | number |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 185 | 1 GET /serv/login.php?lang=en&profile=2 HTTP/1.1 |
| 186 | 2 Host: www.mydomain.com |
| 187 | 3 User-agent: my small browser |
| 188 | 4 Accept: image/jpeg, image/gif |
| 189 | 5 Accept: image/png |
| 190 | |
| 191 | |
| 192 | 1.2.1. The Request line |
| 193 | ----------------------- |
| 194 | |
| 195 | Line 1 is the "request line". It is always composed of 3 fields : |
| 196 | |
| 197 | - a METHOD : GET |
| 198 | - a URI : /serv/login.php?lang=en&profile=2 |
| 199 | - a version tag : HTTP/1.1 |
| 200 | |
| 201 | All of them are delimited by what the standard calls LWS (linear white spaces), |
| 202 | which are commonly spaces, but can also be tabs or line feeds/carriage returns |
| 203 | followed by spaces/tabs. The method itself cannot contain any colon (':') and |
| 204 | is limited to alphabetic letters. All those various combinations make it |
| 205 | desirable that HAProxy performs the splitting itself rather than leaving it to |
| 206 | the user to write a complex or inaccurate regular expression. |
| 207 | |
| 208 | The URI itself can have several forms : |
| 209 | |
| 210 | - A "relative URI" : |
| 211 | |
| 212 | /serv/login.php?lang=en&profile=2 |
| 213 | |
| 214 | It is a complete URL without the host part. This is generally what is |
| 215 | received by servers, reverse proxies and transparent proxies. |
| 216 | |
| 217 | - An "absolute URI", also called a "URL" : |
| 218 | |
| 219 | http://192.168.0.12:8080/serv/login.php?lang=en&profile=2 |
| 220 | |
| 221 | It is composed of a "scheme" (the protocol name followed by '://'), a host |
| 222 | name or address, optionally a colon (':') followed by a port number, then |
| 223 | a relative URI beginning at the first slash ('/') after the address part. |
| 224 | This is generally what proxies receive, but a server supporting HTTP/1.1 |
| 225 | must accept this form too. |
| 226 | |
| 227 | - a star ('*') : this form is only accepted in association with the OPTIONS |
| 228 | method and is not relayable. It is used to inquiry a next hop's |
| 229 | capabilities. |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 230 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 231 | - an address:port combination : 192.168.0.12:80 |
| 232 | This is used with the CONNECT method, which is used to establish TCP |
| 233 | tunnels through HTTP proxies, generally for HTTPS, but sometimes for |
| 234 | other protocols too. |
| 235 | |
| 236 | In a relative URI, two sub-parts are identified. The part before the question |
| 237 | mark is called the "path". It is typically the relative path to static objects |
| 238 | on the server. The part after the question mark is called the "query string". |
| 239 | It is mostly used with GET requests sent to dynamic scripts and is very |
| 240 | specific to the language, framework or application in use. |
| 241 | |
| 242 | |
| 243 | 1.2.2. The request headers |
| 244 | -------------------------- |
| 245 | |
| 246 | The headers start at the second line. They are composed of a name at the |
| 247 | beginning of the line, immediately followed by a colon (':'). Traditionally, |
| 248 | an LWS is added after the colon but that's not required. Then come the values. |
| 249 | Multiple identical headers may be folded into one single line, delimiting the |
| 250 | values with commas, provided that their order is respected. This is commonly |
| 251 | encountered in the "Cookie:" field. A header may span over multiple lines if |
| 252 | the subsequent lines begin with an LWS. In the example in 1.2, lines 4 and 5 |
| 253 | define a total of 3 values for the "Accept:" header. |
| 254 | |
| 255 | Contrary to a common mis-conception, header names are not case-sensitive, and |
| 256 | their values are not either if they refer to other header names (such as the |
| 257 | "Connection:" header). |
| 258 | |
| 259 | The end of the headers is indicated by the first empty line. People often say |
| 260 | that it's a double line feed, which is not exact, even if a double line feed |
| 261 | is one valid form of empty line. |
| 262 | |
| 263 | Fortunately, HAProxy takes care of all these complex combinations when indexing |
| 264 | headers, checking values and counting them, so there is no reason to worry |
| 265 | about the way they could be written, but it is important not to accuse an |
| 266 | application of being buggy if it does unusual, valid things. |
| 267 | |
| 268 | Important note: |
| 269 | As suggested by RFC2616, HAProxy normalizes headers by replacing line breaks |
| 270 | in the middle of headers by LWS in order to join multi-line headers. This |
| 271 | is necessary for proper analysis and helps less capable HTTP parsers to work |
| 272 | correctly and not to be fooled by such complex constructs. |
| 273 | |
| 274 | |
| 275 | 1.3. HTTP response |
| 276 | ------------------ |
| 277 | |
| 278 | An HTTP response looks very much like an HTTP request. Both are called HTTP |
| 279 | messages. Let's consider this HTTP response : |
| 280 | |
| 281 | Line Contents |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 282 | number |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 283 | 1 HTTP/1.1 200 OK |
| 284 | 2 Content-length: 350 |
| 285 | 3 Content-Type: text/html |
| 286 | |
Willy Tarreau | 816b979 | 2009-09-15 21:25:21 +0200 | [diff] [blame] | 287 | As a special case, HTTP supports so called "Informational responses" as status |
| 288 | codes 1xx. These messages are special in that they don't convey any part of the |
| 289 | response, they're just used as sort of a signaling message to ask a client to |
Willy Tarreau | 5843d1a | 2010-02-01 15:13:32 +0100 | [diff] [blame] | 290 | continue to post its request for instance. In the case of a status 100 response |
| 291 | the requested information will be carried by the next non-100 response message |
| 292 | following the informational one. This implies that multiple responses may be |
| 293 | sent to a single request, and that this only works when keep-alive is enabled |
| 294 | (1xx messages are HTTP/1.1 only). HAProxy handles these messages and is able to |
| 295 | correctly forward and skip them, and only process the next non-100 response. As |
| 296 | such, these messages are neither logged nor transformed, unless explicitly |
| 297 | state otherwise. Status 101 messages indicate that the protocol is changing |
| 298 | over the same connection and that haproxy must switch to tunnel mode, just as |
| 299 | if a CONNECT had occurred. Then the Upgrade header would contain additional |
| 300 | information about the type of protocol the connection is switching to. |
Willy Tarreau | 816b979 | 2009-09-15 21:25:21 +0200 | [diff] [blame] | 301 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 302 | |
| 303 | 1.3.1. The Response line |
| 304 | ------------------------ |
| 305 | |
| 306 | Line 1 is the "response line". It is always composed of 3 fields : |
| 307 | |
| 308 | - a version tag : HTTP/1.1 |
| 309 | - a status code : 200 |
| 310 | - a reason : OK |
| 311 | |
| 312 | The status code is always 3-digit. The first digit indicates a general status : |
Willy Tarreau | 816b979 | 2009-09-15 21:25:21 +0200 | [diff] [blame] | 313 | - 1xx = informational message to be skipped (eg: 100, 101) |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 314 | - 2xx = OK, content is following (eg: 200, 206) |
| 315 | - 3xx = OK, no content following (eg: 302, 304) |
| 316 | - 4xx = error caused by the client (eg: 401, 403, 404) |
| 317 | - 5xx = error caused by the server (eg: 500, 502, 503) |
| 318 | |
| 319 | Please refer to RFC2616 for the detailed meaning of all such codes. The |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 320 | "reason" field is just a hint, but is not parsed by clients. Anything can be |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 321 | found there, but it's a common practice to respect the well-established |
| 322 | messages. It can be composed of one or multiple words, such as "OK", "Found", |
| 323 | or "Authentication Required". |
| 324 | |
| 325 | Haproxy may emit the following status codes by itself : |
| 326 | |
| 327 | Code When / reason |
| 328 | 200 access to stats page, and when replying to monitoring requests |
| 329 | 301 when performing a redirection, depending on the configured code |
| 330 | 302 when performing a redirection, depending on the configured code |
| 331 | 303 when performing a redirection, depending on the configured code |
Willy Tarreau | b67fdc4 | 2013-03-29 19:28:11 +0100 | [diff] [blame] | 332 | 307 when performing a redirection, depending on the configured code |
| 333 | 308 when performing a redirection, depending on the configured code |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 334 | 400 for an invalid or too large request |
| 335 | 401 when an authentication is required to perform the action (when |
| 336 | accessing the stats page) |
| 337 | 403 when a request is forbidden by a "block" ACL or "reqdeny" filter |
| 338 | 408 when the request timeout strikes before the request is complete |
| 339 | 500 when haproxy encounters an unrecoverable internal error, such as a |
| 340 | memory allocation failure, which should never happen |
| 341 | 502 when the server returns an empty, invalid or incomplete response, or |
| 342 | when an "rspdeny" filter blocks the response. |
| 343 | 503 when no server was available to handle the request, or in response to |
| 344 | monitoring requests which match the "monitor fail" condition |
| 345 | 504 when the response timeout strikes before the server responds |
| 346 | |
| 347 | The error 4xx and 5xx codes above may be customized (see "errorloc" in section |
| 348 | 4.2). |
| 349 | |
| 350 | |
| 351 | 1.3.2. The response headers |
| 352 | --------------------------- |
| 353 | |
| 354 | Response headers work exactly like request headers, and as such, HAProxy uses |
| 355 | the same parsing function for both. Please refer to paragraph 1.2.2 for more |
| 356 | details. |
| 357 | |
| 358 | |
| 359 | 2. Configuring HAProxy |
| 360 | ---------------------- |
| 361 | |
| 362 | 2.1. Configuration file format |
| 363 | ------------------------------ |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 364 | |
| 365 | HAProxy's configuration process involves 3 major sources of parameters : |
| 366 | |
| 367 | - the arguments from the command-line, which always take precedence |
| 368 | - the "global" section, which sets process-wide parameters |
| 369 | - the proxies sections which can take form of "defaults", "listen", |
| 370 | "frontend" and "backend". |
| 371 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 372 | The configuration file syntax consists in lines beginning with a keyword |
| 373 | referenced in this manual, optionally followed by one or several parameters |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 374 | delimited by spaces. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 375 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 376 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 377 | 2.2. Quoting and escaping |
| 378 | ------------------------- |
| 379 | |
| 380 | HAProxy's configuration introduces a quoting and escaping system similar to |
| 381 | many programming languages. The configuration file supports 3 types: escaping |
| 382 | with a backslash, weak quoting with double quotes, and strong quoting with |
| 383 | single quotes. |
| 384 | |
| 385 | If spaces have to be entered in strings, then they must be escaped by preceding |
| 386 | them by a backslash ('\') or by quoting them. Backslashes also have to be |
| 387 | escaped by doubling or strong quoting them. |
| 388 | |
| 389 | Escaping is achieved by preceding a special character by a backslash ('\'): |
| 390 | |
| 391 | \ to mark a space and differentiate it from a delimiter |
| 392 | \# to mark a hash and differentiate it from a comment |
| 393 | \\ to use a backslash |
| 394 | \' to use a single quote and differentiate it from strong quoting |
| 395 | \" to use a double quote and differentiate it from weak quoting |
| 396 | |
| 397 | Weak quoting is achieved by using double quotes (""). Weak quoting prevents |
| 398 | the interpretation of: |
| 399 | |
| 400 | space as a parameter separator |
| 401 | ' single quote as a strong quoting delimiter |
| 402 | # hash as a comment start |
| 403 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 404 | Weak quoting permits the interpretation of variables, if you want to use a non |
| 405 | -interpreted dollar within a double quoted string, you should escape it with a |
| 406 | backslash ("\$"), it does not work outside weak quoting. |
| 407 | |
| 408 | Interpretation of escaping and special characters are not prevented by weak |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 409 | quoting. |
| 410 | |
| 411 | Strong quoting is achieved by using single quotes (''). Inside single quotes, |
| 412 | nothing is interpreted, it's the efficient way to quote regexes. |
| 413 | |
| 414 | Quoted and escaped strings are replaced in memory by their interpreted |
| 415 | equivalent, it allows you to perform concatenation. |
| 416 | |
| 417 | Example: |
| 418 | # those are equivalents: |
| 419 | log-format %{+Q}o\ %t\ %s\ %{-Q}r |
| 420 | log-format "%{+Q}o %t %s %{-Q}r" |
| 421 | log-format '%{+Q}o %t %s %{-Q}r' |
| 422 | log-format "%{+Q}o %t"' %s %{-Q}r' |
| 423 | log-format "%{+Q}o %t"' %s'\ %{-Q}r |
| 424 | |
| 425 | # those are equivalents: |
| 426 | reqrep "^([^\ :]*)\ /static/(.*)" \1\ /\2 |
| 427 | reqrep "^([^ :]*)\ /static/(.*)" '\1 /\2' |
| 428 | reqrep "^([^ :]*)\ /static/(.*)" "\1 /\2" |
| 429 | reqrep "^([^ :]*)\ /static/(.*)" "\1\ /\2" |
| 430 | |
| 431 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 432 | 2.3. Environment variables |
| 433 | -------------------------- |
| 434 | |
| 435 | HAProxy's configuration supports environment variables. Those variables are |
| 436 | interpreted only within double quotes. Variables are expanded during the |
| 437 | configuration parsing. Variable names must be preceded by a dollar ("$") and |
| 438 | optionally enclosed with braces ("{}") similarly to what is done in Bourne |
| 439 | shell. Variable names can contain alphanumerical characters or the character |
| 440 | underscore ("_") but should not start with a digit. |
| 441 | |
| 442 | Example: |
| 443 | |
| 444 | bind "fd@${FD_APP1}" |
| 445 | |
| 446 | log "${LOCAL_SYSLOG}:514" local0 notice # send to local server |
| 447 | |
| 448 | user "$HAPROXY_USER" |
| 449 | |
| 450 | |
| 451 | 2.4. Time format |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 452 | ---------------- |
| 453 | |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 454 | Some parameters involve values representing time, such as timeouts. These |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 455 | values are generally expressed in milliseconds (unless explicitly stated |
| 456 | otherwise) but may be expressed in any other unit by suffixing the unit to the |
| 457 | numeric value. It is important to consider this because it will not be repeated |
| 458 | for every keyword. Supported units are : |
| 459 | |
| 460 | - us : microseconds. 1 microsecond = 1/1000000 second |
| 461 | - ms : milliseconds. 1 millisecond = 1/1000 second. This is the default. |
| 462 | - s : seconds. 1s = 1000ms |
| 463 | - m : minutes. 1m = 60s = 60000ms |
| 464 | - h : hours. 1h = 60m = 3600s = 3600000ms |
| 465 | - d : days. 1d = 24h = 1440m = 86400s = 86400000ms |
| 466 | |
| 467 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 468 | 2.4. Examples |
Patrick Mezard | 35da19c | 2010-06-12 17:02:47 +0200 | [diff] [blame] | 469 | ------------- |
| 470 | |
| 471 | # Simple configuration for an HTTP proxy listening on port 80 on all |
| 472 | # interfaces and forwarding requests to a single backend "servers" with a |
| 473 | # single server "server1" listening on 127.0.0.1:8000 |
| 474 | global |
| 475 | daemon |
| 476 | maxconn 256 |
| 477 | |
| 478 | defaults |
| 479 | mode http |
| 480 | timeout connect 5000ms |
| 481 | timeout client 50000ms |
| 482 | timeout server 50000ms |
| 483 | |
| 484 | frontend http-in |
| 485 | bind *:80 |
| 486 | default_backend servers |
| 487 | |
| 488 | backend servers |
| 489 | server server1 127.0.0.1:8000 maxconn 32 |
| 490 | |
| 491 | |
| 492 | # The same configuration defined with a single listen block. Shorter but |
| 493 | # less expressive, especially in HTTP mode. |
| 494 | global |
| 495 | daemon |
| 496 | maxconn 256 |
| 497 | |
| 498 | defaults |
| 499 | mode http |
| 500 | timeout connect 5000ms |
| 501 | timeout client 50000ms |
| 502 | timeout server 50000ms |
| 503 | |
| 504 | listen http-in |
| 505 | bind *:80 |
| 506 | server server1 127.0.0.1:8000 maxconn 32 |
| 507 | |
| 508 | |
| 509 | Assuming haproxy is in $PATH, test these configurations in a shell with: |
| 510 | |
Willy Tarreau | ccb289d | 2010-12-11 20:19:38 +0100 | [diff] [blame] | 511 | $ sudo haproxy -f configuration.conf -c |
Patrick Mezard | 35da19c | 2010-06-12 17:02:47 +0200 | [diff] [blame] | 512 | |
| 513 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 514 | 3. Global parameters |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 515 | -------------------- |
| 516 | |
| 517 | Parameters in the "global" section are process-wide and often OS-specific. They |
| 518 | are generally set once for all and do not need being changed once correct. Some |
| 519 | of them have command-line equivalents. |
| 520 | |
| 521 | The following keywords are supported in the "global" section : |
| 522 | |
| 523 | * Process management and security |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 524 | - ca-base |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 525 | - chroot |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 526 | - crt-base |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 527 | - daemon |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 528 | - external-check |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 529 | - gid |
| 530 | - group |
| 531 | - log |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 532 | - log-send-hostname |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 533 | - nbproc |
| 534 | - pidfile |
| 535 | - uid |
| 536 | - ulimit-n |
| 537 | - user |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 538 | - stats |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 539 | - ssl-server-verify |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 540 | - node |
| 541 | - description |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 542 | - unix-bind |
Thomas Holmes | db04f19 | 2015-05-18 13:21:39 +0100 | [diff] [blame] | 543 | - 51degrees-data-file |
| 544 | - 51degrees-property-name-list |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 545 | - 51degrees-property-separator |
Dragan Dosen | ae6d39a | 2015-06-29 16:43:27 +0200 | [diff] [blame] | 546 | - 51degrees-cache-size |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 547 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 548 | * Performance tuning |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 549 | - max-spread-checks |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 550 | - maxconn |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 551 | - maxconnrate |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 552 | - maxcomprate |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 553 | - maxcompcpuusage |
Willy Tarreau | ff4f82d | 2009-02-06 11:28:13 +0100 | [diff] [blame] | 554 | - maxpipes |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 555 | - maxsessrate |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 556 | - maxsslconn |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 557 | - maxsslrate |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 558 | - noepoll |
| 559 | - nokqueue |
| 560 | - nopoll |
Willy Tarreau | ff4f82d | 2009-02-06 11:28:13 +0100 | [diff] [blame] | 561 | - nosplice |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 562 | - nogetaddrinfo |
Willy Tarreau | fe255b7 | 2007-10-14 23:09:26 +0200 | [diff] [blame] | 563 | - spread-checks |
Baptiste Assmann | 5626f48 | 2015-08-23 10:00:10 +0200 | [diff] [blame] | 564 | - server-state-base |
Baptiste Assmann | ef1f0fc | 2015-08-23 10:06:39 +0200 | [diff] [blame] | 565 | - server-state-file |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 566 | - tune.bufsize |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 567 | - tune.chksize |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 568 | - tune.comp.maxlevel |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 569 | - tune.http.cookielen |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 570 | - tune.http.maxhdr |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 571 | - tune.idletimer |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 572 | - tune.lua.forced-yield |
Willy Tarreau | 32f61e2 | 2015-03-18 17:54:59 +0100 | [diff] [blame] | 573 | - tune.lua.maxmem |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 574 | - tune.lua.session-timeout |
| 575 | - tune.lua.task-timeout |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 576 | - tune.maxaccept |
| 577 | - tune.maxpollevents |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 578 | - tune.maxrewrite |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 579 | - tune.pattern.cache-size |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 580 | - tune.pipesize |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 581 | - tune.rcvbuf.client |
| 582 | - tune.rcvbuf.server |
| 583 | - tune.sndbuf.client |
| 584 | - tune.sndbuf.server |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 585 | - tune.ssl.cachesize |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 586 | - tune.ssl.lifetime |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 587 | - tune.ssl.force-private-cache |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 588 | - tune.ssl.maxrecord |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 589 | - tune.ssl.default-dh-param |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 590 | - tune.ssl.ssl-ctx-cache-size |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 591 | - tune.vars.global-max-size |
| 592 | - tune.vars.reqres-max-size |
| 593 | - tune.vars.sess-max-size |
| 594 | - tune.vars.txn-max-size |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 595 | - tune.zlib.memlevel |
| 596 | - tune.zlib.windowsize |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 597 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 598 | * Debugging |
| 599 | - debug |
| 600 | - quiet |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 601 | |
| 602 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 603 | 3.1. Process management and security |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 604 | ------------------------------------ |
| 605 | |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 606 | ca-base <dir> |
| 607 | Assigns a default directory to fetch SSL CA certificates and CRLs from when a |
Emeric Brun | fd33a26 | 2012-10-11 16:28:27 +0200 | [diff] [blame] | 608 | relative path is used with "ca-file" or "crl-file" directives. Absolute |
| 609 | locations specified in "ca-file" and "crl-file" prevail and ignore "ca-base". |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 610 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 611 | chroot <jail dir> |
| 612 | Changes current directory to <jail dir> and performs a chroot() there before |
| 613 | dropping privileges. This increases the security level in case an unknown |
| 614 | vulnerability would be exploited, since it would make it very hard for the |
| 615 | attacker to exploit the system. This only works when the process is started |
| 616 | with superuser privileges. It is important to ensure that <jail_dir> is both |
| 617 | empty and unwritable to anyone. |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 618 | |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 619 | cpu-map <"all"|"odd"|"even"|process_num> <cpu-set>... |
| 620 | On Linux 2.6 and above, it is possible to bind a process to a specific CPU |
| 621 | set. This means that the process will never run on other CPUs. The "cpu-map" |
| 622 | directive specifies CPU sets for process sets. The first argument is the |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 623 | process number to bind. This process must have a number between 1 and 32 or |
| 624 | 64, depending on the machine's word size, and any process IDs above nbproc |
| 625 | are ignored. It is possible to specify all processes at once using "all", |
| 626 | only odd numbers using "odd" or even numbers using "even", just like with the |
| 627 | "bind-process" directive. The second and forthcoming arguments are CPU sets. |
| 628 | Each CPU set is either a unique number between 0 and 31 or 63 or a range with |
| 629 | two such numbers delimited by a dash ('-'). Multiple CPU numbers or ranges |
| 630 | may be specified, and the processes will be allowed to bind to all of them. |
| 631 | Obviously, multiple "cpu-map" directives may be specified. Each "cpu-map" |
| 632 | directive will replace the previous ones when they overlap. |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 633 | |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 634 | crt-base <dir> |
| 635 | Assigns a default directory to fetch SSL certificates from when a relative |
| 636 | path is used with "crtfile" directives. Absolute locations specified after |
| 637 | "crtfile" prevail and ignore "crt-base". |
| 638 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 639 | daemon |
| 640 | Makes the process fork into background. This is the recommended mode of |
| 641 | operation. It is equivalent to the command line "-D" argument. It can be |
| 642 | disabled by the command line "-db" argument. |
| 643 | |
David Carlier | 8167f30 | 2015-06-01 13:50:06 +0200 | [diff] [blame] | 644 | deviceatlas-json-file <path> |
| 645 | Sets the path of the DeviceAtlas JSON data file to be loaded by the API. |
| 646 | The path must be a valid JSON data file and accessible by Haproxy process. |
| 647 | |
| 648 | deviceatlas-log-level <value> |
| 649 | Sets the level of informations returned by the API. This directive is |
| 650 | optional and set to 0 by default if not set. |
| 651 | |
| 652 | deviceatlas-separator <char> |
| 653 | Sets the character separator for the API properties results. This directive |
| 654 | is optional and set to | by default if not set. |
| 655 | |
David Carlier | 29b3ca3 | 2015-09-25 14:09:21 +0100 | [diff] [blame] | 656 | devicatlas-properties-cookie <name> |
| 657 | Sets the client cookie's name used for the detection if the DeviceAtlas Client-side |
| 658 | component was used during the request. This directive is optional and set to |
| 659 | DAPROPS by default if not set. |
| 660 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 661 | external-check |
| 662 | Allows the use of an external agent to perform health checks. |
| 663 | This is disabled by default as a security precaution. |
| 664 | See "option external-check". |
| 665 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 666 | gid <number> |
| 667 | Changes the process' group ID to <number>. It is recommended that the group |
| 668 | ID is dedicated to HAProxy or to a small set of similar daemons. HAProxy must |
| 669 | be started with a user belonging to this group, or with superuser privileges. |
Michael Scherer | ab012dd | 2013-01-12 18:35:19 +0100 | [diff] [blame] | 670 | Note that if haproxy is started from a user having supplementary groups, it |
| 671 | will only be able to drop these groups if started with superuser privileges. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 672 | See also "group" and "uid". |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 673 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 674 | group <group name> |
| 675 | Similar to "gid" but uses the GID of group name <group name> from /etc/group. |
| 676 | See also "gid" and "user". |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 677 | |
Dragan Dosen | 7ad3154 | 2015-09-28 17:16:47 +0200 | [diff] [blame] | 678 | log <address> [len <length>] [format <format>] <facility> [max level [min level]] |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 679 | Adds a global syslog server. Up to two global servers can be defined. They |
| 680 | 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] | 681 | configured with "log global". |
| 682 | |
| 683 | <address> can be one of: |
| 684 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 685 | - 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] | 686 | no port is specified, 514 is used by default (the standard syslog |
| 687 | port). |
| 688 | |
David du Colombier | 24bb5f5 | 2011-03-17 10:40:23 +0100 | [diff] [blame] | 689 | - An IPv6 address followed by a colon and optionally a UDP port. If |
| 690 | no port is specified, 514 is used by default (the standard syslog |
| 691 | port). |
| 692 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 693 | - A filesystem path to a UNIX domain socket, keeping in mind |
| 694 | considerations for chroot (be sure the path is accessible inside |
| 695 | the chroot) and uid/gid (be sure the path is appropriately |
| 696 | writeable). |
| 697 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 698 | You may want to reference some environment variables in the address |
| 699 | parameter, see section 2.3 about environment variables. |
Willy Tarreau | dad36a3 | 2013-03-11 01:20:04 +0100 | [diff] [blame] | 700 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 701 | <length> is an optional maximum line length. Log lines larger than this value |
| 702 | will be truncated before being sent. The reason is that syslog |
| 703 | servers act differently on log line length. All servers support the |
| 704 | default value of 1024, but some servers simply drop larger lines |
| 705 | while others do log them. If a server supports long lines, it may |
| 706 | make sense to set this value here in order to avoid truncating long |
| 707 | lines. Similarly, if a server drops long lines, it is preferable to |
| 708 | truncate them before sending them. Accepted values are 80 to 65535 |
| 709 | inclusive. The default value of 1024 is generally fine for all |
| 710 | standard usages. Some specific cases of long captures or |
| 711 | JSON-formated logs may require larger values. |
| 712 | |
Dragan Dosen | 7ad3154 | 2015-09-28 17:16:47 +0200 | [diff] [blame] | 713 | <format> is the log format used when generating syslog messages. It may be |
| 714 | one of the following : |
| 715 | |
| 716 | rfc3164 The RFC3164 syslog message format. This is the default. |
| 717 | (https://tools.ietf.org/html/rfc3164) |
| 718 | |
| 719 | rfc5424 The RFC5424 syslog message format. |
| 720 | (https://tools.ietf.org/html/rfc5424) |
| 721 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 722 | <facility> must be one of the 24 standard syslog facilities : |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 723 | |
| 724 | kern user mail daemon auth syslog lpr news |
| 725 | uucp cron auth2 ftp ntp audit alert cron2 |
| 726 | local0 local1 local2 local3 local4 local5 local6 local7 |
| 727 | |
| 728 | An optional level can be specified to filter outgoing messages. By default, |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 729 | all messages are sent. If a maximum level is specified, only messages with a |
| 730 | severity at least as important as this level will be sent. An optional minimum |
| 731 | level can be specified. If it is set, logs emitted with a more severe level |
| 732 | than this one will be capped to this level. This is used to avoid sending |
| 733 | "emerg" messages on all terminals on some default syslog configurations. |
| 734 | Eight levels are known : |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 735 | |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 736 | emerg alert crit err warning notice info debug |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 737 | |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 738 | log-send-hostname [<string>] |
| 739 | Sets the hostname field in the syslog header. If optional "string" parameter |
| 740 | is set the header is set to the string contents, otherwise uses the hostname |
| 741 | of the system. Generally used if one is not relaying logs through an |
| 742 | intermediate syslog server or for simply customizing the hostname printed in |
| 743 | the logs. |
| 744 | |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 745 | log-tag <string> |
| 746 | Sets the tag field in the syslog header to this string. It defaults to the |
| 747 | program name as launched from the command line, which usually is "haproxy". |
| 748 | Sometimes it can be useful to differentiate between multiple processes |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 749 | running on the same host. See also the per-proxy "log-tag" directive. |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 750 | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 751 | lua-load <file> |
| 752 | This global directive loads and executes a Lua file. This directive can be |
| 753 | used multiple times. |
| 754 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 755 | nbproc <number> |
| 756 | Creates <number> processes when going daemon. This requires the "daemon" |
| 757 | mode. By default, only one process is created, which is the recommended mode |
| 758 | of operation. For systems limited to small sets of file descriptors per |
| 759 | process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES |
| 760 | IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon". |
| 761 | |
| 762 | pidfile <pidfile> |
| 763 | Writes pids of all daemons into file <pidfile>. This option is equivalent to |
| 764 | the "-p" command line argument. The file must be accessible to the user |
| 765 | starting the process. See also "daemon". |
| 766 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 767 | stats bind-process [ all | odd | even | <number 1-64>[-<number 1-64>] ] ... |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 768 | Limits the stats socket to a certain set of processes numbers. By default the |
| 769 | stats socket is bound to all processes, causing a warning to be emitted when |
| 770 | nbproc is greater than 1 because there is no way to select the target process |
| 771 | when connecting. However, by using this setting, it becomes possible to pin |
| 772 | the stats socket to a specific set of processes, typically the first one. The |
| 773 | warning will automatically be disabled when this setting is used, whatever |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 774 | the number of processes used. The maximum process ID depends on the machine's |
Willy Tarreau | ae30253 | 2014-05-07 19:22:24 +0200 | [diff] [blame] | 775 | word size (32 or 64). A better option consists in using the "process" setting |
| 776 | of the "stats socket" line to force the process on each line. |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 777 | |
Baptiste Assmann | 5626f48 | 2015-08-23 10:00:10 +0200 | [diff] [blame] | 778 | server-state-base <directory> |
| 779 | Specifies the directory prefix to be prepended in front of all servers state |
Baptiste Assmann | 01c6cc3 | 2015-08-23 11:45:29 +0200 | [diff] [blame] | 780 | file names which do not start with a '/'. See also "server-state-file", |
| 781 | "load-server-state-from-file" and "server-state-file-name". |
Baptiste Assmann | ef1f0fc | 2015-08-23 10:06:39 +0200 | [diff] [blame] | 782 | |
| 783 | server-state-file <file> |
| 784 | Specifies the path to the file containing state of servers. If the path starts |
| 785 | with a slash ('/'), it is considered absolute, otherwise it is considered |
| 786 | relative to the directory specified using "server-state-base" (if set) or to |
| 787 | the current directory. Before reloading HAProxy, it is possible to save the |
| 788 | servers' current state using the stats command "show servers state". The |
| 789 | output of this command must be written in the file pointed by <file>. When |
| 790 | starting up, before handling traffic, HAProxy will read, load and apply state |
| 791 | for each server found in the file and available in its current running |
Baptiste Assmann | 01c6cc3 | 2015-08-23 11:45:29 +0200 | [diff] [blame] | 792 | configuration. See also "server-state-base" and "show servers state", |
| 793 | "load-server-state-from-file" and "server-state-file-name" |
Baptiste Assmann | 5626f48 | 2015-08-23 10:00:10 +0200 | [diff] [blame] | 794 | |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 795 | ssl-default-bind-ciphers <ciphers> |
| 796 | This setting is only available when support for OpenSSL was built in. It sets |
| 797 | the default string describing the list of cipher algorithms ("cipher suite") |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 798 | that are negotiated during the SSL/TLS handshake for all "bind" lines which |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 799 | do not explicitly define theirs. The format of the string is defined in |
| 800 | "man 1 ciphers" from OpenSSL man pages, and can be for instance a string such |
| 801 | as "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" (without quotes). Please check the |
| 802 | "bind" keyword for more information. |
| 803 | |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 804 | ssl-default-bind-options [<option>]... |
| 805 | This setting is only available when support for OpenSSL was built in. It sets |
| 806 | default ssl-options to force on all "bind" lines. Please check the "bind" |
| 807 | keyword to see available options. |
| 808 | |
| 809 | Example: |
| 810 | global |
| 811 | ssl-default-bind-options no-sslv3 no-tls-tickets |
| 812 | |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 813 | ssl-default-server-ciphers <ciphers> |
| 814 | This setting is only available when support for OpenSSL was built in. It |
| 815 | sets the default string describing the list of cipher algorithms that are |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 816 | negotiated during the SSL/TLS handshake with the server, for all "server" |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 817 | lines which do not explicitly define theirs. The format of the string is |
| 818 | defined in "man 1 ciphers". Please check the "server" keyword for more |
| 819 | information. |
| 820 | |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 821 | ssl-default-server-options [<option>]... |
| 822 | This setting is only available when support for OpenSSL was built in. It sets |
| 823 | default ssl-options to force on all "server" lines. Please check the "server" |
| 824 | keyword to see available options. |
| 825 | |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 826 | ssl-dh-param-file <file> |
| 827 | This setting is only available when support for OpenSSL was built in. It sets |
| 828 | the default DH parameters that are used during the SSL/TLS handshake when |
| 829 | ephemeral Diffie-Hellman (DHE) key exchange is used, for all "bind" lines |
| 830 | which do not explicitely define theirs. It will be overridden by custom DH |
| 831 | parameters found in a bind certificate file if any. If custom DH parameters |
| 832 | are not specified either by using ssl-dh-param-file or by setting them directly |
| 833 | in the certificate file, pre-generated DH parameters of the size specified |
| 834 | by tune.ssl.default-dh-param will be used. Custom parameters are known to be |
| 835 | more secure and therefore their use is recommended. |
| 836 | Custom DH parameters may be generated by using the OpenSSL command |
| 837 | "openssl dhparam <size>", where size should be at least 2048, as 1024-bit DH |
| 838 | parameters should not be considered secure anymore. |
| 839 | |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 840 | ssl-server-verify [none|required] |
| 841 | The default behavior for SSL verify on servers side. If specified to 'none', |
| 842 | servers certificates are not verified. The default is 'required' except if |
| 843 | forced using cmdline option '-dV'. |
| 844 | |
Willy Tarreau | abb175f | 2012-09-24 12:43:26 +0200 | [diff] [blame] | 845 | stats socket [<address:port>|<path>] [param*] |
| 846 | Binds a UNIX socket to <path> or a TCPv4/v6 address to <address:port>. |
| 847 | Connections to this socket will return various statistics outputs and even |
| 848 | allow some commands to be issued to change some runtime settings. Please |
| 849 | consult section 9.2 "Unix Socket commands" for more details. |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 850 | |
Willy Tarreau | abb175f | 2012-09-24 12:43:26 +0200 | [diff] [blame] | 851 | All parameters supported by "bind" lines are supported, for instance to |
| 852 | restrict access to some users or their access rights. Please consult |
| 853 | section 5.1 for more information. |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 854 | |
| 855 | stats timeout <timeout, in milliseconds> |
| 856 | The default timeout on the stats socket is set to 10 seconds. It is possible |
| 857 | 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] | 858 | 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] | 859 | |
| 860 | stats maxconn <connections> |
| 861 | By default, the stats socket is limited to 10 concurrent connections. It is |
| 862 | possible to change this value with "stats maxconn". |
| 863 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 864 | uid <number> |
| 865 | Changes the process' user ID to <number>. It is recommended that the user ID |
| 866 | is dedicated to HAProxy or to a small set of similar daemons. HAProxy must |
| 867 | be started with superuser privileges in order to be able to switch to another |
| 868 | one. See also "gid" and "user". |
| 869 | |
| 870 | ulimit-n <number> |
| 871 | Sets the maximum number of per-process file-descriptors to <number>. By |
| 872 | default, it is automatically computed, so it is recommended not to use this |
| 873 | option. |
| 874 | |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 875 | unix-bind [ prefix <prefix> ] [ mode <mode> ] [ user <user> ] [ uid <uid> ] |
| 876 | [ group <group> ] [ gid <gid> ] |
| 877 | |
| 878 | Fixes common settings to UNIX listening sockets declared in "bind" statements. |
| 879 | This is mainly used to simplify declaration of those UNIX sockets and reduce |
| 880 | the risk of errors, since those settings are most commonly required but are |
| 881 | also process-specific. The <prefix> setting can be used to force all socket |
| 882 | path to be relative to that directory. This might be needed to access another |
| 883 | component's chroot. Note that those paths are resolved before haproxy chroots |
| 884 | itself, so they are absolute. The <mode>, <user>, <uid>, <group> and <gid> |
| 885 | all have the same meaning as their homonyms used by the "bind" statement. If |
| 886 | both are specified, the "bind" statement has priority, meaning that the |
| 887 | "unix-bind" settings may be seen as process-wide default settings. |
| 888 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 889 | user <user name> |
| 890 | Similar to "uid" but uses the UID of user name <user name> from /etc/passwd. |
| 891 | See also "uid" and "group". |
| 892 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 893 | node <name> |
| 894 | Only letters, digits, hyphen and underscore are allowed, like in DNS names. |
| 895 | |
| 896 | This statement is useful in HA configurations where two or more processes or |
| 897 | servers share the same IP address. By setting a different node-name on all |
| 898 | nodes, it becomes easy to immediately spot what server is handling the |
| 899 | traffic. |
| 900 | |
| 901 | description <text> |
| 902 | Add a text that describes the instance. |
| 903 | |
| 904 | Please note that it is required to escape certain characters (# for example) |
| 905 | and this text is inserted into a html page so you should avoid using |
| 906 | "<" and ">" characters. |
| 907 | |
Thomas Holmes | db04f19 | 2015-05-18 13:21:39 +0100 | [diff] [blame] | 908 | 51degrees-data-file <file path> |
| 909 | The path of the 51Degrees data file to provide device detection services. The |
| 910 | file should be unzipped and accessible by HAProxy with relevavnt permissions. |
| 911 | |
Dragan Dosen | ae6d39a | 2015-06-29 16:43:27 +0200 | [diff] [blame] | 912 | Please note that this option is only available when haproxy has been |
Thomas Holmes | db04f19 | 2015-05-18 13:21:39 +0100 | [diff] [blame] | 913 | compiled with USE_51DEGREES. |
| 914 | |
| 915 | 51degrees-property-name-list [<string>] |
| 916 | A list of 51Degrees property names to be load from the dataset. A full list |
| 917 | of names is available on the 51Degrees website: |
| 918 | https://51degrees.com/resources/property-dictionary |
| 919 | |
Dragan Dosen | ae6d39a | 2015-06-29 16:43:27 +0200 | [diff] [blame] | 920 | Please note that this option is only available when haproxy has been |
Thomas Holmes | db04f19 | 2015-05-18 13:21:39 +0100 | [diff] [blame] | 921 | compiled with USE_51DEGREES. |
| 922 | |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 923 | 51degrees-property-separator <char> |
Thomas Holmes | db04f19 | 2015-05-18 13:21:39 +0100 | [diff] [blame] | 924 | A char that will be appended to every property value in a response header |
| 925 | containing 51Degrees results. If not set that will be set as ','. |
| 926 | |
Dragan Dosen | ae6d39a | 2015-06-29 16:43:27 +0200 | [diff] [blame] | 927 | Please note that this option is only available when haproxy has been |
| 928 | compiled with USE_51DEGREES. |
| 929 | |
| 930 | 51degrees-cache-size <number> |
| 931 | Sets the size of the 51Degrees converter cache to <number> entries. This |
| 932 | is an LRU cache which reminds previous device detections and their results. |
| 933 | By default, this cache is disabled. |
| 934 | |
| 935 | Please note that this option is only available when haproxy has been |
Thomas Holmes | db04f19 | 2015-05-18 13:21:39 +0100 | [diff] [blame] | 936 | compiled with USE_51DEGREES. |
| 937 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 938 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 939 | 3.2. Performance tuning |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 940 | ----------------------- |
| 941 | |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 942 | max-spread-checks <delay in milliseconds> |
| 943 | By default, haproxy tries to spread the start of health checks across the |
| 944 | smallest health check interval of all the servers in a farm. The principle is |
| 945 | to avoid hammering services running on the same server. But when using large |
| 946 | check intervals (10 seconds or more), the last servers in the farm take some |
| 947 | time before starting to be tested, which can be a problem. This parameter is |
| 948 | used to enforce an upper bound on delay between the first and the last check, |
| 949 | even if the servers' check intervals are larger. When servers run with |
| 950 | shorter intervals, their intervals will be respected though. |
| 951 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 952 | maxconn <number> |
| 953 | Sets the maximum per-process number of concurrent connections to <number>. It |
| 954 | is equivalent to the command-line argument "-n". Proxies will stop accepting |
| 955 | connections when this limit is reached. The "ulimit-n" parameter is |
Willy Tarreau | 8274e10 | 2014-06-19 15:31:25 +0200 | [diff] [blame] | 956 | automatically adjusted according to this value. See also "ulimit-n". Note: |
| 957 | the "select" poller cannot reliably use more than 1024 file descriptors on |
| 958 | some platforms. If your platform only supports select and reports "select |
| 959 | FAILED" on startup, you need to reduce maxconn until it works (slightly |
Willy Tarreau | d025648 | 2015-01-15 21:45:22 +0100 | [diff] [blame] | 960 | below 500 in general). If this value is not set, it will default to the value |
| 961 | set in DEFAULT_MAXCONN at build time (reported in haproxy -vv) if no memory |
| 962 | limit is enforced, or will be computed based on the memory limit, the buffer |
| 963 | size, memory allocated to compression, SSL cache size, and use or not of SSL |
| 964 | and the associated maxsslconn (which can also be automatic). |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 965 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 966 | maxconnrate <number> |
| 967 | Sets the maximum per-process number of connections per second to <number>. |
| 968 | Proxies will stop accepting connections when this limit is reached. It can be |
| 969 | used to limit the global capacity regardless of each frontend capacity. It is |
| 970 | important to note that this can only be used as a service protection measure, |
| 971 | as there will not necessarily be a fair share between frontends when the |
| 972 | limit is reached, so it's a good idea to also limit each frontend to some |
| 973 | value close to its expected share. Also, lowering tune.maxaccept can improve |
| 974 | fairness. |
| 975 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 976 | maxcomprate <number> |
| 977 | Sets the maximum per-process input compression rate to <number> kilobytes |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 978 | per second. For each session, if the maximum is reached, the compression |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 979 | level will be decreased during the session. If the maximum is reached at the |
| 980 | beginning of a session, the session will not compress at all. If the maximum |
| 981 | is not reached, the compression level will be increased up to |
| 982 | tune.comp.maxlevel. A value of zero means there is no limit, this is the |
| 983 | default value. |
| 984 | |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 985 | maxcompcpuusage <number> |
| 986 | Sets the maximum CPU usage HAProxy can reach before stopping the compression |
| 987 | for new requests or decreasing the compression level of current requests. |
| 988 | It works like 'maxcomprate' but measures CPU usage instead of incoming data |
| 989 | bandwidth. The value is expressed in percent of the CPU used by haproxy. In |
| 990 | case of multiple processes (nbproc > 1), each process manages its individual |
| 991 | usage. A value of 100 disable the limit. The default value is 100. Setting |
| 992 | a lower value will prevent the compression work from slowing the whole |
| 993 | process down and from introducing high latencies. |
| 994 | |
Willy Tarreau | ff4f82d | 2009-02-06 11:28:13 +0100 | [diff] [blame] | 995 | maxpipes <number> |
| 996 | Sets the maximum per-process number of pipes to <number>. Currently, pipes |
| 997 | are only used by kernel-based tcp splicing. Since a pipe contains two file |
| 998 | descriptors, the "ulimit-n" value will be increased accordingly. The default |
| 999 | value is maxconn/4, which seems to be more than enough for most heavy usages. |
| 1000 | The splice code dynamically allocates and releases pipes, and can fall back |
| 1001 | to standard copy, so setting this value too low may only impact performance. |
| 1002 | |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1003 | maxsessrate <number> |
| 1004 | Sets the maximum per-process number of sessions per second to <number>. |
| 1005 | Proxies will stop accepting connections when this limit is reached. It can be |
| 1006 | used to limit the global capacity regardless of each frontend capacity. It is |
| 1007 | important to note that this can only be used as a service protection measure, |
| 1008 | as there will not necessarily be a fair share between frontends when the |
| 1009 | limit is reached, so it's a good idea to also limit each frontend to some |
| 1010 | value close to its expected share. Also, lowering tune.maxaccept can improve |
| 1011 | fairness. |
| 1012 | |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1013 | maxsslconn <number> |
| 1014 | Sets the maximum per-process number of concurrent SSL connections to |
| 1015 | <number>. By default there is no SSL-specific limit, which means that the |
| 1016 | global maxconn setting will apply to all connections. Setting this limit |
| 1017 | avoids having openssl use too much memory and crash when malloc returns NULL |
| 1018 | (since it unfortunately does not reliably check for such conditions). Note |
| 1019 | that the limit applies both to incoming and outgoing connections, so one |
| 1020 | connection which is deciphered then ciphered accounts for 2 SSL connections. |
Willy Tarreau | d025648 | 2015-01-15 21:45:22 +0100 | [diff] [blame] | 1021 | If this value is not set, but a memory limit is enforced, this value will be |
| 1022 | automatically computed based on the memory limit, maxconn, the buffer size, |
| 1023 | memory allocated to compression, SSL cache size, and use of SSL in either |
| 1024 | frontends, backends or both. If neither maxconn nor maxsslconn are specified |
| 1025 | when there is a memory limit, haproxy will automatically adjust these values |
| 1026 | so that 100% of the connections can be made over SSL with no risk, and will |
| 1027 | consider the sides where it is enabled (frontend, backend, both). |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1028 | |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1029 | maxsslrate <number> |
| 1030 | Sets the maximum per-process number of SSL sessions per second to <number>. |
| 1031 | SSL listeners will stop accepting connections when this limit is reached. It |
| 1032 | can be used to limit the global SSL CPU usage regardless of each frontend |
| 1033 | capacity. It is important to note that this can only be used as a service |
| 1034 | protection measure, as there will not necessarily be a fair share between |
| 1035 | frontends when the limit is reached, so it's a good idea to also limit each |
| 1036 | frontend to some value close to its expected share. It is also important to |
| 1037 | note that the sessions are accounted before they enter the SSL stack and not |
| 1038 | after, which also protects the stack against bad handshakes. Also, lowering |
| 1039 | tune.maxaccept can improve fairness. |
| 1040 | |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1041 | maxzlibmem <number> |
| 1042 | Sets the maximum amount of RAM in megabytes per process usable by the zlib. |
| 1043 | When the maximum amount is reached, future sessions will not compress as long |
| 1044 | as RAM is unavailable. When sets to 0, there is no limit. |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1045 | The default value is 0. The value is available in bytes on the UNIX socket |
| 1046 | with "show info" on the line "MaxZlibMemUsage", the memory used by zlib is |
| 1047 | "ZlibMemUsage" in bytes. |
| 1048 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1049 | noepoll |
| 1050 | Disables the use of the "epoll" event polling system on Linux. It is |
| 1051 | equivalent to the command-line argument "-de". The next polling system |
Willy Tarreau | e9f49e7 | 2012-11-11 17:42:00 +0100 | [diff] [blame] | 1052 | used will generally be "poll". See also "nopoll". |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1053 | |
| 1054 | nokqueue |
| 1055 | Disables the use of the "kqueue" event polling system on BSD. It is |
| 1056 | equivalent to the command-line argument "-dk". The next polling system |
| 1057 | used will generally be "poll". See also "nopoll". |
| 1058 | |
| 1059 | nopoll |
| 1060 | Disables the use of the "poll" event polling system. It is equivalent to the |
| 1061 | command-line argument "-dp". The next polling system used will be "select". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1062 | It should never be needed to disable "poll" since it's available on all |
Willy Tarreau | e9f49e7 | 2012-11-11 17:42:00 +0100 | [diff] [blame] | 1063 | platforms supported by HAProxy. See also "nokqueue" and "noepoll". |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1064 | |
Willy Tarreau | ff4f82d | 2009-02-06 11:28:13 +0100 | [diff] [blame] | 1065 | nosplice |
| 1066 | Disables the use of kernel tcp splicing between sockets on Linux. It is |
| 1067 | equivalent to the command line argument "-dS". Data will then be copied |
| 1068 | using conventional and more portable recv/send calls. Kernel tcp splicing is |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 1069 | limited to some very recent instances of kernel 2.6. Most versions between |
Willy Tarreau | ff4f82d | 2009-02-06 11:28:13 +0100 | [diff] [blame] | 1070 | 2.6.25 and 2.6.28 are buggy and will forward corrupted data, so they must not |
| 1071 | be used. This option makes it easier to globally disable kernel splicing in |
| 1072 | case of doubt. See also "option splice-auto", "option splice-request" and |
| 1073 | "option splice-response". |
| 1074 | |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 1075 | nogetaddrinfo |
| 1076 | Disables the use of getaddrinfo(3) for name resolving. It is equivalent to |
| 1077 | the command line argument "-dG". Deprecated gethostbyname(3) will be used. |
| 1078 | |
Willy Tarreau | fe255b7 | 2007-10-14 23:09:26 +0200 | [diff] [blame] | 1079 | spread-checks <0..50, in percent> |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1080 | Sometimes it is desirable to avoid sending agent and health checks to |
| 1081 | servers at exact intervals, for instance when many logical servers are |
| 1082 | located on the same physical server. With the help of this parameter, it |
| 1083 | becomes possible to add some randomness in the check interval between 0 |
| 1084 | and +/- 50%. A value between 2 and 5 seems to show good results. The |
| 1085 | default value remains at 0. |
Willy Tarreau | fe255b7 | 2007-10-14 23:09:26 +0200 | [diff] [blame] | 1086 | |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 1087 | tune.buffers.limit <number> |
| 1088 | Sets a hard limit on the number of buffers which may be allocated per process. |
| 1089 | The default value is zero which means unlimited. The minimum non-zero value |
| 1090 | will always be greater than "tune.buffers.reserve" and should ideally always |
| 1091 | be about twice as large. Forcing this value can be particularly useful to |
| 1092 | limit the amount of memory a process may take, while retaining a sane |
| 1093 | behaviour. When this limit is reached, sessions which need a buffer wait for |
| 1094 | another one to be released by another session. Since buffers are dynamically |
| 1095 | allocated and released, the waiting time is very short and not perceptible |
| 1096 | provided that limits remain reasonable. In fact sometimes reducing the limit |
| 1097 | may even increase performance by increasing the CPU cache's efficiency. Tests |
| 1098 | have shown good results on average HTTP traffic with a limit to 1/10 of the |
| 1099 | expected global maxconn setting, which also significantly reduces memory |
| 1100 | usage. The memory savings come from the fact that a number of connections |
| 1101 | will not allocate 2*tune.bufsize. It is best not to touch this value unless |
| 1102 | advised to do so by an haproxy core developer. |
| 1103 | |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 1104 | tune.buffers.reserve <number> |
| 1105 | Sets the number of buffers which are pre-allocated and reserved for use only |
| 1106 | during memory shortage conditions resulting in failed memory allocations. The |
| 1107 | minimum value is 2 and is also the default. There is no reason a user would |
| 1108 | want to change this value, it's mostly aimed at haproxy core developers. |
| 1109 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 1110 | tune.bufsize <number> |
| 1111 | Sets the buffer size to this size (in bytes). Lower values allow more |
| 1112 | sessions to coexist in the same amount of RAM, and higher values allow some |
| 1113 | applications with very large cookies to work. The default value is 16384 and |
| 1114 | can be changed at build time. It is strongly recommended not to change this |
| 1115 | from the default value, as very low values will break some services such as |
| 1116 | statistics, and values larger than default size will increase memory usage, |
| 1117 | possibly causing the system to run out of memory. At least the global maxconn |
| 1118 | parameter should be decreased by the same factor as this one is increased. |
Dmitry Sivachenko | f6f4f7b | 2012-10-21 18:10:25 +0400 | [diff] [blame] | 1119 | If HTTP request is larger than (tune.bufsize - tune.maxrewrite), haproxy will |
| 1120 | return HTTP 400 (Bad Request) error. Similarly if an HTTP response is larger |
| 1121 | than this size, haproxy will return HTTP 502 (Bad Gateway). |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 1122 | |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 1123 | tune.chksize <number> |
| 1124 | Sets the check buffer size to this size (in bytes). Higher values may help |
| 1125 | find string or regex patterns in very large pages, though doing so may imply |
| 1126 | more memory and CPU usage. The default value is 16384 and can be changed at |
| 1127 | build time. It is not recommended to change this value, but to use better |
| 1128 | checks whenever possible. |
| 1129 | |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1130 | tune.comp.maxlevel <number> |
| 1131 | Sets the maximum compression level. The compression level affects CPU |
| 1132 | usage during compression. This value affects CPU usage during compression. |
| 1133 | Each session using compression initializes the compression algorithm with |
| 1134 | this value. The default value is 1. |
| 1135 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 1136 | tune.http.cookielen <number> |
| 1137 | Sets the maximum length of captured cookies. This is the maximum value that |
| 1138 | the "capture cookie xxx len yyy" will be allowed to take, and any upper value |
| 1139 | will automatically be truncated to this one. It is important not to set too |
| 1140 | high a value because all cookie captures still allocate this size whatever |
| 1141 | their configured value (they share a same pool). This value is per request |
| 1142 | per response, so the memory allocated is twice this value per connection. |
| 1143 | When not specified, the limit is set to 63 characters. It is recommended not |
| 1144 | to change this value. |
| 1145 | |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1146 | tune.http.maxhdr <number> |
| 1147 | Sets the maximum number of headers in a request. When a request comes with a |
| 1148 | number of headers greater than this value (including the first line), it is |
| 1149 | rejected with a "400 Bad Request" status code. Similarly, too large responses |
| 1150 | are blocked with "502 Bad Gateway". The default value is 101, which is enough |
| 1151 | for all usages, considering that the widely deployed Apache server uses the |
| 1152 | same limit. It can be useful to push this limit further to temporarily allow |
| 1153 | a buggy application to work by the time it gets fixed. Keep in mind that each |
| 1154 | new header consumes 32bits of memory for each session, so don't push this |
| 1155 | limit too high. |
| 1156 | |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 1157 | tune.idletimer <timeout> |
| 1158 | Sets the duration after which haproxy will consider that an empty buffer is |
| 1159 | probably associated with an idle stream. This is used to optimally adjust |
| 1160 | some packet sizes while forwarding large and small data alternatively. The |
| 1161 | decision to use splice() or to send large buffers in SSL is modulated by this |
| 1162 | parameter. The value is in milliseconds between 0 and 65535. A value of zero |
| 1163 | means that haproxy will not try to detect idle streams. The default is 1000, |
| 1164 | which seems to correctly detect end user pauses (eg: read a page before |
| 1165 | clicking). There should be not reason for changing this value. Please check |
| 1166 | tune.ssl.maxrecord below. |
| 1167 | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 1168 | tune.lua.forced-yield <number> |
| 1169 | This directive forces the Lua engine to execute a yield each <number> of |
| 1170 | instructions executed. This permits interruptng a long script and allows the |
| 1171 | HAProxy scheduler to process other tasks like accepting connections or |
| 1172 | forwarding traffic. The default value is 10000 instructions. If HAProxy often |
| 1173 | executes some Lua code but more reactivity is required, this value can be |
| 1174 | lowered. If the Lua code is quite long and its result is absolutely required |
| 1175 | to process the data, the <number> can be increased. |
| 1176 | |
Willy Tarreau | 32f61e2 | 2015-03-18 17:54:59 +0100 | [diff] [blame] | 1177 | tune.lua.maxmem |
| 1178 | Sets the maximum amount of RAM in megabytes per process usable by Lua. By |
| 1179 | default it is zero which means unlimited. It is important to set a limit to |
| 1180 | ensure that a bug in a script will not result in the system running out of |
| 1181 | memory. |
| 1182 | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 1183 | tune.lua.session-timeout <timeout> |
| 1184 | This is the execution timeout for the Lua sessions. This is useful for |
| 1185 | preventing infinite loops or spending too much time in Lua. This timeout has a |
| 1186 | priority over other timeouts. For example, if this timeout is set to 4s and |
| 1187 | you run a 5s sleep, the code will be interrupted with an error after waiting |
| 1188 | 4s. |
| 1189 | |
| 1190 | tune.lua.task-timeout <timeout> |
| 1191 | Purpose is the same as "tune.lua.session-timeout", but this timeout is |
| 1192 | dedicated to the tasks. By default, this timeout isn't set because a task may |
| 1193 | remain alive during of the lifetime of HAProxy. For example, a task used to |
| 1194 | check servers. |
| 1195 | |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 1196 | tune.maxaccept <number> |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 1197 | Sets the maximum number of consecutive connections a process may accept in a |
| 1198 | row before switching to other work. In single process mode, higher numbers |
| 1199 | give better performance at high connection rates. However in multi-process |
| 1200 | modes, keeping a bit of fairness between processes generally is better to |
| 1201 | increase performance. This value applies individually to each listener, so |
| 1202 | that the number of processes a listener is bound to is taken into account. |
| 1203 | This value defaults to 64. In multi-process mode, it is divided by twice |
| 1204 | the number of processes the listener is bound to. Setting this value to -1 |
| 1205 | completely disables the limitation. It should normally not be needed to tweak |
| 1206 | this value. |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 1207 | |
| 1208 | tune.maxpollevents <number> |
| 1209 | Sets the maximum amount of events that can be processed at once in a call to |
| 1210 | the polling system. The default value is adapted to the operating system. It |
| 1211 | has been noticed that reducing it below 200 tends to slightly decrease |
| 1212 | latency at the expense of network bandwidth, and increasing it above 200 |
| 1213 | tends to trade latency for slightly increased bandwidth. |
| 1214 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 1215 | tune.maxrewrite <number> |
| 1216 | Sets the reserved buffer space to this size in bytes. The reserved space is |
| 1217 | used for header rewriting or appending. The first reads on sockets will never |
| 1218 | fill more than bufsize-maxrewrite. Historically it has defaulted to half of |
| 1219 | bufsize, though that does not make much sense since there are rarely large |
| 1220 | numbers of headers to add. Setting it too high prevents processing of large |
| 1221 | requests or responses. Setting it too low prevents addition of new headers |
| 1222 | to already large requests or to POST requests. It is generally wise to set it |
| 1223 | to about 1024. It is automatically readjusted to half of bufsize if it is |
| 1224 | larger than that. This means you don't have to worry about it when changing |
| 1225 | bufsize. |
| 1226 | |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1227 | tune.pattern.cache-size <number> |
| 1228 | Sets the size of the pattern lookup cache to <number> entries. This is an LRU |
| 1229 | cache which reminds previous lookups and their results. It is used by ACLs |
| 1230 | and maps on slow pattern lookups, namely the ones using the "sub", "reg", |
| 1231 | "dir", "dom", "end", "bin" match methods as well as the case-insensitive |
| 1232 | strings. It applies to pattern expressions which means that it will be able |
| 1233 | to memorize the result of a lookup among all the patterns specified on a |
| 1234 | configuration line (including all those loaded from files). It automatically |
| 1235 | invalidates entries which are updated using HTTP actions or on the CLI. The |
| 1236 | default cache size is set to 10000 entries, which limits its footprint to |
| 1237 | about 5 MB on 32-bit systems and 8 MB on 64-bit systems. There is a very low |
| 1238 | risk of collision in this cache, which is in the order of the size of the |
| 1239 | cache divided by 2^64. Typically, at 10000 requests per second with the |
| 1240 | default cache size of 10000 entries, there's 1% chance that a brute force |
| 1241 | attack could cause a single collision after 60 years, or 0.1% after 6 years. |
| 1242 | This is considered much lower than the risk of a memory corruption caused by |
| 1243 | aging components. If this is not acceptable, the cache can be disabled by |
| 1244 | setting this parameter to 0. |
| 1245 | |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 1246 | tune.pipesize <number> |
| 1247 | Sets the kernel pipe buffer size to this size (in bytes). By default, pipes |
| 1248 | are the default size for the system. But sometimes when using TCP splicing, |
| 1249 | it can improve performance to increase pipe sizes, especially if it is |
| 1250 | suspected that pipes are not filled and that many calls to splice() are |
| 1251 | performed. This has an impact on the kernel's memory footprint, so this must |
| 1252 | not be changed if impacts are not understood. |
| 1253 | |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 1254 | tune.rcvbuf.client <number> |
| 1255 | tune.rcvbuf.server <number> |
| 1256 | Forces the kernel socket receive buffer size on the client or the server side |
| 1257 | to the specified value in bytes. This value applies to all TCP/HTTP frontends |
| 1258 | and backends. It should normally never be set, and the default size (0) lets |
| 1259 | the kernel autotune this value depending on the amount of available memory. |
| 1260 | However it can sometimes help to set it to very low values (eg: 4096) in |
| 1261 | order to save kernel memory by preventing it from buffering too large amounts |
| 1262 | of received data. Lower values will significantly increase CPU usage though. |
| 1263 | |
| 1264 | tune.sndbuf.client <number> |
| 1265 | tune.sndbuf.server <number> |
| 1266 | Forces the kernel socket send buffer size on the client or the server side to |
| 1267 | the specified value in bytes. This value applies to all TCP/HTTP frontends |
| 1268 | and backends. It should normally never be set, and the default size (0) lets |
| 1269 | the kernel autotune this value depending on the amount of available memory. |
| 1270 | However it can sometimes help to set it to very low values (eg: 4096) in |
| 1271 | order to save kernel memory by preventing it from buffering too large amounts |
| 1272 | of received data. Lower values will significantly increase CPU usage though. |
| 1273 | Another use case is to prevent write timeouts with extremely slow clients due |
| 1274 | to the kernel waiting for a large part of the buffer to be read before |
| 1275 | notifying haproxy again. |
| 1276 | |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 1277 | tune.ssl.cachesize <number> |
Emeric Brun | af9619d | 2012-11-28 18:47:52 +0100 | [diff] [blame] | 1278 | Sets the size of the global SSL session cache, in a number of blocks. A block |
| 1279 | is large enough to contain an encoded session without peer certificate. |
| 1280 | An encoded session with peer certificate is stored in multiple blocks |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 1281 | depending on the size of the peer certificate. A block uses approximately |
Emeric Brun | af9619d | 2012-11-28 18:47:52 +0100 | [diff] [blame] | 1282 | 200 bytes of memory. The default value may be forced at build time, otherwise |
| 1283 | defaults to 20000. When the cache is full, the most idle entries are purged |
| 1284 | and reassigned. Higher values reduce the occurrence of such a purge, hence |
| 1285 | the number of CPU-intensive SSL handshakes by ensuring that all users keep |
| 1286 | their session as long as possible. All entries are pre-allocated upon startup |
Emeric Brun | 22890a1 | 2012-12-28 14:41:32 +0100 | [diff] [blame] | 1287 | and are shared between all processes if "nbproc" is greater than 1. Setting |
| 1288 | this value to 0 disables the SSL session cache. |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 1289 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 1290 | tune.ssl.force-private-cache |
| 1291 | This boolean disables SSL session cache sharing between all processes. It |
| 1292 | should normally not be used since it will force many renegotiations due to |
| 1293 | clients hitting a random process. But it may be required on some operating |
| 1294 | systems where none of the SSL cache synchronization method may be used. In |
| 1295 | this case, adding a first layer of hash-based load balancing before the SSL |
| 1296 | layer might limit the impact of the lack of session sharing. |
| 1297 | |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 1298 | tune.ssl.lifetime <timeout> |
| 1299 | Sets how long a cached SSL session may remain valid. This time is expressed |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 1300 | in seconds and defaults to 300 (5 min). It is important to understand that it |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 1301 | does not guarantee that sessions will last that long, because if the cache is |
| 1302 | full, the longest idle sessions will be purged despite their configured |
| 1303 | lifetime. The real usefulness of this setting is to prevent sessions from |
| 1304 | being used for too long. |
| 1305 | |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 1306 | tune.ssl.maxrecord <number> |
| 1307 | Sets the maximum amount of bytes passed to SSL_write() at a time. Default |
| 1308 | value 0 means there is no limit. Over SSL/TLS, the client can decipher the |
| 1309 | data only once it has received a full record. With large records, it means |
| 1310 | that clients might have to download up to 16kB of data before starting to |
| 1311 | process them. Limiting the value can improve page load times on browsers |
| 1312 | located over high latency or low bandwidth networks. It is suggested to find |
| 1313 | optimal values which fit into 1 or 2 TCP segments (generally 1448 bytes over |
| 1314 | Ethernet with TCP timestamps enabled, or 1460 when timestamps are disabled), |
| 1315 | keeping in mind that SSL/TLS add some overhead. Typical values of 1419 and |
| 1316 | 2859 gave good results during tests. Use "strace -e trace=write" to find the |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 1317 | best value. Haproxy will automatically switch to this setting after an idle |
| 1318 | stream has been detected (see tune.idletimer above). |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 1319 | |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 1320 | tune.ssl.default-dh-param <number> |
| 1321 | Sets the maximum size of the Diffie-Hellman parameters used for generating |
| 1322 | the ephemeral/temporary Diffie-Hellman key in case of DHE key exchange. The |
| 1323 | final size will try to match the size of the server's RSA (or DSA) key (e.g, |
| 1324 | a 2048 bits temporary DH key for a 2048 bits RSA key), but will not exceed |
| 1325 | this maximum value. Default value if 1024. Only 1024 or higher values are |
| 1326 | allowed. Higher values will increase the CPU load, and values greater than |
| 1327 | 1024 bits are not supported by Java 7 and earlier clients. This value is not |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 1328 | used if static Diffie-Hellman parameters are supplied either directly |
| 1329 | in the certificate file or by using the ssl-dh-param-file parameter. |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 1330 | |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 1331 | tune.ssl.ssl-ctx-cache-size <number> |
| 1332 | Sets the size of the cache used to store generated certificates to <number> |
| 1333 | entries. This is a LRU cache. Because generating a SSL certificate |
| 1334 | dynamically is expensive, they are cached. The default cache size is set to |
| 1335 | 1000 entries. |
| 1336 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 1337 | tune.vars.global-max-size <size> |
| 1338 | tune.vars.reqres-max-size <size> |
| 1339 | tune.vars.sess-max-size <size> |
| 1340 | tune.vars.txn-max-size <size> |
| 1341 | These four tunes helps to manage the allowed amount of memory used by the |
| 1342 | variables system. "global" limits the memory for all the systems. "sess" limit |
| 1343 | the memory by session, "txn" limits the memory by transaction and "reqres" |
| 1344 | limits the memory for each request or response processing. during the |
| 1345 | accounting, "sess" embbed "txn" and "txn" embed "reqres". |
| 1346 | |
| 1347 | By example, we considers that "tune.vars.sess-max-size" is fixed to 100, |
| 1348 | "tune.vars.txn-max-size" is fixed to 100, "tune.vars.reqres-max-size" is |
| 1349 | also fixed to 100. If we create a variable "txn.var" that contains 100 bytes, |
| 1350 | we cannot create any more variable in the other contexts. |
| 1351 | |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1352 | tune.zlib.memlevel <number> |
| 1353 | Sets the memLevel parameter in zlib initialization for each session. It |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 1354 | defines how much memory should be allocated for the internal compression |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1355 | state. A value of 1 uses minimum memory but is slow and reduces compression |
| 1356 | ratio, a value of 9 uses maximum memory for optimal speed. Can be a value |
| 1357 | between 1 and 9. The default value is 8. |
| 1358 | |
| 1359 | tune.zlib.windowsize <number> |
| 1360 | Sets the window size (the size of the history buffer) as a parameter of the |
| 1361 | zlib initialization for each session. Larger values of this parameter result |
| 1362 | in better compression at the expense of memory usage. Can be a value between |
| 1363 | 8 and 15. The default value is 15. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1364 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 1365 | 3.3. Debugging |
| 1366 | -------------- |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1367 | |
| 1368 | debug |
| 1369 | Enables debug mode which dumps to stdout all exchanges, and disables forking |
| 1370 | into background. It is the equivalent of the command-line argument "-d". It |
| 1371 | should never be used in a production configuration since it may prevent full |
| 1372 | system startup. |
| 1373 | |
| 1374 | quiet |
| 1375 | Do not display any message during startup. It is equivalent to the command- |
| 1376 | line argument "-q". |
| 1377 | |
Emeric Brun | f099e79 | 2010-09-27 12:05:28 +0200 | [diff] [blame] | 1378 | |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 1379 | 3.4. Userlists |
| 1380 | -------------- |
| 1381 | It is possible to control access to frontend/backend/listen sections or to |
| 1382 | http stats by allowing only authenticated and authorized users. To do this, |
| 1383 | it is required to create at least one userlist and to define users. |
| 1384 | |
| 1385 | userlist <listname> |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 1386 | Creates new userlist with name <listname>. Many independent userlists can be |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 1387 | used to store authentication & authorization data for independent customers. |
| 1388 | |
| 1389 | group <groupname> [users <user>,<user>,(...)] |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 1390 | Adds group <groupname> to the current userlist. It is also possible to |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 1391 | attach users to this group by using a comma separated list of names |
| 1392 | proceeded by "users" keyword. |
| 1393 | |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 1394 | user <username> [password|insecure-password <password>] |
| 1395 | [groups <group>,<group>,(...)] |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 1396 | Adds user <username> to the current userlist. Both secure (encrypted) and |
| 1397 | insecure (unencrypted) passwords can be used. Encrypted passwords are |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 1398 | evaluated using the crypt(3) function so depending of the system's |
| 1399 | capabilities, different algorithms are supported. For example modern Glibc |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 1400 | based Linux system supports MD5, SHA-256, SHA-512 and of course classic, |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 1401 | DES-based method of encrypting passwords. |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 1402 | |
| 1403 | |
| 1404 | Example: |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 1405 | userlist L1 |
| 1406 | group G1 users tiger,scott |
| 1407 | group G2 users xdb,scott |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 1408 | |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 1409 | user tiger password $6$k6y3o.eP$JlKBx9za9667qe4(...)xHSwRv6J.C0/D7cV91 |
| 1410 | user scott insecure-password elgato |
| 1411 | user xdb insecure-password hello |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 1412 | |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 1413 | userlist L2 |
| 1414 | group G1 |
| 1415 | group G2 |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 1416 | |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 1417 | user tiger password $6$k6y3o.eP$JlKBx(...)xHSwRv6J.C0/D7cV91 groups G1 |
| 1418 | user scott insecure-password elgato groups G1,G2 |
| 1419 | user xdb insecure-password hello groups G2 |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 1420 | |
| 1421 | Please note that both lists are functionally identical. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1422 | |
Emeric Brun | f099e79 | 2010-09-27 12:05:28 +0200 | [diff] [blame] | 1423 | |
| 1424 | 3.5. Peers |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 1425 | ---------- |
Emeric Brun | 9490095 | 2015-06-11 18:25:54 +0200 | [diff] [blame] | 1426 | It is possible to propagate entries of any data-types in stick-tables between |
| 1427 | several haproxy instances over TCP connections in a multi-master fashion. Each |
| 1428 | instance pushes its local updates and insertions to remote peers. The pushed |
| 1429 | values overwrite remote ones without aggregation. Interrupted exchanges are |
| 1430 | automatically detected and recovered from the last known point. |
| 1431 | In addition, during a soft restart, the old process connects to the new one |
| 1432 | using such a TCP connection to push all its entries before the new process |
| 1433 | tries to connect to other peers. That ensures very fast replication during a |
| 1434 | reload, it typically takes a fraction of a second even for large tables. |
| 1435 | Note that Server IDs are used to identify servers remotely, so it is important |
| 1436 | that configurations look similar or at least that the same IDs are forced on |
| 1437 | each server on all participants. |
Emeric Brun | f099e79 | 2010-09-27 12:05:28 +0200 | [diff] [blame] | 1438 | |
| 1439 | peers <peersect> |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 1440 | Creates a new peer list with name <peersect>. It is an independent section, |
Emeric Brun | f099e79 | 2010-09-27 12:05:28 +0200 | [diff] [blame] | 1441 | which is referenced by one or more stick-tables. |
| 1442 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 1443 | disabled |
| 1444 | Disables a peers section. It disables both listening and any synchronization |
| 1445 | related to this section. This is provided to disable synchronization of stick |
| 1446 | tables without having to comment out all "peers" references. |
| 1447 | |
| 1448 | enable |
| 1449 | This re-enables a disabled peers section which was previously disabled. |
| 1450 | |
Emeric Brun | f099e79 | 2010-09-27 12:05:28 +0200 | [diff] [blame] | 1451 | peer <peername> <ip>:<port> |
| 1452 | Defines a peer inside a peers section. |
| 1453 | If <peername> is set to the local peer name (by default hostname, or forced |
| 1454 | using "-L" command line option), haproxy will listen for incoming remote peer |
| 1455 | connection on <ip>:<port>. Otherwise, <ip>:<port> defines where to connect to |
| 1456 | to join the remote peer, and <peername> is used at the protocol level to |
| 1457 | identify and validate the remote peer on the server side. |
| 1458 | |
| 1459 | During a soft restart, local peer <ip>:<port> is used by the old instance to |
| 1460 | connect the new one and initiate a complete replication (teaching process). |
| 1461 | |
| 1462 | It is strongly recommended to have the exact same peers declaration on all |
| 1463 | peers and to only rely on the "-L" command line argument to change the local |
| 1464 | peer name. This makes it easier to maintain coherent configuration files |
| 1465 | across all peers. |
| 1466 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 1467 | You may want to reference some environment variables in the address |
| 1468 | parameter, see section 2.3 about environment variables. |
Willy Tarreau | dad36a3 | 2013-03-11 01:20:04 +0100 | [diff] [blame] | 1469 | |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 1470 | Example: |
Emeric Brun | f099e79 | 2010-09-27 12:05:28 +0200 | [diff] [blame] | 1471 | peers mypeers |
Willy Tarreau | f7b30a9 | 2010-12-06 22:59:17 +0100 | [diff] [blame] | 1472 | peer haproxy1 192.168.0.1:1024 |
| 1473 | peer haproxy2 192.168.0.2:1024 |
| 1474 | peer haproxy3 10.2.0.1:1024 |
Emeric Brun | f099e79 | 2010-09-27 12:05:28 +0200 | [diff] [blame] | 1475 | |
| 1476 | backend mybackend |
| 1477 | mode tcp |
| 1478 | balance roundrobin |
| 1479 | stick-table type ip size 20k peers mypeers |
| 1480 | stick on src |
| 1481 | |
Willy Tarreau | f7b30a9 | 2010-12-06 22:59:17 +0100 | [diff] [blame] | 1482 | server srv1 192.168.0.30:80 |
| 1483 | server srv2 192.168.0.31:80 |
Emeric Brun | f099e79 | 2010-09-27 12:05:28 +0200 | [diff] [blame] | 1484 | |
| 1485 | |
Simon Horman | 51a1cf6 | 2015-02-03 13:00:44 +0900 | [diff] [blame] | 1486 | 3.6. Mailers |
| 1487 | ------------ |
| 1488 | It is possible to send email alerts when the state of servers changes. |
| 1489 | If configured email alerts are sent to each mailer that is configured |
| 1490 | in a mailers section. Email is sent to mailers using SMTP. |
| 1491 | |
Pieter Baauw | 386a127 | 2015-08-16 15:26:24 +0200 | [diff] [blame] | 1492 | mailers <mailersect> |
Simon Horman | 51a1cf6 | 2015-02-03 13:00:44 +0900 | [diff] [blame] | 1493 | Creates a new mailer list with the name <mailersect>. It is an |
| 1494 | independent section which is referenced by one or more proxies. |
| 1495 | |
| 1496 | mailer <mailername> <ip>:<port> |
| 1497 | Defines a mailer inside a mailers section. |
| 1498 | |
| 1499 | Example: |
| 1500 | mailers mymailers |
| 1501 | mailer smtp1 192.168.0.1:587 |
| 1502 | mailer smtp2 192.168.0.2:587 |
| 1503 | |
| 1504 | backend mybackend |
| 1505 | mode tcp |
| 1506 | balance roundrobin |
| 1507 | |
| 1508 | email-alert mailers mymailers |
| 1509 | email-alert from test1@horms.org |
| 1510 | email-alert to test2@horms.org |
| 1511 | |
| 1512 | server srv1 192.168.0.30:80 |
| 1513 | server srv2 192.168.0.31:80 |
| 1514 | |
| 1515 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 1516 | 4. Proxies |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1517 | ---------- |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1518 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1519 | Proxy configuration can be located in a set of sections : |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 1520 | - defaults [<name>] |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1521 | - frontend <name> |
| 1522 | - backend <name> |
| 1523 | - listen <name> |
| 1524 | |
| 1525 | A "defaults" section sets default parameters for all other sections following |
| 1526 | its declaration. Those default parameters are reset by the next "defaults" |
| 1527 | 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] | 1528 | 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] | 1529 | |
| 1530 | A "frontend" section describes a set of listening sockets accepting client |
| 1531 | connections. |
| 1532 | |
| 1533 | A "backend" section describes a set of servers to which the proxy will connect |
| 1534 | to forward incoming connections. |
| 1535 | |
| 1536 | A "listen" section defines a complete proxy with its frontend and backend |
| 1537 | parts combined in one section. It is generally useful for TCP-only traffic. |
| 1538 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1539 | All proxy names must be formed from upper and lower case letters, digits, |
| 1540 | '-' (dash), '_' (underscore) , '.' (dot) and ':' (colon). ACL names are |
| 1541 | case-sensitive, which means that "www" and "WWW" are two different proxies. |
| 1542 | |
| 1543 | Historically, all proxy names could overlap, it just caused troubles in the |
| 1544 | logs. Since the introduction of content switching, it is mandatory that two |
| 1545 | proxies with overlapping capabilities (frontend/backend) have different names. |
| 1546 | However, it is still permitted that a frontend and a backend share the same |
| 1547 | name, as this configuration seems to be commonly encountered. |
| 1548 | |
| 1549 | Right now, two major proxy modes are supported : "tcp", also known as layer 4, |
| 1550 | and "http", also known as layer 7. In layer 4 mode, HAProxy simply forwards |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 1551 | bidirectional traffic between two sides. In layer 7 mode, HAProxy analyzes the |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1552 | protocol, and can interact with it by allowing, blocking, switching, adding, |
| 1553 | modifying, or removing arbitrary contents in requests or responses, based on |
| 1554 | arbitrary criteria. |
| 1555 | |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 1556 | In HTTP mode, the processing applied to requests and responses flowing over |
| 1557 | a connection depends in the combination of the frontend's HTTP options and |
| 1558 | the backend's. HAProxy supports 5 connection modes : |
| 1559 | |
| 1560 | - KAL : keep alive ("option http-keep-alive") which is the default mode : all |
| 1561 | requests and responses are processed, and connections remain open but idle |
| 1562 | between responses and new requests. |
| 1563 | |
| 1564 | - TUN: tunnel ("option http-tunnel") : this was the default mode for versions |
| 1565 | 1.0 to 1.5-dev21 : only the first request and response are processed, and |
| 1566 | everything else is forwarded with no analysis at all. This mode should not |
| 1567 | be used as it creates lots of trouble with logging and HTTP processing. |
| 1568 | |
| 1569 | - PCL: passive close ("option httpclose") : exactly the same as tunnel mode, |
| 1570 | but with "Connection: close" appended in both directions to try to make |
| 1571 | both ends close after the first request/response exchange. |
| 1572 | |
| 1573 | - SCL: server close ("option http-server-close") : the server-facing |
| 1574 | connection is closed after the end of the response is received, but the |
| 1575 | client-facing connection remains open. |
| 1576 | |
| 1577 | - FCL: forced close ("option forceclose") : the connection is actively closed |
| 1578 | after the end of the response. |
| 1579 | |
| 1580 | The effective mode that will be applied to a connection passing through a |
| 1581 | frontend and a backend can be determined by both proxy modes according to the |
| 1582 | following matrix, but in short, the modes are symmetric, keep-alive is the |
| 1583 | weakest option and force close is the strongest. |
| 1584 | |
| 1585 | Backend mode |
| 1586 | |
| 1587 | | KAL | TUN | PCL | SCL | FCL |
| 1588 | ----+-----+-----+-----+-----+---- |
| 1589 | KAL | KAL | TUN | PCL | SCL | FCL |
| 1590 | ----+-----+-----+-----+-----+---- |
| 1591 | TUN | TUN | TUN | PCL | SCL | FCL |
| 1592 | Frontend ----+-----+-----+-----+-----+---- |
| 1593 | mode PCL | PCL | PCL | PCL | FCL | FCL |
| 1594 | ----+-----+-----+-----+-----+---- |
| 1595 | SCL | SCL | SCL | FCL | SCL | FCL |
| 1596 | ----+-----+-----+-----+-----+---- |
| 1597 | FCL | FCL | FCL | FCL | FCL | FCL |
| 1598 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1599 | |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 1600 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 1601 | 4.1. Proxy keywords matrix |
| 1602 | -------------------------- |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1603 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 1604 | The following list of keywords is supported. Most of them may only be used in a |
| 1605 | limited set of section types. Some of them are marked as "deprecated" because |
| 1606 | they are inherited from an old syntax which may be confusing or functionally |
| 1607 | limited, and there are new recommended keywords to replace them. Keywords |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1608 | marked with "(*)" can be optionally inverted using the "no" prefix, eg. "no |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 1609 | option contstats". This makes sense when the option has been enabled by default |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1610 | and must be disabled for a specific instance. Such options may also be prefixed |
| 1611 | with "default" in order to restore default settings regardless of what has been |
| 1612 | specified in a previous "defaults" section. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1613 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1614 | |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1615 | keyword defaults frontend listen backend |
| 1616 | ------------------------------------+----------+----------+---------+--------- |
| 1617 | acl - X X X |
Willy Tarreau | 294d0f0 | 2015-08-10 19:40:12 +0200 | [diff] [blame] | 1618 | appsession - - - - |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1619 | backlog X X X - |
| 1620 | balance X - X X |
| 1621 | bind - X X - |
| 1622 | bind-process X X X X |
| 1623 | block - X X X |
| 1624 | capture cookie - X X - |
| 1625 | capture request header - X X - |
| 1626 | capture response header - X X - |
| 1627 | clitimeout (deprecated) X X X - |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 1628 | compression X X X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1629 | contimeout (deprecated) X - X X |
| 1630 | cookie X - X X |
Thierry FOURNIER | a0a1b75 | 2015-05-26 17:44:32 +0200 | [diff] [blame] | 1631 | declare capture - X X - |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1632 | default-server X - X X |
| 1633 | default_backend X X X - |
| 1634 | description - X X X |
| 1635 | disabled X X X X |
| 1636 | dispatch - - X X |
Simon Horman | 51a1cf6 | 2015-02-03 13:00:44 +0900 | [diff] [blame] | 1637 | email-alert from X X X X |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 1638 | email-alert level X X X X |
Simon Horman | 51a1cf6 | 2015-02-03 13:00:44 +0900 | [diff] [blame] | 1639 | email-alert mailers X X X X |
| 1640 | email-alert myhostname X X X X |
| 1641 | email-alert to X X X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1642 | enabled X X X X |
| 1643 | errorfile X X X X |
| 1644 | errorloc X X X X |
| 1645 | errorloc302 X X X X |
| 1646 | -- keyword -------------------------- defaults - frontend - listen -- backend - |
| 1647 | errorloc303 X X X X |
Cyril Bonté | 0d4bf01 | 2010-04-25 23:21:46 +0200 | [diff] [blame] | 1648 | force-persist - X X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1649 | fullconn X - X X |
| 1650 | grace X X X X |
| 1651 | hash-type X - X X |
| 1652 | http-check disable-on-404 X - X X |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 1653 | http-check expect - - X X |
Willy Tarreau | 7ab6aff | 2010-10-12 06:30:16 +0200 | [diff] [blame] | 1654 | http-check send-state X - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1655 | http-request - X X X |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 1656 | http-response - X X X |
Willy Tarreau | 3063195 | 2015-08-06 15:05:24 +0200 | [diff] [blame] | 1657 | http-reuse X - X X |
Baptiste Assmann | 2c42ef5 | 2013-10-09 21:57:02 +0200 | [diff] [blame] | 1658 | http-send-name-header - - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1659 | id - X X X |
Cyril Bonté | 0d4bf01 | 2010-04-25 23:21:46 +0200 | [diff] [blame] | 1660 | ignore-persist - X X X |
Baptiste Assmann | 01c6cc3 | 2015-08-23 11:45:29 +0200 | [diff] [blame] | 1661 | load-server-state-from-file X - X X |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1662 | log (*) X X X X |
Willy Tarreau | fb4e7ea | 2015-01-07 14:55:17 +0100 | [diff] [blame] | 1663 | log-format X X X - |
Dragan Dosen | 7ad3154 | 2015-09-28 17:16:47 +0200 | [diff] [blame] | 1664 | log-format-sd X X X - |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 1665 | log-tag X X X X |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 1666 | max-keep-alive-queue X - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1667 | maxconn X X X - |
| 1668 | mode X X X X |
| 1669 | monitor fail - X X - |
| 1670 | monitor-net X X X - |
| 1671 | monitor-uri X X X - |
| 1672 | option abortonclose (*) X - X X |
| 1673 | option accept-invalid-http-request (*) X X X - |
| 1674 | option accept-invalid-http-response (*) X - X X |
| 1675 | option allbackups (*) X - X X |
| 1676 | option checkcache (*) X - X X |
| 1677 | option clitcpka (*) X X X - |
| 1678 | option contstats (*) X X X - |
| 1679 | option dontlog-normal (*) X X X - |
| 1680 | option dontlognull (*) X X X - |
| 1681 | option forceclose (*) X X X X |
| 1682 | -- keyword -------------------------- defaults - frontend - listen -- backend - |
| 1683 | option forwardfor X X X X |
Willy Tarreau | 9fbe18e | 2015-05-01 22:42:08 +0200 | [diff] [blame] | 1684 | option http-buffer-request (*) X X X X |
Willy Tarreau | 82649f9 | 2015-05-01 22:40:51 +0200 | [diff] [blame] | 1685 | option http-ignore-probes (*) X X X - |
Willy Tarreau | 16bfb02 | 2010-01-16 19:48:41 +0100 | [diff] [blame] | 1686 | option http-keep-alive (*) X X X X |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 1687 | option http-no-delay (*) X X X X |
Willy Tarreau | 8a8e1d9 | 2010-04-05 16:15:16 +0200 | [diff] [blame] | 1688 | option http-pretend-keepalive (*) X X X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1689 | option http-server-close (*) X X X X |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 1690 | option http-tunnel (*) X X X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1691 | option http-use-proxy-header (*) X X X - |
| 1692 | option httpchk X - X X |
| 1693 | option httpclose (*) X X X X |
| 1694 | option httplog X X X X |
| 1695 | option http_proxy (*) X X X X |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 1696 | option independent-streams (*) X X X X |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 1697 | option ldap-check X - X X |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1698 | option external-check X - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1699 | option log-health-checks (*) X - X X |
| 1700 | option log-separate-errors (*) X X X - |
| 1701 | option logasap (*) X X X - |
| 1702 | option mysql-check X - X X |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 1703 | option pgsql-check X - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1704 | option nolinger (*) X X X X |
| 1705 | option originalto X X X X |
| 1706 | option persist (*) X - X X |
| 1707 | option redispatch (*) X - X X |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 1708 | option redis-check X - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1709 | option smtpchk X - X X |
| 1710 | option socket-stats (*) X X X - |
| 1711 | option splice-auto (*) X X X X |
| 1712 | option splice-request (*) X X X X |
| 1713 | option splice-response (*) X X X X |
| 1714 | option srvtcpka (*) X - X X |
| 1715 | option ssl-hello-chk X - X X |
| 1716 | -- keyword -------------------------- defaults - frontend - listen -- backend - |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 1717 | option tcp-check X - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1718 | option tcp-smart-accept (*) X X X - |
| 1719 | option tcp-smart-connect (*) X - X X |
| 1720 | option tcpka X X X X |
| 1721 | option tcplog X X X X |
| 1722 | option transparent (*) X - X X |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1723 | external-check command X - X X |
| 1724 | external-check path X - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1725 | persist rdp-cookie X - X X |
| 1726 | rate-limit sessions X X X - |
| 1727 | redirect - X X X |
| 1728 | redisp (deprecated) X - X X |
| 1729 | redispatch (deprecated) X - X X |
| 1730 | reqadd - X X X |
| 1731 | reqallow - X X X |
| 1732 | reqdel - X X X |
| 1733 | reqdeny - X X X |
| 1734 | reqiallow - X X X |
| 1735 | reqidel - X X X |
| 1736 | reqideny - X X X |
| 1737 | reqipass - X X X |
| 1738 | reqirep - X X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1739 | reqitarpit - X X X |
| 1740 | reqpass - X X X |
| 1741 | reqrep - X X X |
| 1742 | -- keyword -------------------------- defaults - frontend - listen -- backend - |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1743 | reqtarpit - X X X |
| 1744 | retries X - X X |
| 1745 | rspadd - X X X |
| 1746 | rspdel - X X X |
| 1747 | rspdeny - X X X |
| 1748 | rspidel - X X X |
| 1749 | rspideny - X X X |
| 1750 | rspirep - X X X |
| 1751 | rsprep - X X X |
| 1752 | server - - X X |
Baptiste Assmann | 01c6cc3 | 2015-08-23 11:45:29 +0200 | [diff] [blame] | 1753 | server-state-file-name X - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1754 | source X - X X |
| 1755 | srvtimeout (deprecated) X - X X |
Cyril Bonté | 66c327d | 2010-10-12 00:14:37 +0200 | [diff] [blame] | 1756 | stats admin - - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1757 | stats auth X - X X |
| 1758 | stats enable X - X X |
| 1759 | stats hide-version X - X X |
Cyril Bonté | 2be1b3f | 2010-09-30 23:46:30 +0200 | [diff] [blame] | 1760 | stats http-request - - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1761 | stats realm X - X X |
| 1762 | stats refresh X - X X |
| 1763 | stats scope X - X X |
| 1764 | stats show-desc X - X X |
| 1765 | stats show-legends X - X X |
| 1766 | stats show-node X - X X |
| 1767 | stats uri X - X X |
| 1768 | -- keyword -------------------------- defaults - frontend - listen -- backend - |
| 1769 | stick match - - X X |
| 1770 | stick on - - X X |
| 1771 | stick store-request - - X X |
Willy Tarreau | d8dc99f | 2011-07-01 11:33:25 +0200 | [diff] [blame] | 1772 | stick store-response - - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1773 | stick-table - - X X |
Willy Tarreau | 938c7fe | 2014-04-25 14:21:39 +0200 | [diff] [blame] | 1774 | tcp-check connect - - X X |
| 1775 | tcp-check expect - - X X |
| 1776 | tcp-check send - - X X |
| 1777 | tcp-check send-binary - - X X |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 1778 | tcp-request connection - X X - |
| 1779 | tcp-request content - X X X |
Willy Tarreau | a56235c | 2010-09-14 11:31:36 +0200 | [diff] [blame] | 1780 | tcp-request inspect-delay - X X X |
Emeric Brun | 0a3b67f | 2010-09-24 15:34:53 +0200 | [diff] [blame] | 1781 | tcp-response content - - X X |
| 1782 | tcp-response inspect-delay - - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1783 | timeout check X - X X |
| 1784 | timeout client X X X - |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 1785 | timeout client-fin X X X - |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1786 | timeout clitimeout (deprecated) X X X - |
| 1787 | timeout connect X - X X |
| 1788 | timeout contimeout (deprecated) X - X X |
| 1789 | timeout http-keep-alive X X X X |
| 1790 | timeout http-request X X X X |
| 1791 | timeout queue X - X X |
| 1792 | timeout server X - X X |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 1793 | timeout server-fin X - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1794 | timeout srvtimeout (deprecated) X - X X |
| 1795 | timeout tarpit X X X X |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1796 | timeout tunnel X - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1797 | transparent (deprecated) X - X X |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1798 | unique-id-format X X X - |
| 1799 | unique-id-header X X X - |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1800 | use_backend - X X - |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1801 | use-server - - X X |
Willy Tarreau | 5c6f7b3 | 2010-02-26 13:34:29 +0100 | [diff] [blame] | 1802 | ------------------------------------+----------+----------+---------+--------- |
| 1803 | keyword defaults frontend listen backend |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1804 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1805 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 1806 | 4.2. Alphabetically sorted keywords reference |
| 1807 | --------------------------------------------- |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1808 | |
| 1809 | This section provides a description of each keyword and its usage. |
| 1810 | |
| 1811 | |
| 1812 | acl <aclname> <criterion> [flags] [operator] <value> ... |
| 1813 | Declare or complete an access list. |
| 1814 | May be used in sections : defaults | frontend | listen | backend |
| 1815 | no | yes | yes | yes |
| 1816 | Example: |
| 1817 | acl invalid_src src 0.0.0.0/7 224.0.0.0/3 |
| 1818 | acl invalid_src src_port 0:1023 |
| 1819 | acl local_dst hdr(host) -i localhost |
| 1820 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 1821 | See section 7 about ACL usage. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1822 | |
| 1823 | |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1824 | appsession <cookie> len <length> timeout <holdtime> |
| 1825 | [request-learn] [prefix] [mode <path-parameters|query-string>] |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1826 | Define session stickiness on an existing application cookie. |
| 1827 | May be used in sections : defaults | frontend | listen | backend |
| 1828 | no | no | yes | yes |
| 1829 | Arguments : |
| 1830 | <cookie> this is the name of the cookie used by the application and which |
| 1831 | HAProxy will have to learn for each new session. |
| 1832 | |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1833 | <length> this is the max number of characters that will be memorized and |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1834 | checked in each cookie value. |
| 1835 | |
| 1836 | <holdtime> this is the time after which the cookie will be removed from |
| 1837 | memory if unused. If no unit is specified, this time is in |
| 1838 | milliseconds. |
| 1839 | |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1840 | request-learn |
| 1841 | If this option is specified, then haproxy will be able to learn |
| 1842 | the cookie found in the request in case the server does not |
| 1843 | specify any in response. This is typically what happens with |
| 1844 | PHPSESSID cookies, or when haproxy's session expires before |
| 1845 | the application's session and the correct server is selected. |
| 1846 | It is recommended to specify this option to improve reliability. |
| 1847 | |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1848 | prefix When this option is specified, haproxy will match on the cookie |
| 1849 | prefix (or URL parameter prefix). The appsession value is the |
| 1850 | data following this prefix. |
| 1851 | |
| 1852 | Example : |
| 1853 | appsession ASPSESSIONID len 64 timeout 3h prefix |
| 1854 | |
| 1855 | This will match the cookie ASPSESSIONIDXXXX=XXXXX, |
| 1856 | the appsession value will be XXXX=XXXXX. |
| 1857 | |
| 1858 | mode This option allows to change the URL parser mode. |
| 1859 | 2 modes are currently supported : |
| 1860 | - path-parameters : |
| 1861 | The parser looks for the appsession in the path parameters |
| 1862 | part (each parameter is separated by a semi-colon), which is |
| 1863 | convenient for JSESSIONID for example. |
| 1864 | This is the default mode if the option is not set. |
| 1865 | - query-string : |
| 1866 | In this mode, the parser will look for the appsession in the |
| 1867 | query string. |
| 1868 | |
Willy Tarreau | 294d0f0 | 2015-08-10 19:40:12 +0200 | [diff] [blame] | 1869 | As of version 1.6, appsessions was removed. It is more flexible and more |
| 1870 | convenient to use stick-tables instead, and stick-tables support multi-master |
| 1871 | replication and data conservation across reloads, which appsessions did not. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1872 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 1873 | See also : "cookie", "capture cookie", "balance", "stick", "stick-table", |
| 1874 | "ignore-persist", "nbproc" and "bind-process". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1875 | |
| 1876 | |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1877 | backlog <conns> |
| 1878 | Give hints to the system about the approximate listen backlog desired size |
| 1879 | May be used in sections : defaults | frontend | listen | backend |
| 1880 | yes | yes | yes | no |
| 1881 | Arguments : |
| 1882 | <conns> is the number of pending connections. Depending on the operating |
| 1883 | system, it may represent the number of already acknowledged |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 1884 | connections, of non-acknowledged ones, or both. |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1885 | |
| 1886 | In order to protect against SYN flood attacks, one solution is to increase |
| 1887 | the system's SYN backlog size. Depending on the system, sometimes it is just |
| 1888 | tunable via a system parameter, sometimes it is not adjustable at all, and |
| 1889 | sometimes the system relies on hints given by the application at the time of |
| 1890 | the listen() syscall. By default, HAProxy passes the frontend's maxconn value |
| 1891 | to the listen() syscall. On systems which can make use of this value, it can |
| 1892 | sometimes be useful to be able to specify a different value, hence this |
| 1893 | backlog parameter. |
| 1894 | |
| 1895 | On Linux 2.4, the parameter is ignored by the system. On Linux 2.6, it is |
| 1896 | used as a hint and the system accepts up to the smallest greater power of |
| 1897 | two, and never more than some limits (usually 32768). |
| 1898 | |
| 1899 | See also : "maxconn" and the target operating system's tuning guide. |
| 1900 | |
| 1901 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1902 | balance <algorithm> [ <arguments> ] |
Willy Tarreau | 226071e | 2014-04-10 11:55:45 +0200 | [diff] [blame] | 1903 | balance url_param <param> [check_post] |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1904 | Define the load balancing algorithm to be used in a backend. |
| 1905 | May be used in sections : defaults | frontend | listen | backend |
| 1906 | yes | no | yes | yes |
| 1907 | Arguments : |
| 1908 | <algorithm> is the algorithm used to select a server when doing load |
| 1909 | balancing. This only applies when no persistence information |
| 1910 | is available, or when a connection is redispatched to another |
| 1911 | server. <algorithm> may be one of the following : |
| 1912 | |
| 1913 | roundrobin Each server is used in turns, according to their weights. |
| 1914 | This is the smoothest and fairest algorithm when the server's |
| 1915 | processing time remains equally distributed. This algorithm |
| 1916 | is dynamic, which means that server weights may be adjusted |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 1917 | on the fly for slow starts for instance. It is limited by |
Godbach | a34bdc0 | 2013-07-22 07:44:53 +0800 | [diff] [blame] | 1918 | design to 4095 active servers per backend. Note that in some |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 1919 | large farms, when a server becomes up after having been down |
| 1920 | for a very short time, it may sometimes take a few hundreds |
| 1921 | requests for it to be re-integrated into the farm and start |
| 1922 | receiving traffic. This is normal, though very rare. It is |
| 1923 | indicated here in case you would have the chance to observe |
| 1924 | it, so that you don't worry. |
| 1925 | |
| 1926 | static-rr Each server is used in turns, according to their weights. |
| 1927 | This algorithm is as similar to roundrobin except that it is |
| 1928 | static, which means that changing a server's weight on the |
| 1929 | fly will have no effect. On the other hand, it has no design |
| 1930 | limitation on the number of servers, and when a server goes |
| 1931 | up, it is always immediately reintroduced into the farm, once |
| 1932 | the full map is recomputed. It also uses slightly less CPU to |
| 1933 | run (around -1%). |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1934 | |
Willy Tarreau | 2d2a7f8 | 2008-03-17 12:07:56 +0100 | [diff] [blame] | 1935 | leastconn The server with the lowest number of connections receives the |
| 1936 | connection. Round-robin is performed within groups of servers |
| 1937 | of the same load to ensure that all servers will be used. Use |
| 1938 | of this algorithm is recommended where very long sessions are |
| 1939 | expected, such as LDAP, SQL, TSE, etc... but is not very well |
| 1940 | suited for protocols using short sessions such as HTTP. This |
| 1941 | algorithm is dynamic, which means that server weights may be |
| 1942 | adjusted on the fly for slow starts for instance. |
| 1943 | |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 1944 | first The first server with available connection slots receives the |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 1945 | connection. The servers are chosen from the lowest numeric |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 1946 | identifier to the highest (see server parameter "id"), which |
| 1947 | defaults to the server's position in the farm. Once a server |
Willy Tarreau | 64559c5 | 2012-04-07 09:08:45 +0200 | [diff] [blame] | 1948 | reaches its maxconn value, the next server is used. It does |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 1949 | not make sense to use this algorithm without setting maxconn. |
| 1950 | The purpose of this algorithm is to always use the smallest |
| 1951 | number of servers so that extra servers can be powered off |
| 1952 | during non-intensive hours. This algorithm ignores the server |
| 1953 | weight, and brings more benefit to long session such as RDP |
Willy Tarreau | 64559c5 | 2012-04-07 09:08:45 +0200 | [diff] [blame] | 1954 | or IMAP than HTTP, though it can be useful there too. In |
| 1955 | order to use this algorithm efficiently, it is recommended |
| 1956 | that a cloud controller regularly checks server usage to turn |
| 1957 | them off when unused, and regularly checks backend queue to |
| 1958 | turn new servers on when the queue inflates. Alternatively, |
| 1959 | using "http-check send-state" may inform servers on the load. |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 1960 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1961 | source The source IP address is hashed and divided by the total |
| 1962 | weight of the running servers to designate which server will |
| 1963 | receive the request. This ensures that the same client IP |
| 1964 | address will always reach the same server as long as no |
| 1965 | server goes down or up. If the hash result changes due to the |
| 1966 | number of running servers changing, many clients will be |
| 1967 | directed to a different server. This algorithm is generally |
| 1968 | used in TCP mode where no cookie may be inserted. It may also |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 1969 | be used on the Internet to provide a best-effort stickiness |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1970 | to clients which refuse session cookies. This algorithm is |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 1971 | static by default, which means that changing a server's |
| 1972 | weight on the fly will have no effect, but this can be |
| 1973 | changed using "hash-type". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1974 | |
Oskar Stolc | 8dc4184 | 2012-05-19 10:19:54 +0100 | [diff] [blame] | 1975 | uri This algorithm hashes either the left part of the URI (before |
| 1976 | the question mark) or the whole URI (if the "whole" parameter |
| 1977 | is present) and divides the hash value by the total weight of |
| 1978 | the running servers. The result designates which server will |
| 1979 | receive the request. This ensures that the same URI will |
| 1980 | always be directed to the same server as long as no server |
| 1981 | goes up or down. This is used with proxy caches and |
| 1982 | anti-virus proxies in order to maximize the cache hit rate. |
| 1983 | Note that this algorithm may only be used in an HTTP backend. |
| 1984 | This algorithm is static by default, which means that |
| 1985 | changing a server's weight on the fly will have no effect, |
| 1986 | but this can be changed using "hash-type". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1987 | |
Oskar Stolc | 8dc4184 | 2012-05-19 10:19:54 +0100 | [diff] [blame] | 1988 | This algorithm supports two optional parameters "len" and |
Marek Majkowski | 9c30fc1 | 2008-04-27 23:25:55 +0200 | [diff] [blame] | 1989 | "depth", both followed by a positive integer number. These |
| 1990 | options may be helpful when it is needed to balance servers |
| 1991 | based on the beginning of the URI only. The "len" parameter |
| 1992 | indicates that the algorithm should only consider that many |
| 1993 | characters at the beginning of the URI to compute the hash. |
| 1994 | Note that having "len" set to 1 rarely makes sense since most |
| 1995 | URIs start with a leading "/". |
| 1996 | |
| 1997 | The "depth" parameter indicates the maximum directory depth |
| 1998 | to be used to compute the hash. One level is counted for each |
| 1999 | slash in the request. If both parameters are specified, the |
| 2000 | evaluation stops when either is reached. |
| 2001 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2002 | url_param The URL parameter specified in argument will be looked up in |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 2003 | the query string of each HTTP GET request. |
| 2004 | |
| 2005 | If the modifier "check_post" is used, then an HTTP POST |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 2006 | request entity will be searched for the parameter argument, |
| 2007 | when it is not found in a query string after a question mark |
Willy Tarreau | 226071e | 2014-04-10 11:55:45 +0200 | [diff] [blame] | 2008 | ('?') in the URL. The message body will only start to be |
| 2009 | analyzed once either the advertised amount of data has been |
| 2010 | received or the request buffer is full. In the unlikely event |
| 2011 | that chunked encoding is used, only the first chunk is |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 2012 | scanned. Parameter values separated by a chunk boundary, may |
Willy Tarreau | 226071e | 2014-04-10 11:55:45 +0200 | [diff] [blame] | 2013 | be randomly balanced if at all. This keyword used to support |
| 2014 | an optional <max_wait> parameter which is now ignored. |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 2015 | |
| 2016 | If the parameter is found followed by an equal sign ('=') and |
| 2017 | a value, then the value is hashed and divided by the total |
| 2018 | weight of the running servers. The result designates which |
| 2019 | server will receive the request. |
| 2020 | |
| 2021 | This is used to track user identifiers in requests and ensure |
| 2022 | that a same user ID will always be sent to the same server as |
| 2023 | long as no server goes up or down. If no value is found or if |
| 2024 | the parameter is not found, then a round robin algorithm is |
| 2025 | applied. Note that this algorithm may only be used in an HTTP |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 2026 | backend. This algorithm is static by default, which means |
| 2027 | that changing a server's weight on the fly will have no |
| 2028 | effect, but this can be changed using "hash-type". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2029 | |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 2030 | hdr(<name>) The HTTP header <name> will be looked up in each HTTP |
| 2031 | request. Just as with the equivalent ACL 'hdr()' function, |
| 2032 | the header name in parenthesis is not case sensitive. If the |
| 2033 | header is absent or if it does not contain any value, the |
| 2034 | roundrobin algorithm is applied instead. |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2035 | |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 2036 | An optional 'use_domain_only' parameter is available, for |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2037 | reducing the hash algorithm to the main domain part with some |
| 2038 | specific headers such as 'Host'. For instance, in the Host |
| 2039 | value "haproxy.1wt.eu", only "1wt" will be considered. |
| 2040 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 2041 | This algorithm is static by default, which means that |
| 2042 | changing a server's weight on the fly will have no effect, |
| 2043 | but this can be changed using "hash-type". |
| 2044 | |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 2045 | rdp-cookie |
Hervé COMMOWICK | a3eb39c | 2011-08-05 18:48:51 +0200 | [diff] [blame] | 2046 | rdp-cookie(<name>) |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 2047 | The RDP cookie <name> (or "mstshash" if omitted) will be |
| 2048 | looked up and hashed for each incoming TCP request. Just as |
| 2049 | with the equivalent ACL 'req_rdp_cookie()' function, the name |
| 2050 | is not case-sensitive. This mechanism is useful as a degraded |
| 2051 | persistence mode, as it makes it possible to always send the |
| 2052 | same user (or the same session ID) to the same server. If the |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 2053 | cookie is not found, the normal roundrobin algorithm is |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 2054 | used instead. |
| 2055 | |
| 2056 | Note that for this to work, the frontend must ensure that an |
| 2057 | RDP cookie is already present in the request buffer. For this |
| 2058 | you must use 'tcp-request content accept' rule combined with |
| 2059 | a 'req_rdp_cookie_cnt' ACL. |
| 2060 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 2061 | This algorithm is static by default, which means that |
| 2062 | changing a server's weight on the fly will have no effect, |
| 2063 | but this can be changed using "hash-type". |
| 2064 | |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 2065 | See also the rdp_cookie pattern fetch function. |
Simon Horman | ab814e0 | 2011-06-24 14:50:20 +0900 | [diff] [blame] | 2066 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2067 | <arguments> is an optional list of arguments which may be needed by some |
Marek Majkowski | 9c30fc1 | 2008-04-27 23:25:55 +0200 | [diff] [blame] | 2068 | algorithms. Right now, only "url_param" and "uri" support an |
| 2069 | optional argument. |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 2070 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 2071 | The load balancing algorithm of a backend is set to roundrobin when no other |
| 2072 | algorithm, mode nor option have been set. The algorithm may only be set once |
| 2073 | for each backend. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2074 | |
| 2075 | Examples : |
| 2076 | balance roundrobin |
| 2077 | balance url_param userid |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 2078 | balance url_param session_id check_post 64 |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2079 | balance hdr(User-Agent) |
| 2080 | balance hdr(host) |
| 2081 | balance hdr(Host) use_domain_only |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 2082 | |
| 2083 | Note: the following caveats and limitations on using the "check_post" |
| 2084 | extension with "url_param" must be considered : |
| 2085 | |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 2086 | - all POST requests are eligible for consideration, because there is no way |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 2087 | to determine if the parameters will be found in the body or entity which |
| 2088 | may contain binary data. Therefore another method may be required to |
| 2089 | restrict consideration of POST requests that have no URL parameters in |
| 2090 | the body. (see acl reqideny http_end) |
| 2091 | |
| 2092 | - using a <max_wait> value larger than the request buffer size does not |
| 2093 | make sense and is useless. The buffer size is set at build time, and |
| 2094 | defaults to 16 kB. |
| 2095 | |
| 2096 | - Content-Encoding is not supported, the parameter search will probably |
| 2097 | fail; and load balancing will fall back to Round Robin. |
| 2098 | |
| 2099 | - Expect: 100-continue is not supported, load balancing will fall back to |
| 2100 | Round Robin. |
| 2101 | |
| 2102 | - Transfer-Encoding (RFC2616 3.6.1) is only supported in the first chunk. |
| 2103 | If the entire parameter value is not present in the first chunk, the |
| 2104 | selection of server is undefined (actually, defined by how little |
| 2105 | actually appeared in the first chunk). |
| 2106 | |
| 2107 | - This feature does not support generation of a 100, 411 or 501 response. |
| 2108 | |
| 2109 | - In some cases, requesting "check_post" MAY attempt to scan the entire |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 2110 | contents of a message body. Scanning normally terminates when linear |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 2111 | white space or control characters are found, indicating the end of what |
| 2112 | might be a URL parameter list. This is probably not a concern with SGML |
| 2113 | type message bodies. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2114 | |
Willy Tarreau | 294d0f0 | 2015-08-10 19:40:12 +0200 | [diff] [blame] | 2115 | See also : "dispatch", "cookie", "transparent", "hash-type" and "http_proxy". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2116 | |
| 2117 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 2118 | bind [<address>]:<port_range> [, ...] [param*] |
| 2119 | bind /<path> [, ...] [param*] |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2120 | Define one or several listening addresses and/or ports in a frontend. |
| 2121 | May be used in sections : defaults | frontend | listen | backend |
| 2122 | no | yes | yes | no |
| 2123 | Arguments : |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2124 | <address> is optional and can be a host name, an IPv4 address, an IPv6 |
| 2125 | address, or '*'. It designates the address the frontend will |
| 2126 | listen on. If unset, all IPv4 addresses of the system will be |
| 2127 | listened on. The same will apply for '*' or the system's |
David du Colombier | 9c938da | 2011-03-17 10:40:27 +0100 | [diff] [blame] | 2128 | special address "0.0.0.0". The IPv6 equivalent is '::'. |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2129 | Optionally, an address family prefix may be used before the |
| 2130 | address to force the family regardless of the address format, |
| 2131 | which can be useful to specify a path to a unix socket with |
| 2132 | no slash ('/'). Currently supported prefixes are : |
| 2133 | - 'ipv4@' -> address is always IPv4 |
| 2134 | - 'ipv6@' -> address is always IPv6 |
| 2135 | - 'unix@' -> address is a path to a local unix socket |
Willy Tarreau | 70f72e0 | 2014-07-08 00:37:50 +0200 | [diff] [blame] | 2136 | - 'abns@' -> address is in abstract namespace (Linux only). |
| 2137 | Note: since abstract sockets are not "rebindable", they |
| 2138 | do not cope well with multi-process mode during |
| 2139 | soft-restart, so it is better to avoid them if |
| 2140 | nbproc is greater than 1. The effect is that if the |
| 2141 | new process fails to start, only one of the old ones |
| 2142 | will be able to rebind to the socket. |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 2143 | - 'fd@<n>' -> use file descriptor <n> inherited from the |
| 2144 | parent. The fd must be bound and may or may not already |
| 2145 | be listening. |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 2146 | You may want to reference some environment variables in the |
| 2147 | address parameter, see section 2.3 about environment |
| 2148 | variables. |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2149 | |
Willy Tarreau | c5011ca | 2010-03-22 11:53:56 +0100 | [diff] [blame] | 2150 | <port_range> is either a unique TCP port, or a port range for which the |
| 2151 | proxy will accept connections for the IP address specified |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 2152 | above. The port is mandatory for TCP listeners. Note that in |
| 2153 | the case of an IPv6 address, the port is always the number |
| 2154 | after the last colon (':'). A range can either be : |
Willy Tarreau | c5011ca | 2010-03-22 11:53:56 +0100 | [diff] [blame] | 2155 | - a numerical port (ex: '80') |
| 2156 | - a dash-delimited ports range explicitly stating the lower |
| 2157 | and upper bounds (ex: '2000-2100') which are included in |
| 2158 | the range. |
| 2159 | |
| 2160 | Particular care must be taken against port ranges, because |
| 2161 | every <address:port> couple consumes one socket (= a file |
| 2162 | descriptor), so it's easy to consume lots of descriptors |
| 2163 | with a simple range, and to run out of sockets. Also, each |
| 2164 | <address:port> couple must be used only once among all |
| 2165 | instances running on a same system. Please note that binding |
| 2166 | to ports lower than 1024 generally require particular |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 2167 | privileges to start the program, which are independent of |
Willy Tarreau | c5011ca | 2010-03-22 11:53:56 +0100 | [diff] [blame] | 2168 | the 'uid' parameter. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2169 | |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 2170 | <path> is a UNIX socket path beginning with a slash ('/'). This is |
| 2171 | alternative to the TCP listening port. Haproxy will then |
| 2172 | receive UNIX connections on the socket located at this place. |
| 2173 | The path must begin with a slash and by default is absolute. |
| 2174 | It can be relative to the prefix defined by "unix-bind" in |
| 2175 | the global section. Note that the total length of the prefix |
| 2176 | followed by the socket path cannot exceed some system limits |
| 2177 | for UNIX sockets, which commonly are set to 107 characters. |
| 2178 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 2179 | <param*> is a list of parameters common to all sockets declared on the |
| 2180 | same line. These numerous parameters depend on OS and build |
| 2181 | options and have a complete section dedicated to them. Please |
| 2182 | refer to section 5 to for more details. |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 2183 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2184 | It is possible to specify a list of address:port combinations delimited by |
| 2185 | commas. The frontend will then listen on all of these addresses. There is no |
| 2186 | fixed limit to the number of addresses and ports which can be listened on in |
| 2187 | a frontend, as well as there is no limit to the number of "bind" statements |
| 2188 | in a frontend. |
| 2189 | |
| 2190 | Example : |
| 2191 | listen http_proxy |
| 2192 | bind :80,:443 |
| 2193 | bind 10.0.0.1:10080,10.0.0.1:10443 |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 2194 | bind /var/run/ssl-frontend.sock user root mode 600 accept-proxy |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2195 | |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 2196 | listen http_https_proxy |
| 2197 | bind :80 |
Cyril Bonté | 0d44fc6 | 2012-10-09 22:45:33 +0200 | [diff] [blame] | 2198 | bind :443 ssl crt /etc/haproxy/site.pem |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 2199 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2200 | listen http_https_proxy_explicit |
| 2201 | bind ipv6@:80 |
| 2202 | bind ipv4@public_ssl:443 ssl crt /etc/haproxy/site.pem |
| 2203 | bind unix@ssl-frontend.sock user root mode 600 accept-proxy |
| 2204 | |
Willy Tarreau | dad36a3 | 2013-03-11 01:20:04 +0100 | [diff] [blame] | 2205 | listen external_bind_app1 |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 2206 | bind "fd@${FD_APP1}" |
Willy Tarreau | dad36a3 | 2013-03-11 01:20:04 +0100 | [diff] [blame] | 2207 | |
Willy Tarreau | 55dcaf6 | 2015-09-27 15:03:15 +0200 | [diff] [blame] | 2208 | Note: regarding Linux's abstract namespace sockets, HAProxy uses the whole |
| 2209 | sun_path length is used for the address length. Some other programs |
| 2210 | such as socat use the string length only by default. Pass the option |
| 2211 | ",unix-tightsocklen=0" to any abstract socket definition in socat to |
| 2212 | make it compatible with HAProxy's. |
| 2213 | |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 2214 | See also : "source", "option forwardfor", "unix-bind" and the PROXY protocol |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 2215 | documentation, and section 5 about bind options. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2216 | |
| 2217 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2218 | bind-process [ all | odd | even | <number 1-64>[-<number 1-64>] ] ... |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2219 | Limit visibility of an instance to a certain set of processes numbers. |
| 2220 | May be used in sections : defaults | frontend | listen | backend |
| 2221 | yes | yes | yes | yes |
| 2222 | Arguments : |
| 2223 | all All process will see this instance. This is the default. It |
| 2224 | may be used to override a default value. |
| 2225 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2226 | odd This instance will be enabled on processes 1,3,5,...63. This |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2227 | option may be combined with other numbers. |
| 2228 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2229 | even This instance will be enabled on processes 2,4,6,...64. This |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2230 | option may be combined with other numbers. Do not use it |
| 2231 | with less than 2 processes otherwise some instances might be |
| 2232 | missing from all processes. |
| 2233 | |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2234 | number The instance will be enabled on this process number or range, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2235 | whose values must all be between 1 and 32 or 64 depending on |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 2236 | the machine's word size. If a proxy is bound to process |
| 2237 | numbers greater than the configured global.nbproc, it will |
| 2238 | either be forced to process #1 if a single process was |
| 2239 | specified, or to all processes otherwise. |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2240 | |
| 2241 | This keyword limits binding of certain instances to certain processes. This |
| 2242 | is useful in order not to have too many processes listening to the same |
| 2243 | ports. For instance, on a dual-core machine, it might make sense to set |
| 2244 | 'nbproc 2' in the global section, then distributes the listeners among 'odd' |
| 2245 | and 'even' instances. |
| 2246 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2247 | At the moment, it is not possible to reference more than 32 or 64 processes |
| 2248 | using this keyword, but this should be more than enough for most setups. |
| 2249 | Please note that 'all' really means all processes regardless of the machine's |
| 2250 | word size, and is not limited to the first 32 or 64. |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2251 | |
Willy Tarreau | 6ae1ba6 | 2014-05-07 19:01:58 +0200 | [diff] [blame] | 2252 | Each "bind" line may further be limited to a subset of the proxy's processes, |
| 2253 | please consult the "process" bind keyword in section 5.1. |
| 2254 | |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 2255 | When a frontend has no explicit "bind-process" line, it tries to bind to all |
| 2256 | the processes referenced by its "bind" lines. That means that frontends can |
| 2257 | easily adapt to their listeners' processes. |
| 2258 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2259 | If some backends are referenced by frontends bound to other processes, the |
| 2260 | backend automatically inherits the frontend's processes. |
| 2261 | |
| 2262 | Example : |
| 2263 | listen app_ip1 |
| 2264 | bind 10.0.0.1:80 |
Willy Tarreau | bfcd311 | 2010-10-23 11:22:08 +0200 | [diff] [blame] | 2265 | bind-process odd |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2266 | |
| 2267 | listen app_ip2 |
| 2268 | bind 10.0.0.2:80 |
Willy Tarreau | bfcd311 | 2010-10-23 11:22:08 +0200 | [diff] [blame] | 2269 | bind-process even |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2270 | |
| 2271 | listen management |
| 2272 | bind 10.0.0.3:80 |
Willy Tarreau | bfcd311 | 2010-10-23 11:22:08 +0200 | [diff] [blame] | 2273 | bind-process 1 2 3 4 |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2274 | |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2275 | listen management |
| 2276 | bind 10.0.0.4:80 |
| 2277 | bind-process 1-4 |
| 2278 | |
Willy Tarreau | 6ae1ba6 | 2014-05-07 19:01:58 +0200 | [diff] [blame] | 2279 | See also : "nbproc" in global section, and "process" in section 5.1. |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2280 | |
| 2281 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2282 | block { if | unless } <condition> |
| 2283 | Block a layer 7 request if/unless a condition is matched |
| 2284 | May be used in sections : defaults | frontend | listen | backend |
| 2285 | no | yes | yes | yes |
| 2286 | |
| 2287 | The HTTP request will be blocked very early in the layer 7 processing |
| 2288 | if/unless <condition> is matched. A 403 error will be returned if the request |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 2289 | is blocked. The condition has to reference ACLs (see section 7). This is |
Willy Tarreau | 3c92c5f | 2011-08-28 09:45:47 +0200 | [diff] [blame] | 2290 | typically used to deny access to certain sensitive resources if some |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2291 | conditions are met or not met. There is no fixed limit to the number of |
| 2292 | "block" statements per instance. |
| 2293 | |
| 2294 | Example: |
| 2295 | acl invalid_src src 0.0.0.0/7 224.0.0.0/3 |
| 2296 | acl invalid_src src_port 0:1023 |
| 2297 | acl local_dst hdr(host) -i localhost |
| 2298 | block if invalid_src || local_dst |
| 2299 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 2300 | See section 7 about ACL usage. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2301 | |
| 2302 | |
| 2303 | capture cookie <name> len <length> |
| 2304 | Capture and log a cookie in the request and in the response. |
| 2305 | May be used in sections : defaults | frontend | listen | backend |
| 2306 | no | yes | yes | no |
| 2307 | Arguments : |
| 2308 | <name> is the beginning of the name of the cookie to capture. In order |
| 2309 | to match the exact name, simply suffix the name with an equal |
| 2310 | sign ('='). The full name will appear in the logs, which is |
| 2311 | useful with application servers which adjust both the cookie name |
| 2312 | and value (eg: ASPSESSIONXXXXX). |
| 2313 | |
| 2314 | <length> is the maximum number of characters to report in the logs, which |
| 2315 | include the cookie name, the equal sign and the value, all in the |
| 2316 | standard "name=value" form. The string will be truncated on the |
| 2317 | right if it exceeds <length>. |
| 2318 | |
| 2319 | Only the first cookie is captured. Both the "cookie" request headers and the |
| 2320 | "set-cookie" response headers are monitored. This is particularly useful to |
| 2321 | check for application bugs causing session crossing or stealing between |
| 2322 | users, because generally the user's cookies can only change on a login page. |
| 2323 | |
| 2324 | When the cookie was not presented by the client, the associated log column |
| 2325 | will report "-". When a request does not cause a cookie to be assigned by the |
| 2326 | server, a "-" is reported in the response column. |
| 2327 | |
| 2328 | The capture is performed in the frontend only because it is necessary that |
| 2329 | the log format does not change for a given frontend depending on the |
| 2330 | backends. This may change in the future. Note that there can be only one |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 2331 | "capture cookie" statement in a frontend. The maximum capture length is set |
| 2332 | by the global "tune.http.cookielen" setting and defaults to 63 characters. It |
| 2333 | is not possible to specify a capture in a "defaults" section. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2334 | |
| 2335 | Example: |
| 2336 | capture cookie ASPSESSION len 32 |
| 2337 | |
| 2338 | See also : "capture request header", "capture response header" as well as |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 2339 | section 8 about logging. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2340 | |
| 2341 | |
| 2342 | capture request header <name> len <length> |
Willy Tarreau | 4460d03 | 2012-11-21 23:37:37 +0100 | [diff] [blame] | 2343 | Capture and log the last occurrence of the specified request header. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2344 | May be used in sections : defaults | frontend | listen | backend |
| 2345 | no | yes | yes | no |
| 2346 | Arguments : |
| 2347 | <name> is the name of the header to capture. The header names are not |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 2348 | case-sensitive, but it is a common practice to write them as they |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2349 | appear in the requests, with the first letter of each word in |
| 2350 | upper case. The header name will not appear in the logs, only the |
| 2351 | value is reported, but the position in the logs is respected. |
| 2352 | |
| 2353 | <length> is the maximum number of characters to extract from the value and |
| 2354 | report in the logs. The string will be truncated on the right if |
| 2355 | it exceeds <length>. |
| 2356 | |
Willy Tarreau | 4460d03 | 2012-11-21 23:37:37 +0100 | [diff] [blame] | 2357 | The complete value of the last occurrence of the header is captured. The |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2358 | value will be added to the logs between braces ('{}'). If multiple headers |
| 2359 | are captured, they will be delimited by a vertical bar ('|') and will appear |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 2360 | in the same order they were declared in the configuration. Non-existent |
| 2361 | headers will be logged just as an empty string. Common uses for request |
| 2362 | header captures include the "Host" field in virtual hosting environments, the |
| 2363 | "Content-length" when uploads are supported, "User-agent" to quickly |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 2364 | differentiate between real users and robots, and "X-Forwarded-For" in proxied |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 2365 | environments to find where the request came from. |
| 2366 | |
| 2367 | Note that when capturing headers such as "User-agent", some spaces may be |
| 2368 | logged, making the log analysis more difficult. Thus be careful about what |
| 2369 | you log if you know your log parser is not smart enough to rely on the |
| 2370 | braces. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2371 | |
Willy Tarreau | 0900abb | 2012-11-22 00:21:46 +0100 | [diff] [blame] | 2372 | There is no limit to the number of captured request headers nor to their |
| 2373 | length, though it is wise to keep them low to limit memory usage per session. |
| 2374 | In order to keep log format consistent for a same frontend, header captures |
| 2375 | can only be declared in a frontend. It is not possible to specify a capture |
| 2376 | in a "defaults" section. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2377 | |
| 2378 | Example: |
| 2379 | capture request header Host len 15 |
| 2380 | capture request header X-Forwarded-For len 15 |
| 2381 | capture request header Referrer len 15 |
| 2382 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 2383 | See also : "capture cookie", "capture response header" as well as section 8 |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2384 | about logging. |
| 2385 | |
| 2386 | |
| 2387 | capture response header <name> len <length> |
Willy Tarreau | 4460d03 | 2012-11-21 23:37:37 +0100 | [diff] [blame] | 2388 | Capture and log the last occurrence of the specified response header. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2389 | May be used in sections : defaults | frontend | listen | backend |
| 2390 | no | yes | yes | no |
| 2391 | Arguments : |
| 2392 | <name> is the name of the header to capture. The header names are not |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 2393 | case-sensitive, but it is a common practice to write them as they |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2394 | appear in the response, with the first letter of each word in |
| 2395 | upper case. The header name will not appear in the logs, only the |
| 2396 | value is reported, but the position in the logs is respected. |
| 2397 | |
| 2398 | <length> is the maximum number of characters to extract from the value and |
| 2399 | report in the logs. The string will be truncated on the right if |
| 2400 | it exceeds <length>. |
| 2401 | |
Willy Tarreau | 4460d03 | 2012-11-21 23:37:37 +0100 | [diff] [blame] | 2402 | The complete value of the last occurrence of the header is captured. The |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2403 | result will be added to the logs between braces ('{}') after the captured |
| 2404 | request headers. If multiple headers are captured, they will be delimited by |
| 2405 | a vertical bar ('|') and will appear in the same order they were declared in |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 2406 | the configuration. Non-existent headers will be logged just as an empty |
| 2407 | string. Common uses for response header captures include the "Content-length" |
| 2408 | header which indicates how many bytes are expected to be returned, the |
| 2409 | "Location" header to track redirections. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2410 | |
Willy Tarreau | 0900abb | 2012-11-22 00:21:46 +0100 | [diff] [blame] | 2411 | There is no limit to the number of captured response headers nor to their |
| 2412 | length, though it is wise to keep them low to limit memory usage per session. |
| 2413 | In order to keep log format consistent for a same frontend, header captures |
| 2414 | can only be declared in a frontend. It is not possible to specify a capture |
| 2415 | in a "defaults" section. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2416 | |
| 2417 | Example: |
| 2418 | capture response header Content-length len 9 |
| 2419 | capture response header Location len 15 |
| 2420 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 2421 | See also : "capture cookie", "capture request header" as well as section 8 |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2422 | about logging. |
| 2423 | |
| 2424 | |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 2425 | clitimeout <timeout> (deprecated) |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2426 | Set the maximum inactivity time on the client side. |
| 2427 | May be used in sections : defaults | frontend | listen | backend |
| 2428 | yes | yes | yes | no |
| 2429 | Arguments : |
| 2430 | <timeout> is the timeout value is specified in milliseconds by default, but |
| 2431 | can be in any other unit if the number is suffixed by the unit, |
| 2432 | as explained at the top of this document. |
| 2433 | |
| 2434 | The inactivity timeout applies when the client is expected to acknowledge or |
| 2435 | send data. In HTTP mode, this timeout is particularly important to consider |
| 2436 | during the first phase, when the client sends the request, and during the |
| 2437 | response while it is reading data sent by the server. The value is specified |
| 2438 | in milliseconds by default, but can be in any other unit if the number is |
| 2439 | suffixed by the unit, as specified at the top of this document. In TCP mode |
| 2440 | (and to a lesser extent, in HTTP mode), it is highly recommended that the |
| 2441 | client timeout remains equal to the server timeout in order to avoid complex |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 2442 | situations to debug. It is a good practice to cover one or several TCP packet |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2443 | losses by specifying timeouts that are slightly above multiples of 3 seconds |
| 2444 | (eg: 4 or 5 seconds). |
| 2445 | |
| 2446 | This parameter is specific to frontends, but can be specified once for all in |
| 2447 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 2448 | forget about it. An unspecified timeout results in an infinite timeout, which |
| 2449 | is not recommended. Such a usage is accepted and works but reports a warning |
| 2450 | during startup because it may results in accumulation of expired sessions in |
| 2451 | the system if the system's timeouts are not configured either. |
| 2452 | |
| 2453 | This parameter is provided for compatibility but is currently deprecated. |
| 2454 | Please use "timeout client" instead. |
| 2455 | |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2456 | See also : "timeout client", "timeout http-request", "timeout server", and |
| 2457 | "srvtimeout". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2458 | |
Cyril Bonté | 316a8cf | 2012-11-11 13:38:27 +0100 | [diff] [blame] | 2459 | compression algo <algorithm> ... |
| 2460 | compression type <mime type> ... |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 2461 | compression offload |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2462 | Enable HTTP compression. |
| 2463 | May be used in sections : defaults | frontend | listen | backend |
| 2464 | yes | yes | yes | yes |
| 2465 | Arguments : |
Cyril Bonté | 316a8cf | 2012-11-11 13:38:27 +0100 | [diff] [blame] | 2466 | algo is followed by the list of supported compression algorithms. |
| 2467 | type is followed by the list of MIME types that will be compressed. |
| 2468 | offload makes haproxy work as a compression offloader only (see notes). |
| 2469 | |
| 2470 | The currently supported algorithms are : |
Willy Tarreau | c91840a | 2015-03-28 17:00:39 +0100 | [diff] [blame] | 2471 | identity this is mostly for debugging, and it was useful for developing |
| 2472 | the compression feature. Identity does not apply any change on |
| 2473 | data. |
Cyril Bonté | 316a8cf | 2012-11-11 13:38:27 +0100 | [diff] [blame] | 2474 | |
Willy Tarreau | c91840a | 2015-03-28 17:00:39 +0100 | [diff] [blame] | 2475 | gzip applies gzip compression. This setting is only available when |
| 2476 | support for zlib was built in. |
| 2477 | |
| 2478 | deflate same as "gzip", but with deflate algorithm and zlib format. |
| 2479 | Note that this algorithm has ambiguous support on many |
| 2480 | browsers and no support at all from recent ones. It is |
| 2481 | strongly recommended not to use it for anything else than |
| 2482 | experimentation. This setting is only available when support |
| 2483 | for zlib was built in. |
Cyril Bonté | 316a8cf | 2012-11-11 13:38:27 +0100 | [diff] [blame] | 2484 | |
Willy Tarreau | c91840a | 2015-03-28 17:00:39 +0100 | [diff] [blame] | 2485 | raw-deflate same as "deflate" without the zlib wrapper, and used as an |
| 2486 | alternative when the browser wants "deflate". All major |
| 2487 | browsers understand it and despite violating the standards, |
| 2488 | it is known to work better than "deflate", at least on MSIE |
| 2489 | and some versions of Safari. Do not use it in conjunction |
| 2490 | with "deflate", use either one or the other since both react |
| 2491 | to the same Accept-Encoding token. This setting is only |
| 2492 | available when support for zlib was built in. |
Cyril Bonté | 316a8cf | 2012-11-11 13:38:27 +0100 | [diff] [blame] | 2493 | |
Dmitry Sivachenko | 87c208b | 2012-11-22 20:03:26 +0400 | [diff] [blame] | 2494 | Compression will be activated depending on the Accept-Encoding request |
Cyril Bonté | 316a8cf | 2012-11-11 13:38:27 +0100 | [diff] [blame] | 2495 | header. With identity, it does not take care of that header. |
Dmitry Sivachenko | c9f3b45 | 2012-11-28 17:47:11 +0400 | [diff] [blame] | 2496 | If backend servers support HTTP compression, these directives |
| 2497 | will be no-op: haproxy will see the compressed response and will not |
| 2498 | compress again. If backend servers do not support HTTP compression and |
| 2499 | there is Accept-Encoding header in request, haproxy will compress the |
| 2500 | matching response. |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 2501 | |
| 2502 | The "offload" setting makes haproxy remove the Accept-Encoding header to |
| 2503 | prevent backend servers from compressing responses. It is strongly |
| 2504 | recommended not to do this because this means that all the compression work |
| 2505 | will be done on the single point where haproxy is located. However in some |
| 2506 | deployment scenarios, haproxy may be installed in front of a buggy gateway |
Dmitry Sivachenko | c9f3b45 | 2012-11-28 17:47:11 +0400 | [diff] [blame] | 2507 | with broken HTTP compression implementation which can't be turned off. |
| 2508 | In that case haproxy can be used to prevent that gateway from emitting |
| 2509 | invalid payloads. In this case, simply removing the header in the |
| 2510 | configuration does not work because it applies before the header is parsed, |
| 2511 | so that prevents haproxy from compressing. The "offload" setting should |
Willy Tarreau | ffea9fd | 2014-07-12 16:37:02 +0200 | [diff] [blame] | 2512 | then be used for such scenarios. Note: for now, the "offload" setting is |
| 2513 | ignored when set in a defaults section. |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2514 | |
William Lallemand | 0509744 | 2012-11-20 12:14:28 +0100 | [diff] [blame] | 2515 | Compression is disabled when: |
Baptiste Assmann | 650d53d | 2013-01-05 15:44:44 +0100 | [diff] [blame] | 2516 | * the request does not advertise a supported compression algorithm in the |
| 2517 | "Accept-Encoding" header |
| 2518 | * the response message is not HTTP/1.1 |
William Lallemand | d300261 | 2012-11-26 14:34:47 +0100 | [diff] [blame] | 2519 | * HTTP status code is not 200 |
William Lallemand | 8bb4e34 | 2013-12-10 17:28:48 +0100 | [diff] [blame] | 2520 | * response header "Transfer-Encoding" contains "chunked" (Temporary |
| 2521 | Workaround) |
Baptiste Assmann | 650d53d | 2013-01-05 15:44:44 +0100 | [diff] [blame] | 2522 | * response contain neither a "Content-Length" header nor a |
| 2523 | "Transfer-Encoding" whose last value is "chunked" |
| 2524 | * response contains a "Content-Type" header whose first value starts with |
| 2525 | "multipart" |
| 2526 | * the response contains the "no-transform" value in the "Cache-control" |
| 2527 | header |
| 2528 | * User-Agent matches "Mozilla/4" unless it is MSIE 6 with XP SP2, or MSIE 7 |
| 2529 | and later |
| 2530 | * The response contains a "Content-Encoding" header, indicating that the |
| 2531 | response is already compressed (see compression offload) |
William Lallemand | 0509744 | 2012-11-20 12:14:28 +0100 | [diff] [blame] | 2532 | |
Baptiste Assmann | 650d53d | 2013-01-05 15:44:44 +0100 | [diff] [blame] | 2533 | Note: The compression does not rewrite Etag headers, and does not emit the |
| 2534 | Warning header. |
William Lallemand | 0509744 | 2012-11-20 12:14:28 +0100 | [diff] [blame] | 2535 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2536 | Examples : |
| 2537 | compression algo gzip |
| 2538 | compression type text/html text/plain |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2539 | |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 2540 | contimeout <timeout> (deprecated) |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2541 | Set the maximum time to wait for a connection attempt to a server to succeed. |
| 2542 | May be used in sections : defaults | frontend | listen | backend |
| 2543 | yes | no | yes | yes |
| 2544 | Arguments : |
| 2545 | <timeout> is the timeout value is specified in milliseconds by default, but |
| 2546 | can be in any other unit if the number is suffixed by the unit, |
| 2547 | as explained at the top of this document. |
| 2548 | |
| 2549 | If the server is located on the same LAN as haproxy, the connection should be |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 2550 | immediate (less than a few milliseconds). Anyway, it is a good practice to |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 2551 | cover one or several TCP packet losses by specifying timeouts that are |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2552 | slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the |
| 2553 | connect timeout also presets the queue timeout to the same value if this one |
| 2554 | has not been specified. Historically, the contimeout was also used to set the |
| 2555 | tarpit timeout in a listen section, which is not possible in a pure frontend. |
| 2556 | |
| 2557 | This parameter is specific to backends, but can be specified once for all in |
| 2558 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 2559 | forget about it. An unspecified timeout results in an infinite timeout, which |
| 2560 | is not recommended. Such a usage is accepted and works but reports a warning |
| 2561 | during startup because it may results in accumulation of failed sessions in |
| 2562 | the system if the system's timeouts are not configured either. |
| 2563 | |
| 2564 | This parameter is provided for backwards compatibility but is currently |
| 2565 | deprecated. Please use "timeout connect", "timeout queue" or "timeout tarpit" |
| 2566 | instead. |
| 2567 | |
| 2568 | See also : "timeout connect", "timeout queue", "timeout tarpit", |
| 2569 | "timeout server", "contimeout". |
| 2570 | |
| 2571 | |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 2572 | cookie <name> [ rewrite | insert | prefix ] [ indirect ] [ nocache ] |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2573 | [ postonly ] [ preserve ] [ httponly ] [ secure ] |
| 2574 | [ domain <domain> ]* [ maxidle <idle> ] [ maxlife <life> ] |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2575 | Enable cookie-based persistence in a backend. |
| 2576 | May be used in sections : defaults | frontend | listen | backend |
| 2577 | yes | no | yes | yes |
| 2578 | Arguments : |
| 2579 | <name> is the name of the cookie which will be monitored, modified or |
| 2580 | inserted in order to bring persistence. This cookie is sent to |
| 2581 | the client via a "Set-Cookie" header in the response, and is |
| 2582 | brought back by the client in a "Cookie" header in all requests. |
| 2583 | Special care should be taken to choose a name which does not |
| 2584 | conflict with any likely application cookie. Also, if the same |
| 2585 | backends are subject to be used by the same clients (eg: |
| 2586 | HTTP/HTTPS), care should be taken to use different cookie names |
| 2587 | between all backends if persistence between them is not desired. |
| 2588 | |
| 2589 | rewrite This keyword indicates that the cookie will be provided by the |
| 2590 | server and that haproxy will have to modify its value to set the |
| 2591 | server's identifier in it. This mode is handy when the management |
| 2592 | of complex combinations of "Set-cookie" and "Cache-control" |
| 2593 | headers is left to the application. The application can then |
| 2594 | decide whether or not it is appropriate to emit a persistence |
| 2595 | cookie. Since all responses should be monitored, this mode only |
| 2596 | works in HTTP close mode. Unless the application behaviour is |
| 2597 | very complex and/or broken, it is advised not to start with this |
| 2598 | mode for new deployments. This keyword is incompatible with |
| 2599 | "insert" and "prefix". |
| 2600 | |
| 2601 | insert This keyword indicates that the persistence cookie will have to |
Willy Tarreau | a79094d | 2010-08-31 22:54:15 +0200 | [diff] [blame] | 2602 | be inserted by haproxy in server responses if the client did not |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2603 | |
Willy Tarreau | a79094d | 2010-08-31 22:54:15 +0200 | [diff] [blame] | 2604 | already have a cookie that would have permitted it to access this |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2605 | server. When used without the "preserve" option, if the server |
| 2606 | emits a cookie with the same name, it will be remove before |
| 2607 | processing. For this reason, this mode can be used to upgrade |
| 2608 | existing configurations running in the "rewrite" mode. The cookie |
| 2609 | will only be a session cookie and will not be stored on the |
| 2610 | client's disk. By default, unless the "indirect" option is added, |
| 2611 | the server will see the cookies emitted by the client. Due to |
| 2612 | caching effects, it is generally wise to add the "nocache" or |
| 2613 | "postonly" keywords (see below). The "insert" keyword is not |
| 2614 | compatible with "rewrite" and "prefix". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2615 | |
| 2616 | prefix This keyword indicates that instead of relying on a dedicated |
| 2617 | cookie for the persistence, an existing one will be completed. |
| 2618 | This may be needed in some specific environments where the client |
| 2619 | does not support more than one single cookie and the application |
| 2620 | already needs it. In this case, whenever the server sets a cookie |
| 2621 | named <name>, it will be prefixed with the server's identifier |
| 2622 | and a delimiter. The prefix will be removed from all client |
| 2623 | requests so that the server still finds the cookie it emitted. |
| 2624 | Since all requests and responses are subject to being modified, |
| 2625 | this mode requires the HTTP close mode. The "prefix" keyword is |
Willy Tarreau | 37229df | 2011-10-17 12:24:55 +0200 | [diff] [blame] | 2626 | not compatible with "rewrite" and "insert". Note: it is highly |
| 2627 | recommended not to use "indirect" with "prefix", otherwise server |
| 2628 | cookie updates would not be sent to clients. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2629 | |
Willy Tarreau | a79094d | 2010-08-31 22:54:15 +0200 | [diff] [blame] | 2630 | indirect When this option is specified, no cookie will be emitted to a |
| 2631 | client which already has a valid one for the server which has |
| 2632 | processed the request. If the server sets such a cookie itself, |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2633 | it will be removed, unless the "preserve" option is also set. In |
| 2634 | "insert" mode, this will additionally remove cookies from the |
| 2635 | requests transmitted to the server, making the persistence |
| 2636 | mechanism totally transparent from an application point of view. |
Willy Tarreau | 37229df | 2011-10-17 12:24:55 +0200 | [diff] [blame] | 2637 | Note: it is highly recommended not to use "indirect" with |
| 2638 | "prefix", otherwise server cookie updates would not be sent to |
| 2639 | clients. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2640 | |
| 2641 | nocache This option is recommended in conjunction with the insert mode |
| 2642 | when there is a cache between the client and HAProxy, as it |
| 2643 | ensures that a cacheable response will be tagged non-cacheable if |
| 2644 | a cookie needs to be inserted. This is important because if all |
| 2645 | persistence cookies are added on a cacheable home page for |
| 2646 | instance, then all customers will then fetch the page from an |
| 2647 | outer cache and will all share the same persistence cookie, |
| 2648 | leading to one server receiving much more traffic than others. |
| 2649 | See also the "insert" and "postonly" options. |
| 2650 | |
| 2651 | postonly This option ensures that cookie insertion will only be performed |
| 2652 | on responses to POST requests. It is an alternative to the |
| 2653 | "nocache" option, because POST responses are not cacheable, so |
| 2654 | this ensures that the persistence cookie will never get cached. |
| 2655 | Since most sites do not need any sort of persistence before the |
| 2656 | first POST which generally is a login request, this is a very |
| 2657 | efficient method to optimize caching without risking to find a |
| 2658 | persistence cookie in the cache. |
| 2659 | See also the "insert" and "nocache" options. |
| 2660 | |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2661 | preserve This option may only be used with "insert" and/or "indirect". It |
| 2662 | allows the server to emit the persistence cookie itself. In this |
| 2663 | case, if a cookie is found in the response, haproxy will leave it |
| 2664 | untouched. This is useful in order to end persistence after a |
| 2665 | logout request for instance. For this, the server just has to |
| 2666 | emit a cookie with an invalid value (eg: empty) or with a date in |
| 2667 | the past. By combining this mechanism with the "disable-on-404" |
| 2668 | check option, it is possible to perform a completely graceful |
| 2669 | shutdown because users will definitely leave the server after |
| 2670 | they logout. |
| 2671 | |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2672 | httponly This option tells haproxy to add an "HttpOnly" cookie attribute |
| 2673 | when a cookie is inserted. This attribute is used so that a |
| 2674 | user agent doesn't share the cookie with non-HTTP components. |
| 2675 | Please check RFC6265 for more information on this attribute. |
| 2676 | |
| 2677 | secure This option tells haproxy to add a "Secure" cookie attribute when |
| 2678 | a cookie is inserted. This attribute is used so that a user agent |
| 2679 | never emits this cookie over non-secure channels, which means |
| 2680 | that a cookie learned with this flag will be presented only over |
| 2681 | SSL/TLS connections. Please check RFC6265 for more information on |
| 2682 | this attribute. |
| 2683 | |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2684 | domain This option allows to specify the domain at which a cookie is |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 2685 | inserted. It requires exactly one parameter: a valid domain |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2686 | name. If the domain begins with a dot, the browser is allowed to |
| 2687 | use it for any host ending with that name. It is also possible to |
| 2688 | specify several domain names by invoking this option multiple |
| 2689 | times. Some browsers might have small limits on the number of |
| 2690 | domains, so be careful when doing that. For the record, sending |
| 2691 | 10 domains to MSIE 6 or Firefox 2 works as expected. |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2692 | |
Willy Tarreau | 996a92c | 2010-10-13 19:30:47 +0200 | [diff] [blame] | 2693 | maxidle This option allows inserted cookies to be ignored after some idle |
| 2694 | time. It only works with insert-mode cookies. When a cookie is |
| 2695 | sent to the client, the date this cookie was emitted is sent too. |
| 2696 | Upon further presentations of this cookie, if the date is older |
| 2697 | than the delay indicated by the parameter (in seconds), it will |
| 2698 | be ignored. Otherwise, it will be refreshed if needed when the |
| 2699 | response is sent to the client. This is particularly useful to |
| 2700 | prevent users who never close their browsers from remaining for |
| 2701 | too long on the same server (eg: after a farm size change). When |
| 2702 | this option is set and a cookie has no date, it is always |
| 2703 | accepted, but gets refreshed in the response. This maintains the |
| 2704 | ability for admins to access their sites. Cookies that have a |
| 2705 | date in the future further than 24 hours are ignored. Doing so |
| 2706 | lets admins fix timezone issues without risking kicking users off |
| 2707 | the site. |
| 2708 | |
| 2709 | maxlife This option allows inserted cookies to be ignored after some life |
| 2710 | time, whether they're in use or not. It only works with insert |
| 2711 | mode cookies. When a cookie is first sent to the client, the date |
| 2712 | this cookie was emitted is sent too. Upon further presentations |
| 2713 | of this cookie, if the date is older than the delay indicated by |
| 2714 | the parameter (in seconds), it will be ignored. If the cookie in |
| 2715 | the request has no date, it is accepted and a date will be set. |
| 2716 | Cookies that have a date in the future further than 24 hours are |
| 2717 | ignored. Doing so lets admins fix timezone issues without risking |
| 2718 | kicking users off the site. Contrary to maxidle, this value is |
| 2719 | not refreshed, only the first visit date counts. Both maxidle and |
| 2720 | maxlife may be used at the time. This is particularly useful to |
| 2721 | prevent users who never close their browsers from remaining for |
| 2722 | too long on the same server (eg: after a farm size change). This |
| 2723 | is stronger than the maxidle method in that it forces a |
| 2724 | redispatch after some absolute delay. |
| 2725 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2726 | There can be only one persistence cookie per HTTP backend, and it can be |
| 2727 | declared in a defaults section. The value of the cookie will be the value |
| 2728 | indicated after the "cookie" keyword in a "server" statement. If no cookie |
| 2729 | is declared for a given server, the cookie is not set. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2730 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2731 | Examples : |
| 2732 | cookie JSESSIONID prefix |
| 2733 | cookie SRV insert indirect nocache |
| 2734 | cookie SRV insert postonly indirect |
Willy Tarreau | 996a92c | 2010-10-13 19:30:47 +0200 | [diff] [blame] | 2735 | cookie SRV insert indirect nocache maxidle 30m maxlife 8h |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2736 | |
Willy Tarreau | 294d0f0 | 2015-08-10 19:40:12 +0200 | [diff] [blame] | 2737 | See also : "balance source", "capture cookie", "server" and "ignore-persist". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2738 | |
Willy Tarreau | 983e01e | 2010-01-11 18:42:06 +0100 | [diff] [blame] | 2739 | |
Thierry FOURNIER | a0a1b75 | 2015-05-26 17:44:32 +0200 | [diff] [blame] | 2740 | declare capture [ request | response ] len <length> |
| 2741 | Declares a capture slot. |
| 2742 | May be used in sections : defaults | frontend | listen | backend |
| 2743 | no | yes | yes | no |
| 2744 | Arguments: |
| 2745 | <length> is the length allowed for the capture. |
| 2746 | |
| 2747 | This declaration is only available in the frontend or listen section, but the |
| 2748 | reserved slot can be used in the backends. The "request" keyword allocates a |
| 2749 | capture slot for use in the request, and "response" allocates a capture slot |
| 2750 | for use in the response. |
| 2751 | |
| 2752 | See also: "capture-req", "capture-res" (sample converters), |
| 2753 | "http-request capture" and "http-response capture". |
| 2754 | |
| 2755 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2756 | default-server [param*] |
| 2757 | Change default options for a server in a backend |
| 2758 | May be used in sections : defaults | frontend | listen | backend |
| 2759 | yes | no | yes | yes |
| 2760 | Arguments: |
Willy Tarreau | 983e01e | 2010-01-11 18:42:06 +0100 | [diff] [blame] | 2761 | <param*> is a list of parameters for this server. The "default-server" |
| 2762 | keyword accepts an important number of options and has a complete |
| 2763 | section dedicated to it. Please refer to section 5 for more |
| 2764 | details. |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2765 | |
Willy Tarreau | 983e01e | 2010-01-11 18:42:06 +0100 | [diff] [blame] | 2766 | Example : |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2767 | default-server inter 1000 weight 13 |
| 2768 | |
| 2769 | See also: "server" and section 5 about server options |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2770 | |
Willy Tarreau | 983e01e | 2010-01-11 18:42:06 +0100 | [diff] [blame] | 2771 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2772 | default_backend <backend> |
| 2773 | Specify the backend to use when no "use_backend" rule has been matched. |
| 2774 | May be used in sections : defaults | frontend | listen | backend |
| 2775 | yes | yes | yes | no |
| 2776 | Arguments : |
| 2777 | <backend> is the name of the backend to use. |
| 2778 | |
| 2779 | When doing content-switching between frontend and backends using the |
| 2780 | "use_backend" keyword, it is often useful to indicate which backend will be |
| 2781 | used when no rule has matched. It generally is the dynamic backend which |
| 2782 | will catch all undetermined requests. |
| 2783 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2784 | Example : |
| 2785 | |
| 2786 | use_backend dynamic if url_dyn |
| 2787 | use_backend static if url_css url_img extension_img |
| 2788 | default_backend dynamic |
| 2789 | |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 2790 | See also : "use_backend" |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 2791 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2792 | |
Baptiste Assmann | 27f5134 | 2013-10-09 06:51:49 +0200 | [diff] [blame] | 2793 | description <string> |
| 2794 | Describe a listen, frontend or backend. |
| 2795 | May be used in sections : defaults | frontend | listen | backend |
| 2796 | no | yes | yes | yes |
| 2797 | Arguments : string |
| 2798 | |
| 2799 | Allows to add a sentence to describe the related object in the HAProxy HTML |
| 2800 | stats page. The description will be printed on the right of the object name |
| 2801 | it describes. |
| 2802 | No need to backslash spaces in the <string> arguments. |
| 2803 | |
| 2804 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2805 | disabled |
| 2806 | Disable a proxy, frontend or backend. |
| 2807 | May be used in sections : defaults | frontend | listen | backend |
| 2808 | yes | yes | yes | yes |
| 2809 | Arguments : none |
| 2810 | |
| 2811 | The "disabled" keyword is used to disable an instance, mainly in order to |
| 2812 | liberate a listening port or to temporarily disable a service. The instance |
| 2813 | will still be created and its configuration will be checked, but it will be |
| 2814 | created in the "stopped" state and will appear as such in the statistics. It |
| 2815 | will not receive any traffic nor will it send any health-checks or logs. It |
| 2816 | is possible to disable many instances at once by adding the "disabled" |
| 2817 | keyword in a "defaults" section. |
| 2818 | |
| 2819 | See also : "enabled" |
| 2820 | |
| 2821 | |
Willy Tarreau | 5ce9457 | 2010-06-07 14:35:41 +0200 | [diff] [blame] | 2822 | dispatch <address>:<port> |
| 2823 | Set a default server address |
| 2824 | May be used in sections : defaults | frontend | listen | backend |
| 2825 | no | no | yes | yes |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 2826 | Arguments : |
Willy Tarreau | 5ce9457 | 2010-06-07 14:35:41 +0200 | [diff] [blame] | 2827 | |
| 2828 | <address> is the IPv4 address of the default server. Alternatively, a |
| 2829 | resolvable hostname is supported, but this name will be resolved |
| 2830 | during start-up. |
| 2831 | |
| 2832 | <ports> is a mandatory port specification. All connections will be sent |
| 2833 | to this port, and it is not permitted to use port offsets as is |
| 2834 | possible with normal servers. |
| 2835 | |
Willy Tarreau | 787aed5 | 2011-04-15 06:45:37 +0200 | [diff] [blame] | 2836 | The "dispatch" keyword designates a default server for use when no other |
Willy Tarreau | 5ce9457 | 2010-06-07 14:35:41 +0200 | [diff] [blame] | 2837 | server can take the connection. In the past it was used to forward non |
| 2838 | persistent connections to an auxiliary load balancer. Due to its simple |
| 2839 | syntax, it has also been used for simple TCP relays. It is recommended not to |
| 2840 | use it for more clarity, and to use the "server" directive instead. |
| 2841 | |
| 2842 | See also : "server" |
| 2843 | |
| 2844 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2845 | enabled |
| 2846 | Enable a proxy, frontend or backend. |
| 2847 | May be used in sections : defaults | frontend | listen | backend |
| 2848 | yes | yes | yes | yes |
| 2849 | Arguments : none |
| 2850 | |
| 2851 | The "enabled" keyword is used to explicitly enable an instance, when the |
| 2852 | defaults has been set to "disabled". This is very rarely used. |
| 2853 | |
| 2854 | See also : "disabled" |
| 2855 | |
| 2856 | |
| 2857 | errorfile <code> <file> |
| 2858 | Return a file contents instead of errors generated by HAProxy |
| 2859 | May be used in sections : defaults | frontend | listen | backend |
| 2860 | yes | yes | yes | yes |
| 2861 | Arguments : |
| 2862 | <code> is the HTTP status code. Currently, HAProxy is capable of |
CJ Ess | 108b1dd | 2015-04-07 12:03:37 -0400 | [diff] [blame] | 2863 | generating codes 200, 400, 403, 405, 408, 429, 500, 502, 503, and |
| 2864 | 504. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2865 | |
| 2866 | <file> designates a file containing the full HTTP response. It is |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 2867 | recommended to follow the common practice of appending ".http" to |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2868 | the filename so that people do not confuse the response with HTML |
Willy Tarreau | 59140a2 | 2009-02-22 12:02:30 +0100 | [diff] [blame] | 2869 | error pages, and to use absolute paths, since files are read |
| 2870 | before any chroot is performed. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2871 | |
| 2872 | It is important to understand that this keyword is not meant to rewrite |
| 2873 | errors returned by the server, but errors detected and returned by HAProxy. |
| 2874 | This is why the list of supported errors is limited to a small set. |
| 2875 | |
Willy Tarreau | ae94d4d | 2011-05-11 16:28:49 +0200 | [diff] [blame] | 2876 | Code 200 is emitted in response to requests matching a "monitor-uri" rule. |
| 2877 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2878 | The files are returned verbatim on the TCP socket. This allows any trick such |
| 2879 | as redirections to another URL or site, as well as tricks to clean cookies, |
| 2880 | force enable or disable caching, etc... The package provides default error |
| 2881 | files returning the same contents as default errors. |
| 2882 | |
Willy Tarreau | 59140a2 | 2009-02-22 12:02:30 +0100 | [diff] [blame] | 2883 | The files should not exceed the configured buffer size (BUFSIZE), which |
| 2884 | generally is 8 or 16 kB, otherwise they will be truncated. It is also wise |
| 2885 | not to put any reference to local contents (eg: images) in order to avoid |
| 2886 | loops between the client and HAProxy when all servers are down, causing an |
| 2887 | error to be returned instead of an image. For better HTTP compliance, it is |
| 2888 | recommended that all header lines end with CR-LF and not LF alone. |
| 2889 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2890 | The files are read at the same time as the configuration and kept in memory. |
| 2891 | For this reason, the errors continue to be returned even when the process is |
| 2892 | 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] | 2893 | simple method for developing those files consists in associating them to the |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2894 | 403 status code and interrogating a blocked URL. |
| 2895 | |
| 2896 | See also : "errorloc", "errorloc302", "errorloc303" |
| 2897 | |
Willy Tarreau | 59140a2 | 2009-02-22 12:02:30 +0100 | [diff] [blame] | 2898 | Example : |
| 2899 | errorfile 400 /etc/haproxy/errorfiles/400badreq.http |
Willy Tarreau | 2705a61 | 2014-05-23 17:38:34 +0200 | [diff] [blame] | 2900 | errorfile 408 /dev/null # workaround Chrome pre-connect bug |
Willy Tarreau | 59140a2 | 2009-02-22 12:02:30 +0100 | [diff] [blame] | 2901 | errorfile 403 /etc/haproxy/errorfiles/403forbid.http |
| 2902 | errorfile 503 /etc/haproxy/errorfiles/503sorry.http |
| 2903 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 2904 | |
| 2905 | errorloc <code> <url> |
| 2906 | errorloc302 <code> <url> |
| 2907 | Return an HTTP redirection to a URL instead of errors generated by HAProxy |
| 2908 | May be used in sections : defaults | frontend | listen | backend |
| 2909 | yes | yes | yes | yes |
| 2910 | Arguments : |
| 2911 | <code> is the HTTP status code. Currently, HAProxy is capable of |
Willy Tarreau | ae94d4d | 2011-05-11 16:28:49 +0200 | [diff] [blame] | 2912 | generating codes 200, 400, 403, 408, 500, 502, 503, and 504. |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 2913 | |
| 2914 | <url> it is the exact contents of the "Location" header. It may contain |
| 2915 | either a relative URI to an error page hosted on the same site, |
| 2916 | or an absolute URI designating an error page on another site. |
| 2917 | Special care should be given to relative URIs to avoid redirect |
| 2918 | loops if the URI itself may generate the same error (eg: 500). |
| 2919 | |
| 2920 | It is important to understand that this keyword is not meant to rewrite |
| 2921 | errors returned by the server, but errors detected and returned by HAProxy. |
| 2922 | This is why the list of supported errors is limited to a small set. |
| 2923 | |
Willy Tarreau | ae94d4d | 2011-05-11 16:28:49 +0200 | [diff] [blame] | 2924 | Code 200 is emitted in response to requests matching a "monitor-uri" rule. |
| 2925 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 2926 | Note that both keyword return the HTTP 302 status code, which tells the |
| 2927 | client to fetch the designated URL using the same HTTP method. This can be |
| 2928 | quite problematic in case of non-GET methods such as POST, because the URL |
| 2929 | sent to the client might not be allowed for something other than GET. To |
| 2930 | workaround this problem, please use "errorloc303" which send the HTTP 303 |
| 2931 | status code, indicating to the client that the URL must be fetched with a GET |
| 2932 | request. |
| 2933 | |
| 2934 | See also : "errorfile", "errorloc303" |
| 2935 | |
| 2936 | |
| 2937 | errorloc303 <code> <url> |
| 2938 | Return an HTTP redirection to a URL instead of errors generated by HAProxy |
| 2939 | May be used in sections : defaults | frontend | listen | backend |
| 2940 | yes | yes | yes | yes |
| 2941 | Arguments : |
| 2942 | <code> is the HTTP status code. Currently, HAProxy is capable of |
| 2943 | generating codes 400, 403, 408, 500, 502, 503, and 504. |
| 2944 | |
| 2945 | <url> it is the exact contents of the "Location" header. It may contain |
| 2946 | either a relative URI to an error page hosted on the same site, |
| 2947 | or an absolute URI designating an error page on another site. |
| 2948 | Special care should be given to relative URIs to avoid redirect |
| 2949 | loops if the URI itself may generate the same error (eg: 500). |
| 2950 | |
| 2951 | It is important to understand that this keyword is not meant to rewrite |
| 2952 | errors returned by the server, but errors detected and returned by HAProxy. |
| 2953 | This is why the list of supported errors is limited to a small set. |
| 2954 | |
Willy Tarreau | ae94d4d | 2011-05-11 16:28:49 +0200 | [diff] [blame] | 2955 | Code 200 is emitted in response to requests matching a "monitor-uri" rule. |
| 2956 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 2957 | Note that both keyword return the HTTP 303 status code, which tells the |
| 2958 | client to fetch the designated URL using the same HTTP GET method. This |
| 2959 | solves the usual problems associated with "errorloc" and the 302 code. It is |
| 2960 | possible that some very old browsers designed before HTTP/1.1 do not support |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 2961 | it, but no such problem has been reported till now. |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 2962 | |
| 2963 | See also : "errorfile", "errorloc", "errorloc302" |
| 2964 | |
| 2965 | |
Simon Horman | 51a1cf6 | 2015-02-03 13:00:44 +0900 | [diff] [blame] | 2966 | email-alert from <emailaddr> |
| 2967 | Declare the from email address to be used in both the envelope and header |
| 2968 | of email alerts. This is the address that email alerts are sent from. |
| 2969 | May be used in sections: defaults | frontend | listen | backend |
| 2970 | yes | yes | yes | yes |
| 2971 | |
| 2972 | Arguments : |
| 2973 | |
| 2974 | <emailaddr> is the from email address to use when sending email alerts |
| 2975 | |
| 2976 | Also requires "email-alert mailers" and "email-alert to" to be set |
| 2977 | and if so sending email alerts is enabled for the proxy. |
| 2978 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 2979 | See also : "email-alert level", "email-alert mailers", |
| 2980 | "email-alert myhostname", "email-alert to", section 3.6 about mailers. |
| 2981 | |
| 2982 | |
| 2983 | email-alert level <level> |
| 2984 | Declare the maximum log level of messages for which email alerts will be |
| 2985 | sent. This acts as a filter on the sending of email alerts. |
| 2986 | May be used in sections: defaults | frontend | listen | backend |
| 2987 | yes | yes | yes | yes |
| 2988 | |
| 2989 | Arguments : |
| 2990 | |
| 2991 | <level> One of the 8 syslog levels: |
| 2992 | emerg alert crit err warning notice info debug |
| 2993 | The above syslog levels are ordered from lowest to highest. |
| 2994 | |
| 2995 | By default level is alert |
| 2996 | |
| 2997 | Also requires "email-alert from", "email-alert mailers" and |
| 2998 | "email-alert to" to be set and if so sending email alerts is enabled |
| 2999 | for the proxy. |
| 3000 | |
Simon Horman | 1421e21 | 2015-04-30 13:10:35 +0900 | [diff] [blame] | 3001 | Alerts are sent when : |
| 3002 | |
| 3003 | * An un-paused server is marked as down and <level> is alert or lower |
| 3004 | * A paused server is marked as down and <level> is notice or lower |
| 3005 | * A server is marked as up or enters the drain state and <level> |
| 3006 | is notice or lower |
| 3007 | * "option log-health-checks" is enabled, <level> is info or lower, |
| 3008 | and a health check status update occurs |
| 3009 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3010 | See also : "email-alert from", "email-alert mailers", |
| 3011 | "email-alert myhostname", "email-alert to", |
Simon Horman | 51a1cf6 | 2015-02-03 13:00:44 +0900 | [diff] [blame] | 3012 | section 3.6 about mailers. |
| 3013 | |
| 3014 | |
| 3015 | email-alert mailers <mailersect> |
| 3016 | Declare the mailers to be used when sending email alerts |
| 3017 | May be used in sections: defaults | frontend | listen | backend |
| 3018 | yes | yes | yes | yes |
| 3019 | |
| 3020 | Arguments : |
| 3021 | |
| 3022 | <mailersect> is the name of the mailers section to send email alerts. |
| 3023 | |
| 3024 | Also requires "email-alert from" and "email-alert to" to be set |
| 3025 | and if so sending email alerts is enabled for the proxy. |
| 3026 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3027 | See also : "email-alert from", "email-alert level", "email-alert myhostname", |
| 3028 | "email-alert to", section 3.6 about mailers. |
Simon Horman | 51a1cf6 | 2015-02-03 13:00:44 +0900 | [diff] [blame] | 3029 | |
| 3030 | |
| 3031 | email-alert myhostname <hostname> |
| 3032 | Declare the to hostname address to be used when communicating with |
| 3033 | mailers. |
| 3034 | May be used in sections: defaults | frontend | listen | backend |
| 3035 | yes | yes | yes | yes |
| 3036 | |
| 3037 | Arguments : |
| 3038 | |
| 3039 | <emailaddr> is the to email address to use when sending email alerts |
| 3040 | |
| 3041 | By default the systems hostname is used. |
| 3042 | |
| 3043 | Also requires "email-alert from", "email-alert mailers" and |
| 3044 | "email-alert to" to be set and if so sending email alerts is enabled |
| 3045 | for the proxy. |
| 3046 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3047 | See also : "email-alert from", "email-alert level", "email-alert mailers", |
| 3048 | "email-alert to", section 3.6 about mailers. |
Simon Horman | 51a1cf6 | 2015-02-03 13:00:44 +0900 | [diff] [blame] | 3049 | |
| 3050 | |
| 3051 | email-alert to <emailaddr> |
| 3052 | Declare both the recipent address in the envelope and to address in the |
| 3053 | header of email alerts. This is the address that email alerts are sent to. |
| 3054 | May be used in sections: defaults | frontend | listen | backend |
| 3055 | yes | yes | yes | yes |
| 3056 | |
| 3057 | Arguments : |
| 3058 | |
| 3059 | <emailaddr> is the to email address to use when sending email alerts |
| 3060 | |
| 3061 | Also requires "email-alert mailers" and "email-alert to" to be set |
| 3062 | and if so sending email alerts is enabled for the proxy. |
| 3063 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3064 | See also : "email-alert from", "email-alert level", "email-alert mailers", |
Simon Horman | 51a1cf6 | 2015-02-03 13:00:44 +0900 | [diff] [blame] | 3065 | "email-alert myhostname", section 3.6 about mailers. |
| 3066 | |
| 3067 | |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3068 | force-persist { if | unless } <condition> |
| 3069 | Declare a condition to force persistence on down servers |
| 3070 | May be used in sections: defaults | frontend | listen | backend |
| 3071 | no | yes | yes | yes |
| 3072 | |
| 3073 | By default, requests are not dispatched to down servers. It is possible to |
| 3074 | force this using "option persist", but it is unconditional and redispatches |
| 3075 | to a valid server if "option redispatch" is set. That leaves with very little |
| 3076 | possibilities to force some requests to reach a server which is artificially |
| 3077 | marked down for maintenance operations. |
| 3078 | |
| 3079 | The "force-persist" statement allows one to declare various ACL-based |
| 3080 | conditions which, when met, will cause a request to ignore the down status of |
| 3081 | a server and still try to connect to it. That makes it possible to start a |
| 3082 | server, still replying an error to the health checks, and run a specially |
| 3083 | configured browser to test the service. Among the handy methods, one could |
| 3084 | use a specific source IP address, or a specific cookie. The cookie also has |
| 3085 | the advantage that it can easily be added/removed on the browser from a test |
| 3086 | page. Once the service is validated, it is then possible to open the service |
| 3087 | to the world by returning a valid response to health checks. |
| 3088 | |
| 3089 | The forced persistence is enabled when an "if" condition is met, or unless an |
| 3090 | "unless" condition is met. The final redispatch is always disabled when this |
| 3091 | is used. |
| 3092 | |
Cyril Bonté | 0d4bf01 | 2010-04-25 23:21:46 +0200 | [diff] [blame] | 3093 | See also : "option redispatch", "ignore-persist", "persist", |
Cyril Bonté | a8e7bbc | 2010-04-25 22:29:29 +0200 | [diff] [blame] | 3094 | and section 7 about ACL usage. |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3095 | |
| 3096 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 3097 | fullconn <conns> |
| 3098 | Specify at what backend load the servers will reach their maxconn |
| 3099 | May be used in sections : defaults | frontend | listen | backend |
| 3100 | yes | no | yes | yes |
| 3101 | Arguments : |
| 3102 | <conns> is the number of connections on the backend which will make the |
| 3103 | servers use the maximal number of connections. |
| 3104 | |
Willy Tarreau | 198a744 | 2008-01-17 12:05:32 +0100 | [diff] [blame] | 3105 | When a server has a "maxconn" parameter specified, it means that its number |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 3106 | of concurrent connections will never go higher. Additionally, if it has a |
Willy Tarreau | 198a744 | 2008-01-17 12:05:32 +0100 | [diff] [blame] | 3107 | "minconn" parameter, it indicates a dynamic limit following the backend's |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 3108 | load. The server will then always accept at least <minconn> connections, |
| 3109 | never more than <maxconn>, and the limit will be on the ramp between both |
| 3110 | values when the backend has less than <conns> concurrent connections. This |
| 3111 | makes it possible to limit the load on the servers during normal loads, but |
| 3112 | push it further for important loads without overloading the servers during |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 3113 | exceptional loads. |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 3114 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 3115 | Since it's hard to get this value right, haproxy automatically sets it to |
| 3116 | 10% of the sum of the maxconns of all frontends that may branch to this |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 3117 | backend (based on "use_backend" and "default_backend" rules). That way it's |
| 3118 | safe to leave it unset. However, "use_backend" involving dynamic names are |
| 3119 | not counted since there is no way to know if they could match or not. |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 3120 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 3121 | Example : |
| 3122 | # The servers will accept between 100 and 1000 concurrent connections each |
| 3123 | # and the maximum of 1000 will be reached when the backend reaches 10000 |
| 3124 | # connections. |
| 3125 | backend dynamic |
| 3126 | fullconn 10000 |
| 3127 | server srv1 dyn1:80 minconn 100 maxconn 1000 |
| 3128 | server srv2 dyn2:80 minconn 100 maxconn 1000 |
| 3129 | |
| 3130 | See also : "maxconn", "server" |
| 3131 | |
| 3132 | |
| 3133 | grace <time> |
| 3134 | Maintain a proxy operational for some time after a soft stop |
| 3135 | May be used in sections : defaults | frontend | listen | backend |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3136 | yes | yes | yes | yes |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 3137 | Arguments : |
| 3138 | <time> is the time (by default in milliseconds) for which the instance |
| 3139 | will remain operational with the frontend sockets still listening |
| 3140 | when a soft-stop is received via the SIGUSR1 signal. |
| 3141 | |
| 3142 | This may be used to ensure that the services disappear in a certain order. |
| 3143 | This was designed so that frontends which are dedicated to monitoring by an |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 3144 | external equipment fail immediately while other ones remain up for the time |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 3145 | needed by the equipment to detect the failure. |
| 3146 | |
| 3147 | Note that currently, there is very little benefit in using this parameter, |
| 3148 | and it may in fact complicate the soft-reconfiguration process more than |
| 3149 | simplify it. |
| 3150 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 3151 | |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 3152 | hash-type <method> <function> <modifier> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3153 | Specify a method to use for mapping hashes to servers |
| 3154 | May be used in sections : defaults | frontend | listen | backend |
| 3155 | yes | no | yes | yes |
| 3156 | Arguments : |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 3157 | <method> is the method used to select a server from the hash computed by |
| 3158 | the <function> : |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3159 | |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 3160 | map-based the hash table is a static array containing all alive servers. |
| 3161 | The hashes will be very smooth, will consider weights, but |
| 3162 | will be static in that weight changes while a server is up |
| 3163 | will be ignored. This means that there will be no slow start. |
| 3164 | Also, since a server is selected by its position in the array, |
| 3165 | most mappings are changed when the server count changes. This |
| 3166 | means that when a server goes up or down, or when a server is |
| 3167 | added to a farm, most connections will be redistributed to |
| 3168 | different servers. This can be inconvenient with caches for |
| 3169 | instance. |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3170 | |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 3171 | consistent the hash table is a tree filled with many occurrences of each |
| 3172 | server. The hash key is looked up in the tree and the closest |
| 3173 | server is chosen. This hash is dynamic, it supports changing |
| 3174 | weights while the servers are up, so it is compatible with the |
| 3175 | slow start feature. It has the advantage that when a server |
| 3176 | goes up or down, only its associations are moved. When a |
| 3177 | server is added to the farm, only a few part of the mappings |
| 3178 | are redistributed, making it an ideal method for caches. |
| 3179 | However, due to its principle, the distribution will never be |
| 3180 | very smooth and it may sometimes be necessary to adjust a |
| 3181 | server's weight or its ID to get a more balanced distribution. |
| 3182 | In order to get the same distribution on multiple load |
| 3183 | balancers, it is important that all servers have the exact |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 3184 | same IDs. Note: consistent hash uses sdbm and avalanche if no |
| 3185 | hash function is specified. |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 3186 | |
| 3187 | <function> is the hash function to be used : |
| 3188 | |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 3189 | sdbm this function was created initially for sdbm (a public-domain |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 3190 | reimplementation of ndbm) database library. It was found to do |
| 3191 | well in scrambling bits, causing better distribution of the keys |
| 3192 | and fewer splits. It also happens to be a good general hashing |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 3193 | function with good distribution, unless the total server weight |
| 3194 | is a multiple of 64, in which case applying the avalanche |
| 3195 | modifier may help. |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 3196 | |
| 3197 | djb2 this function was first proposed by Dan Bernstein many years ago |
| 3198 | on comp.lang.c. Studies have shown that for certain workload this |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 3199 | function provides a better distribution than sdbm. It generally |
| 3200 | works well with text-based inputs though it can perform extremely |
| 3201 | poorly with numeric-only input or when the total server weight is |
| 3202 | a multiple of 33, unless the avalanche modifier is also used. |
| 3203 | |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 3204 | wt6 this function was designed for haproxy while testing other |
| 3205 | functions in the past. It is not as smooth as the other ones, but |
| 3206 | is much less sensible to the input data set or to the number of |
| 3207 | servers. It can make sense as an alternative to sdbm+avalanche or |
| 3208 | djb2+avalanche for consistent hashing or when hashing on numeric |
| 3209 | data such as a source IP address or a visitor identifier in a URL |
| 3210 | parameter. |
| 3211 | |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 3212 | crc32 this is the most common CRC32 implementation as used in Ethernet, |
| 3213 | gzip, PNG, etc. It is slower than the other ones but may provide |
| 3214 | a better distribution or less predictable results especially when |
| 3215 | used on strings. |
| 3216 | |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 3217 | <modifier> indicates an optional method applied after hashing the key : |
| 3218 | |
| 3219 | avalanche This directive indicates that the result from the hash |
| 3220 | function above should not be used in its raw form but that |
| 3221 | a 4-byte full avalanche hash must be applied first. The |
| 3222 | purpose of this step is to mix the resulting bits from the |
| 3223 | previous hash in order to avoid any undesired effect when |
| 3224 | the input contains some limited values or when the number of |
| 3225 | servers is a multiple of one of the hash's components (64 |
| 3226 | for SDBM, 33 for DJB2). Enabling avalanche tends to make the |
| 3227 | result less predictable, but it's also not as smooth as when |
| 3228 | using the original function. Some testing might be needed |
| 3229 | with some workloads. This hash is one of the many proposed |
| 3230 | by Bob Jenkins. |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3231 | |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 3232 | The default hash type is "map-based" and is recommended for most usages. The |
| 3233 | default function is "sdbm", the selection of a function should be based on |
| 3234 | the range of the values being hashed. |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3235 | |
| 3236 | See also : "balance", "server" |
| 3237 | |
| 3238 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 3239 | http-check disable-on-404 |
| 3240 | Enable a maintenance mode upon HTTP/404 response to health-checks |
| 3241 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 3242 | yes | no | yes | yes |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 3243 | Arguments : none |
| 3244 | |
| 3245 | When this option is set, a server which returns an HTTP code 404 will be |
| 3246 | excluded from further load-balancing, but will still receive persistent |
| 3247 | connections. This provides a very convenient method for Web administrators |
| 3248 | to perform a graceful shutdown of their servers. It is also important to note |
| 3249 | that a server which is detected as failed while it was in this mode will not |
| 3250 | generate an alert, just a notice. If the server responds 2xx or 3xx again, it |
| 3251 | will immediately be reinserted into the farm. The status on the stats page |
| 3252 | reports "NOLB" for a server in this mode. It is important to note that this |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3253 | option only works in conjunction with the "httpchk" option. If this option |
| 3254 | is used with "http-check expect", then it has precedence over it so that 404 |
| 3255 | responses will still be considered as soft-stop. |
| 3256 | |
| 3257 | See also : "option httpchk", "http-check expect" |
| 3258 | |
| 3259 | |
| 3260 | http-check expect [!] <match> <pattern> |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 3261 | Make HTTP health checks consider response contents or specific status codes |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3262 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3263 | yes | no | yes | yes |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3264 | Arguments : |
| 3265 | <match> is a keyword indicating how to look for a specific pattern in the |
| 3266 | response. The keyword may be one of "status", "rstatus", |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 3267 | "string", or "rstring". The keyword may be preceded by an |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3268 | exclamation mark ("!") to negate the match. Spaces are allowed |
| 3269 | between the exclamation mark and the keyword. See below for more |
| 3270 | details on the supported keywords. |
| 3271 | |
| 3272 | <pattern> is the pattern to look for. It may be a string or a regular |
| 3273 | expression. If the pattern contains spaces, they must be escaped |
| 3274 | with the usual backslash ('\'). |
| 3275 | |
| 3276 | By default, "option httpchk" considers that response statuses 2xx and 3xx |
| 3277 | are valid, and that others are invalid. When "http-check expect" is used, |
| 3278 | it defines what is considered valid or invalid. Only one "http-check" |
| 3279 | statement is supported in a backend. If a server fails to respond or times |
| 3280 | out, the check obviously fails. The available matches are : |
| 3281 | |
| 3282 | status <string> : test the exact string match for the HTTP status code. |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 3283 | A health check response will be considered valid if the |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3284 | response's status code is exactly this string. If the |
| 3285 | "status" keyword is prefixed with "!", then the response |
| 3286 | will be considered invalid if the status code matches. |
| 3287 | |
| 3288 | rstatus <regex> : test a regular expression for the HTTP status code. |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 3289 | A health check response will be considered valid if the |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3290 | response's status code matches the expression. If the |
| 3291 | "rstatus" keyword is prefixed with "!", then the response |
| 3292 | will be considered invalid if the status code matches. |
| 3293 | This is mostly used to check for multiple codes. |
| 3294 | |
| 3295 | string <string> : test the exact string match in the HTTP response body. |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 3296 | A health check response will be considered valid if the |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3297 | response's body contains this exact string. If the |
| 3298 | "string" keyword is prefixed with "!", then the response |
| 3299 | will be considered invalid if the body contains this |
| 3300 | string. This can be used to look for a mandatory word at |
| 3301 | the end of a dynamic page, or to detect a failure when a |
| 3302 | specific error appears on the check page (eg: a stack |
| 3303 | trace). |
| 3304 | |
| 3305 | rstring <regex> : test a regular expression on the HTTP response body. |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 3306 | A health check response will be considered valid if the |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3307 | response's body matches this expression. If the "rstring" |
| 3308 | keyword is prefixed with "!", then the response will be |
| 3309 | considered invalid if the body matches the expression. |
| 3310 | This can be used to look for a mandatory word at the end |
| 3311 | of a dynamic page, or to detect a failure when a specific |
| 3312 | error appears on the check page (eg: a stack trace). |
| 3313 | |
| 3314 | It is important to note that the responses will be limited to a certain size |
| 3315 | defined by the global "tune.chksize" option, which defaults to 16384 bytes. |
| 3316 | Thus, too large responses may not contain the mandatory pattern when using |
| 3317 | "string" or "rstring". If a large response is absolutely required, it is |
| 3318 | possible to change the default max size by setting the global variable. |
| 3319 | However, it is worth keeping in mind that parsing very large responses can |
| 3320 | waste some CPU cycles, especially when regular expressions are used, and that |
| 3321 | it is always better to focus the checks on smaller resources. |
| 3322 | |
Cyril Bonté | 32602d2 | 2015-01-30 00:07:07 +0100 | [diff] [blame] | 3323 | Also "http-check expect" doesn't support HTTP keep-alive. Keep in mind that it |
| 3324 | will automatically append a "Connection: close" header, meaning that this |
| 3325 | header should not be present in the request provided by "option httpchk". |
| 3326 | |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3327 | Last, if "http-check expect" is combined with "http-check disable-on-404", |
| 3328 | then this last one has precedence when the server responds with 404. |
| 3329 | |
| 3330 | Examples : |
| 3331 | # only accept status 200 as valid |
Willy Tarreau | 8f2a1e7 | 2011-01-06 16:36:10 +0100 | [diff] [blame] | 3332 | http-check expect status 200 |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3333 | |
| 3334 | # consider SQL errors as errors |
Willy Tarreau | 8f2a1e7 | 2011-01-06 16:36:10 +0100 | [diff] [blame] | 3335 | http-check expect ! string SQL\ Error |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3336 | |
| 3337 | # consider status 5xx only as errors |
Willy Tarreau | 8f2a1e7 | 2011-01-06 16:36:10 +0100 | [diff] [blame] | 3338 | http-check expect ! rstatus ^5 |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3339 | |
| 3340 | # check that we have a correct hexadecimal tag before /html |
Willy Tarreau | 8f2a1e7 | 2011-01-06 16:36:10 +0100 | [diff] [blame] | 3341 | http-check expect rstring <!--tag:[0-9a-f]*</html> |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 3342 | |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3343 | See also : "option httpchk", "http-check disable-on-404" |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 3344 | |
| 3345 | |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3346 | http-check send-state |
| 3347 | Enable emission of a state header with HTTP health checks |
| 3348 | May be used in sections : defaults | frontend | listen | backend |
| 3349 | yes | no | yes | yes |
| 3350 | Arguments : none |
| 3351 | |
| 3352 | When this option is set, haproxy will systematically send a special header |
| 3353 | "X-Haproxy-Server-State" with a list of parameters indicating to each server |
| 3354 | how they are seen by haproxy. This can be used for instance when a server is |
| 3355 | manipulated without access to haproxy and the operator needs to know whether |
| 3356 | haproxy still sees it up or not, or if the server is the last one in a farm. |
| 3357 | |
| 3358 | The header is composed of fields delimited by semi-colons, the first of which |
| 3359 | is a word ("UP", "DOWN", "NOLB"), possibly followed by a number of valid |
| 3360 | checks on the total number before transition, just as appears in the stats |
| 3361 | interface. Next headers are in the form "<variable>=<value>", indicating in |
| 3362 | no specific order some values available in the stats interface : |
Joseph Lynch | 514061c | 2015-01-15 17:52:59 -0800 | [diff] [blame] | 3363 | - a variable "address", containing the address of the backend server. |
| 3364 | This corresponds to the <address> field in the server declaration. For |
| 3365 | unix domain sockets, it will read "unix". |
| 3366 | |
| 3367 | - a variable "port", containing the port of the backend server. This |
| 3368 | corresponds to the <port> field in the server declaration. For unix |
| 3369 | domain sockets, it will read "unix". |
| 3370 | |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3371 | - a variable "name", containing the name of the backend followed by a slash |
| 3372 | ("/") then the name of the server. This can be used when a server is |
| 3373 | checked in multiple backends. |
| 3374 | |
| 3375 | - a variable "node" containing the name of the haproxy node, as set in the |
| 3376 | global "node" variable, otherwise the system's hostname if unspecified. |
| 3377 | |
| 3378 | - a variable "weight" indicating the weight of the server, a slash ("/") |
| 3379 | and the total weight of the farm (just counting usable servers). This |
| 3380 | helps to know if other servers are available to handle the load when this |
| 3381 | one fails. |
| 3382 | |
| 3383 | - a variable "scur" indicating the current number of concurrent connections |
| 3384 | on the server, followed by a slash ("/") then the total number of |
| 3385 | connections on all servers of the same backend. |
| 3386 | |
| 3387 | - a variable "qcur" indicating the current number of requests in the |
| 3388 | server's queue. |
| 3389 | |
| 3390 | Example of a header received by the application server : |
| 3391 | >>> X-Haproxy-Server-State: UP 2/3; name=bck/srv2; node=lb1; weight=1/2; \ |
| 3392 | scur=13/22; qcur=0 |
| 3393 | |
| 3394 | See also : "option httpchk", "http-check disable-on-404" |
| 3395 | |
Willy Tarreau | ccbcc37 | 2012-12-27 12:37:57 +0100 | [diff] [blame] | 3396 | http-request { allow | deny | tarpit | auth [realm <realm>] | redirect <rule> | |
Willy Tarreau | f4c43c1 | 2013-06-11 17:01:13 +0200 | [diff] [blame] | 3397 | add-header <name> <fmt> | set-header <name> <fmt> | |
Thierry FOURNIER | 82bf70d | 2015-05-26 17:58:29 +0200 | [diff] [blame] | 3398 | capture <sample> [ len <length> | id <id> ] | |
Thierry FOURNIER | dad3d1d | 2014-04-22 18:07:25 +0200 | [diff] [blame] | 3399 | del-header <name> | set-nice <nice> | set-log-level <level> | |
Sasha Pachev | 218f064 | 2014-06-16 12:05:59 -0600 | [diff] [blame] | 3400 | replace-header <name> <match-regex> <replace-fmt> | |
| 3401 | replace-value <name> <match-regex> <replace-fmt> | |
Willy Tarreau | a0dc23f | 2015-01-22 20:46:11 +0100 | [diff] [blame] | 3402 | set-method <fmt> | set-path <fmt> | set-query <fmt> | |
| 3403 | set-uri <fmt> | set-tos <tos> | set-mark <mark> | |
Baptiste Assmann | fabcbe0 | 2014-04-24 22:16:59 +0200 | [diff] [blame] | 3404 | add-acl(<file name>) <key fmt> | |
| 3405 | del-acl(<file name>) <key fmt> | |
| 3406 | del-map(<file name>) <key fmt> | |
Baptiste Assmann | bb7e86a | 2014-09-03 18:29:47 +0200 | [diff] [blame] | 3407 | set-map(<file name>) <key fmt> <value fmt> | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 3408 | set-var(<var name>) <expr> | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 3409 | { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 3410 | sc-inc-gpc0(<sc-id>) | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3411 | sc-set-gpt0(<sc-id>) <int> | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 3412 | lua <function name> |
Baptiste Assmann | fabcbe0 | 2014-04-24 22:16:59 +0200 | [diff] [blame] | 3413 | } |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 3414 | [ { if | unless } <condition> ] |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 3415 | Access control for Layer 7 requests |
| 3416 | |
| 3417 | May be used in sections: defaults | frontend | listen | backend |
| 3418 | no | yes | yes | yes |
| 3419 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3420 | The http-request statement defines a set of rules which apply to layer 7 |
| 3421 | processing. The rules are evaluated in their declaration order when they are |
| 3422 | met in a frontend, listen or backend section. Any rule may optionally be |
| 3423 | followed by an ACL-based condition, in which case it will only be evaluated |
| 3424 | if the condition is true. |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 3425 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3426 | The first keyword is the rule's action. Currently supported actions include : |
| 3427 | - "allow" : this stops the evaluation of the rules and lets the request |
| 3428 | pass the check. No further "http-request" rules are evaluated. |
| 3429 | |
| 3430 | - "deny" : this stops the evaluation of the rules and immediately rejects |
| 3431 | the request and emits an HTTP 403 error. No further "http-request" rules |
| 3432 | are evaluated. |
| 3433 | |
Willy Tarreau | ccbcc37 | 2012-12-27 12:37:57 +0100 | [diff] [blame] | 3434 | - "tarpit" : this stops the evaluation of the rules and immediately blocks |
| 3435 | the request without responding for a delay specified by "timeout tarpit" |
| 3436 | or "timeout connect" if the former is not set. After that delay, if the |
| 3437 | client is still connected, an HTTP error 500 is returned so that the |
| 3438 | client does not suspect it has been tarpitted. Logs will report the flags |
| 3439 | "PT". The goal of the tarpit rule is to slow down robots during an attack |
| 3440 | when they're limited on the number of concurrent requests. It can be very |
| 3441 | efficient against very dumb robots, and will significantly reduce the |
| 3442 | load on firewalls compared to a "deny" rule. But when facing "correctly" |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 3443 | developed robots, it can make things worse by forcing haproxy and the |
Willy Tarreau | ccbcc37 | 2012-12-27 12:37:57 +0100 | [diff] [blame] | 3444 | front firewall to support insane number of concurrent connections. |
| 3445 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3446 | - "auth" : this stops the evaluation of the rules and immediately responds |
| 3447 | with an HTTP 401 or 407 error code to invite the user to present a valid |
| 3448 | user name and password. No further "http-request" rules are evaluated. An |
| 3449 | optional "realm" parameter is supported, it sets the authentication realm |
| 3450 | that is returned with the response (typically the application's name). |
| 3451 | |
Willy Tarreau | 81499eb | 2012-12-27 12:19:02 +0100 | [diff] [blame] | 3452 | - "redirect" : this performs an HTTP redirection based on a redirect rule. |
| 3453 | This is exactly the same as the "redirect" statement except that it |
| 3454 | inserts a redirect rule which can be processed in the middle of other |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 3455 | "http-request" rules and that these rules use the "log-format" strings. |
| 3456 | See the "redirect" keyword for the rule's syntax. |
Willy Tarreau | 81499eb | 2012-12-27 12:19:02 +0100 | [diff] [blame] | 3457 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3458 | - "add-header" appends an HTTP header field whose name is specified in |
| 3459 | <name> and whose value is defined by <fmt> which follows the log-format |
| 3460 | rules (see Custom Log Format in section 8.2.4). This is particularly |
| 3461 | useful to pass connection-specific information to the server (eg: the |
| 3462 | client's SSL certificate), or to combine several headers into one. This |
| 3463 | rule is not final, so it is possible to add other similar rules. Note |
| 3464 | that header addition is performed immediately, so one rule might reuse |
| 3465 | the resulting header from a previous rule. |
| 3466 | |
| 3467 | - "set-header" does the same as "add-header" except that the header name |
| 3468 | is first removed if it existed. This is useful when passing security |
| 3469 | information to the server, where the header must not be manipulated by |
Willy Tarreau | 8560328 | 2015-01-21 20:39:27 +0100 | [diff] [blame] | 3470 | external users. Note that the new value is computed before the removal so |
| 3471 | it is possible to concatenate a value to an existing header. |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3472 | |
Thierry FOURNIER | dad3d1d | 2014-04-22 18:07:25 +0200 | [diff] [blame] | 3473 | - "del-header" removes all HTTP header fields whose name is specified in |
| 3474 | <name>. |
| 3475 | |
Sasha Pachev | 218f064 | 2014-06-16 12:05:59 -0600 | [diff] [blame] | 3476 | - "replace-header" matches the regular expression in all occurrences of |
| 3477 | header field <name> according to <match-regex>, and replaces them with |
| 3478 | the <replace-fmt> argument. Format characters are allowed in replace-fmt |
| 3479 | and work like in <fmt> arguments in "add-header". The match is only |
| 3480 | case-sensitive. It is important to understand that this action only |
| 3481 | considers whole header lines, regardless of the number of values they |
| 3482 | may contain. This usage is suited to headers naturally containing commas |
| 3483 | in their value, such as If-Modified-Since and so on. |
| 3484 | |
| 3485 | Example: |
| 3486 | |
| 3487 | http-request replace-header Cookie foo=([^;]*);(.*) foo=\1;ip=%bi;\2 |
| 3488 | |
| 3489 | applied to: |
| 3490 | |
| 3491 | Cookie: foo=foobar; expires=Tue, 14-Jun-2016 01:40:45 GMT; |
| 3492 | |
| 3493 | outputs: |
| 3494 | |
| 3495 | Cookie: foo=foobar;ip=192.168.1.20; expires=Tue, 14-Jun-2016 01:40:45 GMT; |
| 3496 | |
| 3497 | assuming the backend IP is 192.168.1.20 |
| 3498 | |
| 3499 | - "replace-value" works like "replace-header" except that it matches the |
| 3500 | regex against every comma-delimited value of the header field <name> |
| 3501 | instead of the entire header. This is suited for all headers which are |
| 3502 | allowed to carry more than one value. An example could be the Accept |
| 3503 | header. |
| 3504 | |
| 3505 | Example: |
| 3506 | |
| 3507 | http-request replace-value X-Forwarded-For ^192\.168\.(.*)$ 172.16.\1 |
| 3508 | |
| 3509 | applied to: |
| 3510 | |
| 3511 | X-Forwarded-For: 192.168.10.1, 192.168.13.24, 10.0.0.37 |
| 3512 | |
| 3513 | outputs: |
| 3514 | |
| 3515 | X-Forwarded-For: 172.16.10.1, 172.16.13.24, 10.0.0.37 |
| 3516 | |
Willy Tarreau | a0dc23f | 2015-01-22 20:46:11 +0100 | [diff] [blame] | 3517 | - "set-method" rewrites the request method with the result of the |
| 3518 | evaluation of format string <fmt>. There should be very few valid reasons |
| 3519 | for having to do so as this is more likely to break something than to fix |
| 3520 | it. |
| 3521 | |
| 3522 | - "set-path" rewrites the request path with the result of the evaluation of |
| 3523 | format string <fmt>. The query string, if any, is left intact. If a |
| 3524 | scheme and authority is found before the path, they are left intact as |
| 3525 | well. If the request doesn't have a path ("*"), this one is replaced with |
| 3526 | the format. This can be used to prepend a directory component in front of |
| 3527 | a path for example. See also "set-query" and "set-uri". |
| 3528 | |
| 3529 | Example : |
| 3530 | # prepend the host name before the path |
| 3531 | http-request set-path /%[hdr(host)]%[path] |
| 3532 | |
| 3533 | - "set-query" rewrites the request's query string which appears after the |
| 3534 | first question mark ("?") with the result of the evaluation of format |
| 3535 | string <fmt>. The part prior to the question mark is left intact. If the |
| 3536 | request doesn't contain a question mark and the new value is not empty, |
| 3537 | then one is added at the end of the URI, followed by the new value. If |
| 3538 | a question mark was present, it will never be removed even if the value |
| 3539 | is empty. This can be used to add or remove parameters from the query |
| 3540 | string. See also "set-query" and "set-uri". |
| 3541 | |
| 3542 | Example : |
| 3543 | # replace "%3D" with "=" in the query string |
| 3544 | http-request set-query %[query,regsub(%3D,=,g)] |
| 3545 | |
| 3546 | - "set-uri" rewrites the request URI with the result of the evaluation of |
| 3547 | format string <fmt>. The scheme, authority, path and query string are all |
| 3548 | replaced at once. This can be used to rewrite hosts in front of proxies, |
| 3549 | or to perform complex modifications to the URI such as moving parts |
| 3550 | between the path and the query string. See also "set-path" and |
| 3551 | "set-query". |
| 3552 | |
Willy Tarreau | f4c43c1 | 2013-06-11 17:01:13 +0200 | [diff] [blame] | 3553 | - "set-nice" sets the "nice" factor of the current request being processed. |
| 3554 | It only has effect against the other requests being processed at the same |
| 3555 | time. The default value is 0, unless altered by the "nice" setting on the |
| 3556 | "bind" line. The accepted range is -1024..1024. The higher the value, the |
| 3557 | nicest the request will be. Lower values will make the request more |
| 3558 | important than other ones. This can be useful to improve the speed of |
| 3559 | some requests, or lower the priority of non-important requests. Using |
| 3560 | this setting without prior experimentation can cause some major slowdown. |
| 3561 | |
Willy Tarreau | 9a355ec | 2013-06-11 17:45:46 +0200 | [diff] [blame] | 3562 | - "set-log-level" is used to change the log level of the current request |
| 3563 | when a certain condition is met. Valid levels are the 8 syslog levels |
| 3564 | (see the "log" keyword) plus the special level "silent" which disables |
| 3565 | logging for this request. This rule is not final so the last matching |
| 3566 | rule wins. This rule can be useful to disable health checks coming from |
| 3567 | another equipment. |
| 3568 | |
Willy Tarreau | 42cf39e | 2013-06-11 18:51:32 +0200 | [diff] [blame] | 3569 | - "set-tos" is used to set the TOS or DSCP field value of packets sent to |
| 3570 | the client to the value passed in <tos> on platforms which support this. |
| 3571 | This value represents the whole 8 bits of the IP TOS field, and can be |
| 3572 | expressed both in decimal or hexadecimal format (prefixed by "0x"). Note |
| 3573 | that only the 6 higher bits are used in DSCP or TOS, and the two lower |
| 3574 | bits are always 0. This can be used to adjust some routing behaviour on |
| 3575 | border routers based on some information from the request. See RFC 2474, |
| 3576 | 2597, 3260 and 4594 for more information. |
| 3577 | |
Willy Tarreau | 51347ed | 2013-06-11 19:34:13 +0200 | [diff] [blame] | 3578 | - "set-mark" is used to set the Netfilter MARK on all packets sent to the |
| 3579 | client to the value passed in <mark> on platforms which support it. This |
| 3580 | value is an unsigned 32 bit value which can be matched by netfilter and |
| 3581 | by the routing table. It can be expressed both in decimal or hexadecimal |
| 3582 | format (prefixed by "0x"). This can be useful to force certain packets to |
| 3583 | take a different route (for example a cheaper network path for bulk |
| 3584 | downloads). This works on Linux kernels 2.6.32 and above and requires |
| 3585 | admin privileges. |
| 3586 | |
Baptiste Assmann | fabcbe0 | 2014-04-24 22:16:59 +0200 | [diff] [blame] | 3587 | - "add-acl" is used to add a new entry into an ACL. The ACL must be loaded |
| 3588 | from a file (even a dummy empty file). The file name of the ACL to be |
| 3589 | updated is passed between parentheses. It takes one argument: <key fmt>, |
| 3590 | which follows log-format rules, to collect content of the new entry. It |
| 3591 | performs a lookup in the ACL before insertion, to avoid duplicated (or |
| 3592 | more) values. This lookup is done by a linear search and can be expensive |
| 3593 | with large lists! It is the equivalent of the "add acl" command from the |
| 3594 | stats socket, but can be triggered by an HTTP request. |
| 3595 | |
| 3596 | - "del-acl" is used to delete an entry from an ACL. The ACL must be loaded |
| 3597 | from a file (even a dummy empty file). The file name of the ACL to be |
| 3598 | updated is passed between parentheses. It takes one argument: <key fmt>, |
| 3599 | which follows log-format rules, to collect content of the entry to delete. |
| 3600 | It is the equivalent of the "del acl" command from the stats socket, but |
| 3601 | can be triggered by an HTTP request. |
| 3602 | |
| 3603 | - "del-map" is used to delete an entry from a MAP. The MAP must be loaded |
| 3604 | from a file (even a dummy empty file). The file name of the MAP to be |
| 3605 | updated is passed between parentheses. It takes one argument: <key fmt>, |
| 3606 | which follows log-format rules, to collect content of the entry to delete. |
| 3607 | It takes one argument: "file name" It is the equivalent of the "del map" |
| 3608 | command from the stats socket, but can be triggered by an HTTP request. |
| 3609 | |
| 3610 | - "set-map" is used to add a new entry into a MAP. The MAP must be loaded |
| 3611 | from a file (even a dummy empty file). The file name of the MAP to be |
| 3612 | updated is passed between parentheses. It takes 2 arguments: <key fmt>, |
| 3613 | which follows log-format rules, used to collect MAP key, and <value fmt>, |
| 3614 | which follows log-format rules, used to collect content for the new entry. |
| 3615 | It performs a lookup in the MAP before insertion, to avoid duplicated (or |
| 3616 | more) values. This lookup is done by a linear search and can be expensive |
| 3617 | with large lists! It is the equivalent of the "set map" command from the |
| 3618 | stats socket, but can be triggered by an HTTP request. |
| 3619 | |
Thierry FOURNIER | 82bf70d | 2015-05-26 17:58:29 +0200 | [diff] [blame] | 3620 | - capture <sample> [ len <length> | id <id> ] : |
Willy Tarreau | a9083d0 | 2015-05-08 15:27:59 +0200 | [diff] [blame] | 3621 | captures sample expression <sample> from the request buffer, and converts |
| 3622 | it to a string of at most <len> characters. The resulting string is |
| 3623 | stored into the next request "capture" slot, so it will possibly appear |
| 3624 | next to some captured HTTP headers. It will then automatically appear in |
| 3625 | the logs, and it will be possible to extract it using sample fetch rules |
| 3626 | to feed it into headers or anything. The length should be limited given |
| 3627 | that this size will be allocated for each capture during the whole |
| 3628 | session life. Please check section 7.3 (Fetching samples) and "capture |
| 3629 | request header" for more information. |
| 3630 | |
Thierry FOURNIER | 82bf70d | 2015-05-26 17:58:29 +0200 | [diff] [blame] | 3631 | If the keyword "id" is used instead of "len", the action tries to store |
| 3632 | the captured string in a previously declared capture slot. This is useful |
| 3633 | to run captures in backends. The slot id can be declared by a previous |
| 3634 | directive "http-request capture" or with the "declare capture" keyword. |
| 3635 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 3636 | - { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] : |
| 3637 | enables tracking of sticky counters from current request. These rules |
| 3638 | do not stop evaluation and do not change default action. Three sets of |
| 3639 | counters may be simultaneously tracked by the same connection. The first |
| 3640 | "track-sc0" rule executed enables tracking of the counters of the |
| 3641 | specified table as the first set. The first "track-sc1" rule executed |
| 3642 | enables tracking of the counters of the specified table as the second |
| 3643 | set. The first "track-sc2" rule executed enables tracking of the |
| 3644 | counters of the specified table as the third set. It is a recommended |
| 3645 | practice to use the first set of counters for the per-frontend counters |
| 3646 | and the second set for the per-backend ones. But this is just a |
| 3647 | guideline, all may be used everywhere. |
| 3648 | |
| 3649 | These actions take one or two arguments : |
| 3650 | <key> is mandatory, and is a sample expression rule as described |
| 3651 | in section 7.3. It describes what elements of the incoming |
| 3652 | request or connection will be analysed, extracted, combined, |
| 3653 | and used to select which table entry to update the counters. |
| 3654 | |
| 3655 | <table> is an optional table to be used instead of the default one, |
| 3656 | which is the stick-table declared in the current proxy. All |
| 3657 | the counters for the matches and updates for the key will |
| 3658 | then be performed in that table until the session ends. |
| 3659 | |
| 3660 | Once a "track-sc*" rule is executed, the key is looked up in the table |
| 3661 | and if it is not found, an entry is allocated for it. Then a pointer to |
| 3662 | that entry is kept during all the session's life, and this entry's |
| 3663 | counters are updated as often as possible, every time the session's |
| 3664 | counters are updated, and also systematically when the session ends. |
| 3665 | Counters are only updated for events that happen after the tracking has |
| 3666 | been started. As an exception, connection counters and request counters |
| 3667 | are systematically updated so that they reflect useful information. |
| 3668 | |
| 3669 | If the entry tracks concurrent connection counters, one connection is |
| 3670 | counted for as long as the entry is tracked, and the entry will not |
| 3671 | expire during that time. Tracking counters also provides a performance |
| 3672 | advantage over just checking the keys, because only one table lookup is |
| 3673 | performed for all ACL checks that make use of it. |
| 3674 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3675 | - sc-set-gpt0(<sc-id>) <int> : |
| 3676 | This action sets the GPT0 tag according to the sticky counter designated |
| 3677 | by <sc-id> and the value of <int>. The expected result is a boolean. If |
| 3678 | an error occurs, this action silently fails and the actions evaluation |
| 3679 | continues. |
| 3680 | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 3681 | - sc-inc-gpc0(<sc-id>): |
| 3682 | This action increments the GPC0 counter according with the sticky counter |
| 3683 | designated by <sc-id>. If an error occurs, this action silently fails and |
| 3684 | the actions evaluation continues. |
| 3685 | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 3686 | - "lua" is used to run a Lua function if the action is executed. The single |
| 3687 | parameter is the name of the function to run. The prototype of the |
| 3688 | function is documented in the API documentation. |
| 3689 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 3690 | - set-var(<var-name>) <expr> : |
| 3691 | Is used to set the contents of a variable. The variable is declared |
| 3692 | inline. |
| 3693 | |
| 3694 | <var-name> The name of the variable starts by an indication about its |
| 3695 | scope. The allowed scopes are: |
| 3696 | "sess" : the variable is shared with all the session, |
| 3697 | "txn" : the variable is shared with all the transaction |
| 3698 | (request and response) |
| 3699 | "req" : the variable is shared only during the request |
| 3700 | processing |
| 3701 | "res" : the variable is shared only during the response |
| 3702 | processing. |
| 3703 | This prefix is followed by a name. The separator is a '.'. |
| 3704 | The name may only contain characters 'a-z', 'A-Z', '0-9', |
| 3705 | and '_'. |
| 3706 | |
| 3707 | <expr> Is a standard HAProxy expression formed by a sample-fetch |
| 3708 | followed by some converters. |
| 3709 | |
| 3710 | Example: |
| 3711 | |
| 3712 | http-request set-var(req.my_var) req.fhdr(user-agent),lower |
| 3713 | |
Adis Nezirovic | 2fbcafc | 2015-07-06 15:44:30 +0200 | [diff] [blame] | 3714 | - set-src <expr> : |
| 3715 | Is used to set the source IP address to the value of specified |
| 3716 | expression. Useful when a proxy in front of HAProxy rewrites source IP, |
| 3717 | but provides the correct IP in a HTTP header; or you want to mask |
| 3718 | source IP for privacy. |
| 3719 | |
| 3720 | <expr> Is a standard HAProxy expression formed by a sample-fetch |
| 3721 | followed by some converters. |
| 3722 | |
| 3723 | Example: |
| 3724 | |
| 3725 | http-request set-src hdr(x-forwarded-for) |
| 3726 | http-request set-src src,ipmask(24) |
| 3727 | |
| 3728 | When set-src is successful, the source port is set to 0. |
| 3729 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3730 | There is no limit to the number of http-request statements per instance. |
| 3731 | |
| 3732 | It is important to know that http-request rules are processed very early in |
| 3733 | the HTTP processing, just after "block" rules and before "reqdel" or "reqrep" |
| 3734 | rules. That way, headers added by "add-header"/"set-header" are visible by |
| 3735 | almost all further ACL rules. |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 3736 | |
| 3737 | Example: |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 3738 | acl nagios src 192.168.129.3 |
| 3739 | acl local_net src 192.168.0.0/16 |
| 3740 | acl auth_ok http_auth(L1) |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 3741 | |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 3742 | http-request allow if nagios |
| 3743 | http-request allow if local_net auth_ok |
| 3744 | http-request auth realm Gimme if local_net auth_ok |
| 3745 | http-request deny |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 3746 | |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 3747 | Example: |
| 3748 | acl auth_ok http_auth_group(L1) G1 |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 3749 | http-request auth unless auth_ok |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 3750 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3751 | Example: |
| 3752 | http-request set-header X-Haproxy-Current-Date %T |
| 3753 | http-request set-header X-SSL %[ssl_fc] |
Willy Tarreau | fca4261 | 2015-08-27 17:15:05 +0200 | [diff] [blame] | 3754 | http-request set-header X-SSL-Session_ID %[ssl_fc_session_id,hex] |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3755 | http-request set-header X-SSL-Client-Verify %[ssl_c_verify] |
| 3756 | http-request set-header X-SSL-Client-DN %{+Q}[ssl_c_s_dn] |
| 3757 | http-request set-header X-SSL-Client-CN %{+Q}[ssl_c_s_dn(cn)] |
| 3758 | http-request set-header X-SSL-Issuer %{+Q}[ssl_c_i_dn] |
| 3759 | http-request set-header X-SSL-Client-NotBefore %{+Q}[ssl_c_notbefore] |
| 3760 | http-request set-header X-SSL-Client-NotAfter %{+Q}[ssl_c_notafter] |
| 3761 | |
Baptiste Assmann | fabcbe0 | 2014-04-24 22:16:59 +0200 | [diff] [blame] | 3762 | Example: |
| 3763 | acl key req.hdr(X-Add-Acl-Key) -m found |
| 3764 | acl add path /addacl |
| 3765 | acl del path /delacl |
| 3766 | |
| 3767 | acl myhost hdr(Host) -f myhost.lst |
| 3768 | |
| 3769 | http-request add-acl(myhost.lst) %[req.hdr(X-Add-Acl-Key)] if key add |
| 3770 | http-request del-acl(myhost.lst) %[req.hdr(X-Add-Acl-Key)] if key del |
| 3771 | |
| 3772 | Example: |
| 3773 | acl value req.hdr(X-Value) -m found |
| 3774 | acl setmap path /setmap |
| 3775 | acl delmap path /delmap |
| 3776 | |
| 3777 | use_backend bk_appli if { hdr(Host),map_str(map.lst) -m found } |
| 3778 | |
| 3779 | http-request set-map(map.lst) %[src] %[req.hdr(X-Value)] if setmap value |
| 3780 | http-request del-map(map.lst) %[src] if delmap |
| 3781 | |
Cyril Bonté | 2be1b3f | 2010-09-30 23:46:30 +0200 | [diff] [blame] | 3782 | See also : "stats http-request", section 3.4 about userlists and section 7 |
| 3783 | about ACL usage. |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3784 | |
Willy Tarreau | f4c43c1 | 2013-06-11 17:01:13 +0200 | [diff] [blame] | 3785 | http-response { allow | deny | add-header <name> <fmt> | set-nice <nice> | |
Willy Tarreau | 51d861a | 2015-05-22 17:30:48 +0200 | [diff] [blame] | 3786 | capture <sample> id <id> | redirect <rule> | |
Thierry FOURNIER | dad3d1d | 2014-04-22 18:07:25 +0200 | [diff] [blame] | 3787 | set-header <name> <fmt> | del-header <name> | |
Sasha Pachev | 218f064 | 2014-06-16 12:05:59 -0600 | [diff] [blame] | 3788 | replace-header <name> <regex-match> <replace-fmt> | |
| 3789 | replace-value <name> <regex-match> <replace-fmt> | |
Thierry FOURNIER | 35d70ef | 2015-08-26 16:21:56 +0200 | [diff] [blame] | 3790 | set-status <status> | |
Baptiste Assmann | fabcbe0 | 2014-04-24 22:16:59 +0200 | [diff] [blame] | 3791 | set-log-level <level> | set-mark <mark> | set-tos <tos> | |
| 3792 | add-acl(<file name>) <key fmt> | |
| 3793 | del-acl(<file name>) <key fmt> | |
| 3794 | del-map(<file name>) <key fmt> | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 3795 | set-map(<file name>) <key fmt> <value fmt> | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 3796 | set-var(<var-name>) <expr> | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 3797 | sc-inc-gpc0(<sc-id>) | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3798 | sc-set-gpt0(<sc-id>) <int> | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 3799 | lua <function name> |
Baptiste Assmann | fabcbe0 | 2014-04-24 22:16:59 +0200 | [diff] [blame] | 3800 | } |
Lukas Tribus | 2dd1d1a | 2013-06-19 23:34:41 +0200 | [diff] [blame] | 3801 | [ { if | unless } <condition> ] |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3802 | Access control for Layer 7 responses |
| 3803 | |
| 3804 | May be used in sections: defaults | frontend | listen | backend |
| 3805 | no | yes | yes | yes |
| 3806 | |
| 3807 | The http-response statement defines a set of rules which apply to layer 7 |
| 3808 | processing. The rules are evaluated in their declaration order when they are |
| 3809 | met in a frontend, listen or backend section. Any rule may optionally be |
| 3810 | followed by an ACL-based condition, in which case it will only be evaluated |
| 3811 | if the condition is true. Since these rules apply on responses, the backend |
| 3812 | rules are applied first, followed by the frontend's rules. |
| 3813 | |
| 3814 | The first keyword is the rule's action. Currently supported actions include : |
| 3815 | - "allow" : this stops the evaluation of the rules and lets the response |
| 3816 | pass the check. No further "http-response" rules are evaluated for the |
| 3817 | current section. |
| 3818 | |
| 3819 | - "deny" : this stops the evaluation of the rules and immediately rejects |
| 3820 | the response and emits an HTTP 502 error. No further "http-response" |
| 3821 | rules are evaluated. |
| 3822 | |
| 3823 | - "add-header" appends an HTTP header field whose name is specified in |
| 3824 | <name> and whose value is defined by <fmt> which follows the log-format |
| 3825 | rules (see Custom Log Format in section 8.2.4). This may be used to send |
| 3826 | a cookie to a client for example, or to pass some internal information. |
| 3827 | This rule is not final, so it is possible to add other similar rules. |
| 3828 | Note that header addition is performed immediately, so one rule might |
| 3829 | reuse the resulting header from a previous rule. |
| 3830 | |
| 3831 | - "set-header" does the same as "add-header" except that the header name |
| 3832 | is first removed if it existed. This is useful when passing security |
| 3833 | information to the server, where the header must not be manipulated by |
| 3834 | external users. |
| 3835 | |
Thierry FOURNIER | dad3d1d | 2014-04-22 18:07:25 +0200 | [diff] [blame] | 3836 | - "del-header" removes all HTTP header fields whose name is specified in |
| 3837 | <name>. |
| 3838 | |
Sasha Pachev | 218f064 | 2014-06-16 12:05:59 -0600 | [diff] [blame] | 3839 | - "replace-header" matches the regular expression in all occurrences of |
| 3840 | header field <name> according to <match-regex>, and replaces them with |
| 3841 | the <replace-fmt> argument. Format characters are allowed in replace-fmt |
| 3842 | and work like in <fmt> arguments in "add-header". The match is only |
| 3843 | case-sensitive. It is important to understand that this action only |
| 3844 | considers whole header lines, regardless of the number of values they |
| 3845 | may contain. This usage is suited to headers naturally containing commas |
| 3846 | in their value, such as Set-Cookie, Expires and so on. |
| 3847 | |
| 3848 | Example: |
| 3849 | |
| 3850 | http-response replace-header Set-Cookie (C=[^;]*);(.*) \1;ip=%bi;\2 |
| 3851 | |
| 3852 | applied to: |
| 3853 | |
| 3854 | Set-Cookie: C=1; expires=Tue, 14-Jun-2016 01:40:45 GMT |
| 3855 | |
| 3856 | outputs: |
| 3857 | |
| 3858 | Set-Cookie: C=1;ip=192.168.1.20; expires=Tue, 14-Jun-2016 01:40:45 GMT |
| 3859 | |
| 3860 | assuming the backend IP is 192.168.1.20. |
| 3861 | |
| 3862 | - "replace-value" works like "replace-header" except that it matches the |
| 3863 | regex against every comma-delimited value of the header field <name> |
| 3864 | instead of the entire header. This is suited for all headers which are |
| 3865 | allowed to carry more than one value. An example could be the Accept |
| 3866 | header. |
| 3867 | |
| 3868 | Example: |
| 3869 | |
| 3870 | http-response replace-value Cache-control ^public$ private |
| 3871 | |
| 3872 | applied to: |
| 3873 | |
| 3874 | Cache-Control: max-age=3600, public |
| 3875 | |
| 3876 | outputs: |
| 3877 | |
| 3878 | Cache-Control: max-age=3600, private |
| 3879 | |
Thierry FOURNIER | 35d70ef | 2015-08-26 16:21:56 +0200 | [diff] [blame] | 3880 | - "set-status" replaces the response status code with <status> which must |
| 3881 | be an integer between 100 and 999. Note that the reason is automatically |
| 3882 | adapted to the new code. |
| 3883 | |
| 3884 | Example: |
| 3885 | |
| 3886 | # return "431 Request Header Fields Too Large" |
| 3887 | http-response set-status 431 |
| 3888 | |
Willy Tarreau | f4c43c1 | 2013-06-11 17:01:13 +0200 | [diff] [blame] | 3889 | - "set-nice" sets the "nice" factor of the current request being processed. |
| 3890 | It only has effect against the other requests being processed at the same |
| 3891 | time. The default value is 0, unless altered by the "nice" setting on the |
| 3892 | "bind" line. The accepted range is -1024..1024. The higher the value, the |
| 3893 | nicest the request will be. Lower values will make the request more |
| 3894 | important than other ones. This can be useful to improve the speed of |
| 3895 | some requests, or lower the priority of non-important requests. Using |
| 3896 | this setting without prior experimentation can cause some major slowdown. |
| 3897 | |
Willy Tarreau | 9a355ec | 2013-06-11 17:45:46 +0200 | [diff] [blame] | 3898 | - "set-log-level" is used to change the log level of the current request |
| 3899 | when a certain condition is met. Valid levels are the 8 syslog levels |
| 3900 | (see the "log" keyword) plus the special level "silent" which disables |
| 3901 | logging for this request. This rule is not final so the last matching |
| 3902 | rule wins. This rule can be useful to disable health checks coming from |
| 3903 | another equipment. |
| 3904 | |
Willy Tarreau | 42cf39e | 2013-06-11 18:51:32 +0200 | [diff] [blame] | 3905 | - "set-tos" is used to set the TOS or DSCP field value of packets sent to |
| 3906 | the client to the value passed in <tos> on platforms which support this. |
| 3907 | This value represents the whole 8 bits of the IP TOS field, and can be |
| 3908 | expressed both in decimal or hexadecimal format (prefixed by "0x"). Note |
| 3909 | that only the 6 higher bits are used in DSCP or TOS, and the two lower |
| 3910 | bits are always 0. This can be used to adjust some routing behaviour on |
| 3911 | border routers based on some information from the request. See RFC 2474, |
| 3912 | 2597, 3260 and 4594 for more information. |
| 3913 | |
Willy Tarreau | 51347ed | 2013-06-11 19:34:13 +0200 | [diff] [blame] | 3914 | - "set-mark" is used to set the Netfilter MARK on all packets sent to the |
| 3915 | client to the value passed in <mark> on platforms which support it. This |
| 3916 | value is an unsigned 32 bit value which can be matched by netfilter and |
| 3917 | by the routing table. It can be expressed both in decimal or hexadecimal |
| 3918 | format (prefixed by "0x"). This can be useful to force certain packets to |
| 3919 | take a different route (for example a cheaper network path for bulk |
| 3920 | downloads). This works on Linux kernels 2.6.32 and above and requires |
| 3921 | admin privileges. |
| 3922 | |
Baptiste Assmann | fabcbe0 | 2014-04-24 22:16:59 +0200 | [diff] [blame] | 3923 | - "add-acl" is used to add a new entry into an ACL. The ACL must be loaded |
| 3924 | from a file (even a dummy empty file). The file name of the ACL to be |
| 3925 | updated is passed between parentheses. It takes one argument: <key fmt>, |
| 3926 | which follows log-format rules, to collect content of the new entry. It |
| 3927 | performs a lookup in the ACL before insertion, to avoid duplicated (or |
| 3928 | more) values. This lookup is done by a linear search and can be expensive |
| 3929 | with large lists! It is the equivalent of the "add acl" command from the |
| 3930 | stats socket, but can be triggered by an HTTP response. |
| 3931 | |
| 3932 | - "del-acl" is used to delete an entry from an ACL. The ACL must be loaded |
| 3933 | from a file (even a dummy empty file). The file name of the ACL to be |
| 3934 | updated is passed between parentheses. It takes one argument: <key fmt>, |
| 3935 | which follows log-format rules, to collect content of the entry to delete. |
| 3936 | It is the equivalent of the "del acl" command from the stats socket, but |
| 3937 | can be triggered by an HTTP response. |
| 3938 | |
| 3939 | - "del-map" is used to delete an entry from a MAP. The MAP must be loaded |
| 3940 | from a file (even a dummy empty file). The file name of the MAP to be |
| 3941 | updated is passed between parentheses. It takes one argument: <key fmt>, |
| 3942 | which follows log-format rules, to collect content of the entry to delete. |
| 3943 | It takes one argument: "file name" It is the equivalent of the "del map" |
| 3944 | command from the stats socket, but can be triggered by an HTTP response. |
| 3945 | |
| 3946 | - "set-map" is used to add a new entry into a MAP. The MAP must be loaded |
| 3947 | from a file (even a dummy empty file). The file name of the MAP to be |
| 3948 | updated is passed between parentheses. It takes 2 arguments: <key fmt>, |
| 3949 | which follows log-format rules, used to collect MAP key, and <value fmt>, |
| 3950 | which follows log-format rules, used to collect content for the new entry. |
| 3951 | It performs a lookup in the MAP before insertion, to avoid duplicated (or |
| 3952 | more) values. This lookup is done by a linear search and can be expensive |
| 3953 | with large lists! It is the equivalent of the "set map" command from the |
| 3954 | stats socket, but can be triggered by an HTTP response. |
| 3955 | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 3956 | - "lua" is used to run a Lua function if the action is executed. The single |
| 3957 | parameter is the name of the function to run. The prototype of the |
| 3958 | function is documented in the API documentation. |
| 3959 | |
Thierry FOURNIER | e80fada | 2015-05-26 18:06:31 +0200 | [diff] [blame] | 3960 | - capture <sample> id <id> : |
| 3961 | captures sample expression <sample> from the response buffer, and converts |
| 3962 | it to a string. The resulting string is stored into the next request |
| 3963 | "capture" slot, so it will possibly appear next to some captured HTTP |
| 3964 | headers. It will then automatically appear in the logs, and it will be |
| 3965 | possible to extract it using sample fetch rules to feed it into headers or |
| 3966 | anything. Please check section 7.3 (Fetching samples) and "capture |
| 3967 | response header" for more information. |
| 3968 | |
| 3969 | The keyword "id" is the id of the capture slot which is used for storing |
| 3970 | the string. The capture slot must be defined in an associated frontend. |
| 3971 | This is useful to run captures in backends. The slot id can be declared by |
| 3972 | a previous directive "http-response capture" or with the "declare capture" |
| 3973 | keyword. |
| 3974 | |
Willy Tarreau | 51d861a | 2015-05-22 17:30:48 +0200 | [diff] [blame] | 3975 | - "redirect" : this performs an HTTP redirection based on a redirect rule. |
| 3976 | This supports a format string similarly to "http-request redirect" rules, |
| 3977 | with the exception that only the "location" type of redirect is possible |
| 3978 | on the response. See the "redirect" keyword for the rule's syntax. When |
| 3979 | a redirect rule is applied during a response, connections to the server |
| 3980 | are closed so that no data can be forwarded from the server to the client. |
| 3981 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 3982 | - set-var(<var-name>) expr: |
| 3983 | Is used to set the contents of a variable. The variable is declared |
| 3984 | inline. |
| 3985 | |
| 3986 | <var-name> The name of the variable starts by an indication about its |
| 3987 | scope. The allowed scopes are: |
| 3988 | "sess" : the variable is shared with all the session, |
| 3989 | "txn" : the variable is shared with all the transaction |
| 3990 | (request and response) |
| 3991 | "req" : the variable is shared only during the request |
| 3992 | processing |
| 3993 | "res" : the variable is shared only during the response |
| 3994 | processing. |
| 3995 | This prefix is followed by a name. The separator is a '.'. |
| 3996 | The name may only contain characters 'a-z', 'A-Z', '0-9', |
| 3997 | and '_'. |
| 3998 | |
| 3999 | <expr> Is a standard HAProxy expression formed by a sample-fetch |
| 4000 | followed by some converters. |
| 4001 | |
| 4002 | Example: |
| 4003 | |
| 4004 | http-response set-var(sess.last_redir) res.hdr(location) |
| 4005 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 4006 | - sc-set-gpt0(<sc-id>) <int> : |
| 4007 | This action sets the GPT0 tag according to the sticky counter designated |
| 4008 | by <sc-id> and the value of <int>. The expected result is a boolean. If |
| 4009 | an error occurs, this action silently fails and the actions evaluation |
| 4010 | continues. |
| 4011 | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 4012 | - sc-inc-gpc0(<sc-id>): |
| 4013 | This action increments the GPC0 counter according with the sticky counter |
| 4014 | designated by <sc-id>. If an error occurs, this action silently fails and |
| 4015 | the actions evaluation continues. |
| 4016 | |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 4017 | There is no limit to the number of http-response statements per instance. |
| 4018 | |
Godbach | 0925026 | 2013-07-02 01:19:15 +0800 | [diff] [blame] | 4019 | It is important to know that http-response rules are processed very early in |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 4020 | the HTTP processing, before "reqdel" or "reqrep" rules. That way, headers |
| 4021 | added by "add-header"/"set-header" are visible by almost all further ACL |
| 4022 | rules. |
| 4023 | |
Baptiste Assmann | fabcbe0 | 2014-04-24 22:16:59 +0200 | [diff] [blame] | 4024 | Example: |
| 4025 | acl key_acl res.hdr(X-Acl-Key) -m found |
| 4026 | |
| 4027 | acl myhost hdr(Host) -f myhost.lst |
| 4028 | |
| 4029 | http-response add-acl(myhost.lst) %[res.hdr(X-Acl-Key)] if key_acl |
| 4030 | http-response del-acl(myhost.lst) %[res.hdr(X-Acl-Key)] if key_acl |
| 4031 | |
| 4032 | Example: |
| 4033 | acl value res.hdr(X-Value) -m found |
| 4034 | |
| 4035 | use_backend bk_appli if { hdr(Host),map_str(map.lst) -m found } |
| 4036 | |
| 4037 | http-response set-map(map.lst) %[src] %[res.hdr(X-Value)] if value |
| 4038 | http-response del-map(map.lst) %[src] if ! value |
| 4039 | |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 4040 | See also : "http-request", section 3.4 about userlists and section 7 about |
| 4041 | ACL usage. |
| 4042 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4043 | |
Willy Tarreau | 3063195 | 2015-08-06 15:05:24 +0200 | [diff] [blame] | 4044 | http-reuse { never | safe | aggressive | always } |
| 4045 | Declare how idle HTTP connections may be shared between requests |
| 4046 | |
| 4047 | May be used in sections: defaults | frontend | listen | backend |
| 4048 | yes | no | yes | yes |
| 4049 | |
| 4050 | By default, a connection established between haproxy and the backend server |
| 4051 | belongs to the session that initiated it. The downside is that between the |
| 4052 | response and the next request, the connection remains idle and is not used. |
| 4053 | In many cases for performance reasons it is desirable to make it possible to |
| 4054 | reuse these idle connections to serve other requests from different sessions. |
| 4055 | This directive allows to tune this behaviour. |
| 4056 | |
| 4057 | The argument indicates the desired connection reuse strategy : |
| 4058 | |
| 4059 | - "never" : idle connections are never shared between sessions. This is |
| 4060 | the default choice. It may be enforced to cancel a different |
| 4061 | strategy inherited from a defaults section or for |
| 4062 | troubleshooting. For example, if an old bogus application |
| 4063 | considers that multiple requests over the same connection come |
| 4064 | from the same client and it is not possible to fix the |
| 4065 | application, it may be desirable to disable connection sharing |
| 4066 | in a single backend. An example of such an application could |
| 4067 | be an old haproxy using cookie insertion in tunnel mode and |
| 4068 | not checking any request past the first one. |
| 4069 | |
| 4070 | - "safe" : this is the recommended strategy. The first request of a |
| 4071 | session is always sent over its own connection, and only |
| 4072 | subsequent requests may be dispatched over other existing |
| 4073 | connections. This ensures that in case the server closes the |
| 4074 | connection when the request is being sent, the browser can |
| 4075 | decide to silently retry it. Since it is exactly equivalent to |
| 4076 | regular keep-alive, there should be no side effects. |
| 4077 | |
| 4078 | - "aggressive" : this mode may be useful in webservices environments where |
| 4079 | all servers are not necessarily known and where it would be |
| 4080 | appreciable to deliver most first requests over existing |
| 4081 | connections. In this case, first requests are only delivered |
| 4082 | over existing connections that have been reused at least once, |
| 4083 | proving that the server correctly supports connection reuse. |
| 4084 | It should only be used when it's sure that the client can |
| 4085 | retry a failed request once in a while and where the benefit |
| 4086 | of aggressive connection reuse significantly outweights the |
| 4087 | downsides of rare connection failures. |
| 4088 | |
| 4089 | - "always" : this mode is only recommended when the path to the server is |
| 4090 | known for never breaking existing connections quickly after |
| 4091 | releasing them. It allows the first request of a session to be |
| 4092 | sent to an existing connection. This can provide a significant |
| 4093 | performance increase over the "safe" strategy when the backend |
| 4094 | is a cache farm, since such components tend to show a |
| 4095 | consistent behaviour and will benefit from the connection |
| 4096 | sharing. It is recommended that the "http-keep-alive" timeout |
| 4097 | remains low in this mode so that no dead connections remain |
| 4098 | usable. In most cases, this will lead to the same performance |
| 4099 | gains as "aggressive" but with more risks. It should only be |
| 4100 | used when it improves the situation over "aggressive". |
| 4101 | |
| 4102 | When http connection sharing is enabled, a great care is taken to respect the |
| 4103 | connection properties and compatiblities. Specifically : |
| 4104 | - connections made with "usesrc" followed by a client-dependant value |
| 4105 | ("client", "clientip", "hdr_ip") are marked private and never shared ; |
| 4106 | |
| 4107 | - connections sent to a server with a TLS SNI extension are marked private |
| 4108 | and are never shared ; |
| 4109 | |
| 4110 | - connections receiving a status code 401 or 407 expect some authentication |
| 4111 | to be sent in return. Due to certain bogus authentication schemes (such |
| 4112 | as NTLM) relying on the connection, these connections are marked private |
| 4113 | and are never shared ; |
| 4114 | |
| 4115 | No connection pool is involved, once a session dies, the last idle connection |
| 4116 | it was attached to is deleted at the same time. This ensures that connections |
| 4117 | may not last after all sessions are closed. |
| 4118 | |
| 4119 | Note: connection reuse improves the accuracy of the "server maxconn" setting, |
| 4120 | because almost no new connection will be established while idle connections |
| 4121 | remain available. This is particularly true with the "always" strategy. |
| 4122 | |
| 4123 | See also : "option http-keep-alive", "server maxconn" |
| 4124 | |
| 4125 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 4126 | http-send-name-header [<header>] |
| 4127 | Add the server name to a request. Use the header string given by <header> |
| 4128 | |
| 4129 | May be used in sections: defaults | frontend | listen | backend |
| 4130 | yes | no | yes | yes |
| 4131 | |
| 4132 | Arguments : |
| 4133 | |
| 4134 | <header> The header string to use to send the server name |
| 4135 | |
| 4136 | The "http-send-name-header" statement causes the name of the target |
| 4137 | server to be added to the headers of an HTTP request. The name |
| 4138 | is added with the header string proved. |
| 4139 | |
| 4140 | See also : "server" |
| 4141 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4142 | id <value> |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4143 | Set a persistent ID to a proxy. |
| 4144 | May be used in sections : defaults | frontend | listen | backend |
| 4145 | no | yes | yes | yes |
| 4146 | Arguments : none |
| 4147 | |
| 4148 | Set a persistent ID for the proxy. This ID must be unique and positive. |
| 4149 | An unused ID will automatically be assigned if unset. The first assigned |
| 4150 | value will be 1. This ID is currently only returned in statistics. |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4151 | |
| 4152 | |
Cyril Bonté | 0d4bf01 | 2010-04-25 23:21:46 +0200 | [diff] [blame] | 4153 | ignore-persist { if | unless } <condition> |
| 4154 | Declare a condition to ignore persistence |
| 4155 | May be used in sections: defaults | frontend | listen | backend |
| 4156 | no | yes | yes | yes |
| 4157 | |
| 4158 | By default, when cookie persistence is enabled, every requests containing |
| 4159 | the cookie are unconditionally persistent (assuming the target server is up |
| 4160 | and running). |
| 4161 | |
| 4162 | The "ignore-persist" statement allows one to declare various ACL-based |
| 4163 | conditions which, when met, will cause a request to ignore persistence. |
| 4164 | This is sometimes useful to load balance requests for static files, which |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 4165 | often don't require persistence. This can also be used to fully disable |
Cyril Bonté | 0d4bf01 | 2010-04-25 23:21:46 +0200 | [diff] [blame] | 4166 | persistence for a specific User-Agent (for example, some web crawler bots). |
| 4167 | |
Cyril Bonté | 0d4bf01 | 2010-04-25 23:21:46 +0200 | [diff] [blame] | 4168 | The persistence is ignored when an "if" condition is met, or unless an |
| 4169 | "unless" condition is met. |
| 4170 | |
| 4171 | See also : "force-persist", "cookie", and section 7 about ACL usage. |
| 4172 | |
Baptiste Assmann | 01c6cc3 | 2015-08-23 11:45:29 +0200 | [diff] [blame] | 4173 | load-server-state-from-file { global | local | none } |
| 4174 | Allow seamless reload of HAProxy |
| 4175 | May be used in sections: defaults | frontend | listen | backend |
| 4176 | yes | no | yes | yes |
| 4177 | |
| 4178 | This directive points HAProxy to a file where server state from previous |
| 4179 | running process has been saved. That way, when starting up, before handling |
| 4180 | traffic, the new process can apply old states to servers exactly has if no |
| 4181 | reload occured. The purpose of the "load-server-state-from-file" directive is |
| 4182 | to tell haproxy which file to use. For now, only 2 arguments to either prevent |
| 4183 | loading state or load states from a file containing all backends and servers. |
| 4184 | The state file can be generated by running the command "show servers state" |
| 4185 | over the stats socket and redirect output. |
| 4186 | |
| 4187 | The format of the file is versionned and is very specific. To understand it, |
| 4188 | please read the documentation of the "show servers state" command (chapter |
| 4189 | 9.2). |
| 4190 | |
| 4191 | Arguments: |
| 4192 | global load the content of the file pointed by the global directive |
| 4193 | named "server-state-file". |
| 4194 | |
| 4195 | local load the content of the file pointed by the directive |
| 4196 | "server-state-file-name" if set. If not set, then the backend |
| 4197 | name is used as a file name. |
| 4198 | |
| 4199 | none don't load any stat for this backend |
| 4200 | |
| 4201 | Notes: |
| 4202 | - server's IP address is not updated unless DNS resolution is enabled on |
| 4203 | the server. It means that if a server IP address has been changed using |
| 4204 | the stat socket, this information won't be re-applied after reloading. |
| 4205 | |
| 4206 | - server's weight is applied from previous running process unless it has |
| 4207 | has changed between previous and new configuration files. |
| 4208 | |
| 4209 | Example 1: |
| 4210 | |
| 4211 | Minimal configuration: |
| 4212 | |
| 4213 | global |
| 4214 | stats socket /tmp/socket |
| 4215 | server-state-file /tmp/server_state |
| 4216 | |
| 4217 | defaults |
| 4218 | load-server-state-from-file global |
| 4219 | |
| 4220 | backend bk |
| 4221 | server s1 127.0.0.1:22 check weight 11 |
| 4222 | server s2 127.0.0.1:22 check weight 12 |
| 4223 | |
| 4224 | Then one can run : |
| 4225 | |
| 4226 | socat /tmp/socket - <<< "show servers state" > /tmp/server_state |
| 4227 | |
| 4228 | Content of the file /tmp/server_state would be like this: |
| 4229 | |
| 4230 | 1 |
| 4231 | # <field names skipped for the doc example> |
| 4232 | 1 bk 1 s1 127.0.0.1 2 0 11 11 4 6 3 4 6 0 0 |
| 4233 | 1 bk 2 s2 127.0.0.1 2 0 12 12 4 6 3 4 6 0 0 |
| 4234 | |
| 4235 | Example 2: |
| 4236 | |
| 4237 | Minimal configuration: |
| 4238 | |
| 4239 | global |
| 4240 | stats socket /tmp/socket |
| 4241 | server-state-base /etc/haproxy/states |
| 4242 | |
| 4243 | defaults |
| 4244 | load-server-state-from-file local |
| 4245 | |
| 4246 | backend bk |
| 4247 | server s1 127.0.0.1:22 check weight 11 |
| 4248 | server s2 127.0.0.1:22 check weight 12 |
| 4249 | |
| 4250 | Then one can run : |
| 4251 | |
| 4252 | socat /tmp/socket - <<< "show servers state bk" > /etc/haproxy/states/bk |
| 4253 | |
| 4254 | Content of the file /etc/haproxy/states/bk would be like this: |
| 4255 | |
| 4256 | 1 |
| 4257 | # <field names skipped for the doc example> |
| 4258 | 1 bk 1 s1 127.0.0.1 2 0 11 11 4 6 3 4 6 0 0 |
| 4259 | 1 bk 2 s2 127.0.0.1 2 0 12 12 4 6 3 4 6 0 0 |
| 4260 | |
| 4261 | See also: "server-state-file", "server-state-file-name", and |
| 4262 | "show servers state" |
| 4263 | |
Cyril Bonté | 0d4bf01 | 2010-04-25 23:21:46 +0200 | [diff] [blame] | 4264 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4265 | log global |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4266 | log <address> [len <length>] <facility> [<level> [<minlevel>]] |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4267 | no log |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4268 | Enable per-instance logging of events and traffic. |
| 4269 | May be used in sections : defaults | frontend | listen | backend |
| 4270 | yes | yes | yes | yes |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4271 | |
| 4272 | Prefix : |
| 4273 | no should be used when the logger list must be flushed. For example, |
| 4274 | if you don't want to inherit from the default logger list. This |
| 4275 | prefix does not allow arguments. |
| 4276 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4277 | Arguments : |
| 4278 | global should be used when the instance's logging parameters are the |
| 4279 | same as the global ones. This is the most common usage. "global" |
| 4280 | replaces <address>, <facility> and <level> with those of the log |
| 4281 | entries found in the "global" section. Only one "log global" |
| 4282 | statement may be used per instance, and this form takes no other |
| 4283 | parameter. |
| 4284 | |
| 4285 | <address> indicates where to send the logs. It takes the same format as |
| 4286 | for the "global" section's logs, and can be one of : |
| 4287 | |
| 4288 | - An IPv4 address optionally followed by a colon (':') and a UDP |
| 4289 | port. If no port is specified, 514 is used by default (the |
| 4290 | standard syslog port). |
| 4291 | |
David du Colombier | 24bb5f5 | 2011-03-17 10:40:23 +0100 | [diff] [blame] | 4292 | - An IPv6 address followed by a colon (':') and optionally a UDP |
| 4293 | port. If no port is specified, 514 is used by default (the |
| 4294 | standard syslog port). |
| 4295 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4296 | - A filesystem path to a UNIX domain socket, keeping in mind |
| 4297 | considerations for chroot (be sure the path is accessible |
| 4298 | inside the chroot) and uid/gid (be sure the path is |
| 4299 | appropriately writeable). |
| 4300 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 4301 | You may want to reference some environment variables in the |
| 4302 | address parameter, see section 2.3 about environment variables. |
Willy Tarreau | dad36a3 | 2013-03-11 01:20:04 +0100 | [diff] [blame] | 4303 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4304 | <length> is an optional maximum line length. Log lines larger than this |
| 4305 | value will be truncated before being sent. The reason is that |
| 4306 | syslog servers act differently on log line length. All servers |
| 4307 | support the default value of 1024, but some servers simply drop |
| 4308 | larger lines while others do log them. If a server supports long |
| 4309 | lines, it may make sense to set this value here in order to avoid |
| 4310 | truncating long lines. Similarly, if a server drops long lines, |
| 4311 | it is preferable to truncate them before sending them. Accepted |
| 4312 | values are 80 to 65535 inclusive. The default value of 1024 is |
| 4313 | generally fine for all standard usages. Some specific cases of |
| 4314 | long captures or JSON-formated logs may require larger values. |
| 4315 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4316 | <facility> must be one of the 24 standard syslog facilities : |
| 4317 | |
| 4318 | kern user mail daemon auth syslog lpr news |
| 4319 | uucp cron auth2 ftp ntp audit alert cron2 |
| 4320 | local0 local1 local2 local3 local4 local5 local6 local7 |
| 4321 | |
| 4322 | <level> is optional and can be specified to filter outgoing messages. By |
| 4323 | default, all messages are sent. If a level is specified, only |
| 4324 | messages with a severity at least as important as this level |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4325 | will be sent. An optional minimum level can be specified. If it |
| 4326 | is set, logs emitted with a more severe level than this one will |
| 4327 | be capped to this level. This is used to avoid sending "emerg" |
| 4328 | messages on all terminals on some default syslog configurations. |
| 4329 | Eight levels are known : |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4330 | |
| 4331 | emerg alert crit err warning notice info debug |
| 4332 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4333 | It is important to keep in mind that it is the frontend which decides what to |
| 4334 | log from a connection, and that in case of content switching, the log entries |
| 4335 | from the backend will be ignored. Connections are logged at level "info". |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 4336 | |
| 4337 | However, backend log declaration define how and where servers status changes |
| 4338 | will be logged. Level "notice" will be used to indicate a server going up, |
| 4339 | "warning" will be used for termination signals and definitive service |
| 4340 | termination, and "alert" will be used for when a server goes down. |
| 4341 | |
| 4342 | Note : According to RFC3164, messages are truncated to 1024 bytes before |
| 4343 | being emitted. |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4344 | |
| 4345 | Example : |
| 4346 | log global |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4347 | log 127.0.0.1:514 local0 notice # only send important events |
| 4348 | log 127.0.0.1:514 local0 notice notice # same but limit output level |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 4349 | log "${LOCAL_SYSLOG}:514" local0 notice # send to local server |
Willy Tarreau | dad36a3 | 2013-03-11 01:20:04 +0100 | [diff] [blame] | 4350 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4351 | |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 4352 | log-format <string> |
Willy Tarreau | fb4e7ea | 2015-01-07 14:55:17 +0100 | [diff] [blame] | 4353 | Specifies the log format string to use for traffic logs |
| 4354 | May be used in sections: defaults | frontend | listen | backend |
| 4355 | yes | yes | yes | no |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 4356 | |
Willy Tarreau | fb4e7ea | 2015-01-07 14:55:17 +0100 | [diff] [blame] | 4357 | This directive specifies the log format string that will be used for all logs |
| 4358 | resulting from traffic passing through the frontend using this line. If the |
| 4359 | directive is used in a defaults section, all subsequent frontends will use |
| 4360 | the same log format. Please see section 8.2.4 which covers the log format |
| 4361 | string in depth. |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 4362 | |
Dragan Dosen | 7ad3154 | 2015-09-28 17:16:47 +0200 | [diff] [blame] | 4363 | log-format-sd <string> |
| 4364 | Specifies the RFC5424 structured-data log format string |
| 4365 | May be used in sections: defaults | frontend | listen | backend |
| 4366 | yes | yes | yes | no |
| 4367 | |
| 4368 | This directive specifies the RFC5424 structured-data log format string that |
| 4369 | will be used for all logs resulting from traffic passing through the frontend |
| 4370 | using this line. If the directive is used in a defaults section, all |
| 4371 | subsequent frontends will use the same log format. Please see section 8.2.4 |
| 4372 | which covers the log format string in depth. |
| 4373 | |
| 4374 | See https://tools.ietf.org/html/rfc5424#section-6.3 for more information |
| 4375 | about the RFC5424 structured-data part. |
| 4376 | |
| 4377 | Note : This log format string will be used only for loggers that have set |
| 4378 | log format to "rfc5424". |
| 4379 | |
| 4380 | Example : |
| 4381 | log-format-sd [exampleSDID@1234\ bytes=\"%B\"\ status=\"%ST\"] |
| 4382 | |
| 4383 | |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 4384 | log-tag <string> |
| 4385 | Specifies the log tag to use for all outgoing logs |
| 4386 | May be used in sections: defaults | frontend | listen | backend |
| 4387 | yes | yes | yes | yes |
| 4388 | |
| 4389 | Sets the tag field in the syslog header to this string. It defaults to the |
| 4390 | log-tag set in the global section, otherwise the program name as launched |
| 4391 | from the command line, which usually is "haproxy". Sometimes it can be useful |
| 4392 | to differentiate between multiple processes running on the same host, or to |
| 4393 | differentiate customer instances running in the same process. In the backend, |
| 4394 | logs about servers up/down will use this tag. As a hint, it can be convenient |
| 4395 | to set a log-tag related to a hosted customer in a defaults section then put |
| 4396 | all the frontends and backends for that customer, then start another customer |
| 4397 | in a new defaults section. See also the global "log-tag" directive. |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4398 | |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 4399 | max-keep-alive-queue <value> |
| 4400 | Set the maximum server queue size for maintaining keep-alive connections |
| 4401 | May be used in sections: defaults | frontend | listen | backend |
| 4402 | yes | no | yes | yes |
| 4403 | |
| 4404 | HTTP keep-alive tries to reuse the same server connection whenever possible, |
| 4405 | but sometimes it can be counter-productive, for example if a server has a lot |
| 4406 | of connections while other ones are idle. This is especially true for static |
| 4407 | servers. |
| 4408 | |
| 4409 | The purpose of this setting is to set a threshold on the number of queued |
| 4410 | connections at which haproxy stops trying to reuse the same server and prefers |
| 4411 | to find another one. The default value, -1, means there is no limit. A value |
| 4412 | of zero means that keep-alive requests will never be queued. For very close |
| 4413 | servers which can be reached with a low latency and which are not sensible to |
| 4414 | breaking keep-alive, a low value is recommended (eg: local static server can |
| 4415 | use a value of 10 or less). For remote servers suffering from a high latency, |
| 4416 | higher values might be needed to cover for the latency and/or the cost of |
| 4417 | picking a different server. |
| 4418 | |
| 4419 | Note that this has no impact on responses which are maintained to the same |
| 4420 | server consecutively to a 401 response. They will still go to the same server |
| 4421 | even if they have to be queued. |
| 4422 | |
| 4423 | See also : "option http-server-close", "option prefer-last-server", server |
| 4424 | "maxconn" and cookie persistence. |
| 4425 | |
| 4426 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4427 | maxconn <conns> |
| 4428 | Fix the maximum number of concurrent connections on a frontend |
| 4429 | May be used in sections : defaults | frontend | listen | backend |
| 4430 | yes | yes | yes | no |
| 4431 | Arguments : |
| 4432 | <conns> is the maximum number of concurrent connections the frontend will |
| 4433 | accept to serve. Excess connections will be queued by the system |
| 4434 | in the socket's listen queue and will be served once a connection |
| 4435 | closes. |
| 4436 | |
| 4437 | If the system supports it, it can be useful on big sites to raise this limit |
| 4438 | very high so that haproxy manages connection queues, instead of leaving the |
| 4439 | clients with unanswered connection attempts. This value should not exceed the |
| 4440 | global maxconn. Also, keep in mind that a connection contains two buffers |
| 4441 | of 8kB each, as well as some other data resulting in about 17 kB of RAM being |
| 4442 | consumed per established connection. That means that a medium system equipped |
| 4443 | with 1GB of RAM can withstand around 40000-50000 concurrent connections if |
| 4444 | properly tuned. |
| 4445 | |
| 4446 | Also, when <conns> is set to large values, it is possible that the servers |
| 4447 | are not sized to accept such loads, and for this reason it is generally wise |
| 4448 | to assign them some reasonable connection limits. |
| 4449 | |
Vincent Bernat | 6341be5 | 2012-06-27 17:18:30 +0200 | [diff] [blame] | 4450 | By default, this value is set to 2000. |
| 4451 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4452 | See also : "server", global section's "maxconn", "fullconn" |
| 4453 | |
| 4454 | |
| 4455 | mode { tcp|http|health } |
| 4456 | Set the running mode or protocol of the instance |
| 4457 | May be used in sections : defaults | frontend | listen | backend |
| 4458 | yes | yes | yes | yes |
| 4459 | Arguments : |
| 4460 | tcp The instance will work in pure TCP mode. A full-duplex connection |
| 4461 | will be established between clients and servers, and no layer 7 |
| 4462 | examination will be performed. This is the default mode. It |
| 4463 | should be used for SSL, SSH, SMTP, ... |
| 4464 | |
| 4465 | http The instance will work in HTTP mode. The client request will be |
| 4466 | analyzed in depth before connecting to any server. Any request |
| 4467 | which is not RFC-compliant will be rejected. Layer 7 filtering, |
| 4468 | processing and switching will be possible. This is the mode which |
| 4469 | brings HAProxy most of its value. |
| 4470 | |
| 4471 | health The instance will work in "health" mode. It will just reply "OK" |
Willy Tarreau | 82569f9 | 2012-09-27 23:48:56 +0200 | [diff] [blame] | 4472 | to incoming connections and close the connection. Alternatively, |
| 4473 | If the "httpchk" option is set, "HTTP/1.0 200 OK" will be sent |
| 4474 | instead. Nothing will be logged in either case. This mode is used |
| 4475 | to reply to external components health checks. This mode is |
| 4476 | deprecated and should not be used anymore as it is possible to do |
| 4477 | the same and even better by combining TCP or HTTP modes with the |
| 4478 | "monitor" keyword. |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4479 | |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 4480 | When doing content switching, it is mandatory that the frontend and the |
| 4481 | backend are in the same mode (generally HTTP), otherwise the configuration |
| 4482 | will be refused. |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4483 | |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 4484 | Example : |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4485 | defaults http_instances |
| 4486 | mode http |
| 4487 | |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 4488 | See also : "monitor", "monitor-net" |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4489 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 4490 | |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 4491 | monitor fail { if | unless } <condition> |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4492 | Add a condition to report a failure to a monitor HTTP request. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 4493 | May be used in sections : defaults | frontend | listen | backend |
| 4494 | no | yes | yes | no |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 4495 | Arguments : |
| 4496 | if <cond> the monitor request will fail if the condition is satisfied, |
| 4497 | and will succeed otherwise. The condition should describe a |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 4498 | combined test which must induce a failure if all conditions |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 4499 | are met, for instance a low number of servers both in a |
| 4500 | backend and its backup. |
| 4501 | |
| 4502 | unless <cond> the monitor request will succeed only if the condition is |
| 4503 | satisfied, and will fail otherwise. Such a condition may be |
| 4504 | based on a test on the presence of a minimum number of active |
| 4505 | servers in a list of backends. |
| 4506 | |
| 4507 | This statement adds a condition which can force the response to a monitor |
| 4508 | request to report a failure. By default, when an external component queries |
| 4509 | the URI dedicated to monitoring, a 200 response is returned. When one of the |
| 4510 | conditions above is met, haproxy will return 503 instead of 200. This is |
| 4511 | very useful to report a site failure to an external component which may base |
| 4512 | routing advertisements between multiple sites on the availability reported by |
| 4513 | haproxy. In this case, one would rely on an ACL involving the "nbsrv" |
Willy Tarreau | ae94d4d | 2011-05-11 16:28:49 +0200 | [diff] [blame] | 4514 | criterion. Note that "monitor fail" only works in HTTP mode. Both status |
| 4515 | messages may be tweaked using "errorfile" or "errorloc" if needed. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 4516 | |
| 4517 | Example: |
| 4518 | frontend www |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4519 | mode http |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 4520 | acl site_dead nbsrv(dynamic) lt 2 |
| 4521 | acl site_dead nbsrv(static) lt 2 |
| 4522 | monitor-uri /site_alive |
| 4523 | monitor fail if site_dead |
| 4524 | |
Willy Tarreau | ae94d4d | 2011-05-11 16:28:49 +0200 | [diff] [blame] | 4525 | See also : "monitor-net", "monitor-uri", "errorfile", "errorloc" |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4526 | |
| 4527 | |
| 4528 | monitor-net <source> |
| 4529 | Declare a source network which is limited to monitor requests |
| 4530 | May be used in sections : defaults | frontend | listen | backend |
| 4531 | yes | yes | yes | no |
| 4532 | Arguments : |
| 4533 | <source> is the source IPv4 address or network which will only be able to |
| 4534 | get monitor responses to any request. It can be either an IPv4 |
| 4535 | address, a host name, or an address followed by a slash ('/') |
| 4536 | followed by a mask. |
| 4537 | |
| 4538 | In TCP mode, any connection coming from a source matching <source> will cause |
| 4539 | the connection to be immediately closed without any log. This allows another |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 4540 | equipment to probe the port and verify that it is still listening, without |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4541 | forwarding the connection to a remote server. |
| 4542 | |
| 4543 | In HTTP mode, a connection coming from a source matching <source> will be |
| 4544 | accepted, the following response will be sent without waiting for a request, |
| 4545 | then the connection will be closed : "HTTP/1.0 200 OK". This is normally |
| 4546 | enough for any front-end HTTP probe to detect that the service is UP and |
Willy Tarreau | 82569f9 | 2012-09-27 23:48:56 +0200 | [diff] [blame] | 4547 | running without forwarding the request to a backend server. Note that this |
| 4548 | response is sent in raw format, without any transformation. This is important |
| 4549 | as it means that it will not be SSL-encrypted on SSL listeners. |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4550 | |
Willy Tarreau | 82569f9 | 2012-09-27 23:48:56 +0200 | [diff] [blame] | 4551 | Monitor requests are processed very early, just after tcp-request connection |
| 4552 | ACLs which are the only ones able to block them. These connections are short |
| 4553 | lived and never wait for any data from the client. They cannot be logged, and |
| 4554 | it is the intended purpose. They are only used to report HAProxy's health to |
| 4555 | an upper component, nothing more. Please note that "monitor fail" rules do |
| 4556 | not apply to connections intercepted by "monitor-net". |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4557 | |
Willy Tarreau | 95cd283 | 2010-03-04 23:36:33 +0100 | [diff] [blame] | 4558 | Last, please note that only one "monitor-net" statement can be specified in |
| 4559 | a frontend. If more than one is found, only the last one will be considered. |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 4560 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 4561 | Example : |
| 4562 | # addresses .252 and .253 are just probing us. |
| 4563 | frontend www |
| 4564 | monitor-net 192.168.0.252/31 |
| 4565 | |
| 4566 | See also : "monitor fail", "monitor-uri" |
| 4567 | |
| 4568 | |
| 4569 | monitor-uri <uri> |
| 4570 | Intercept a URI used by external components' monitor requests |
| 4571 | May be used in sections : defaults | frontend | listen | backend |
| 4572 | yes | yes | yes | no |
| 4573 | Arguments : |
| 4574 | <uri> is the exact URI which we want to intercept to return HAProxy's |
| 4575 | health status instead of forwarding the request. |
| 4576 | |
| 4577 | When an HTTP request referencing <uri> will be received on a frontend, |
| 4578 | HAProxy will not forward it nor log it, but instead will return either |
| 4579 | "HTTP/1.0 200 OK" or "HTTP/1.0 503 Service unavailable", depending on failure |
| 4580 | conditions defined with "monitor fail". This is normally enough for any |
| 4581 | front-end HTTP probe to detect that the service is UP and running without |
| 4582 | forwarding the request to a backend server. Note that the HTTP method, the |
| 4583 | version and all headers are ignored, but the request must at least be valid |
| 4584 | at the HTTP level. This keyword may only be used with an HTTP-mode frontend. |
| 4585 | |
| 4586 | Monitor requests are processed very early. It is not possible to block nor |
| 4587 | divert them using ACLs. They cannot be logged either, and it is the intended |
| 4588 | purpose. They are only used to report HAProxy's health to an upper component, |
| 4589 | nothing more. However, it is possible to add any number of conditions using |
| 4590 | "monitor fail" and ACLs so that the result can be adjusted to whatever check |
| 4591 | can be imagined (most often the number of available servers in a backend). |
| 4592 | |
| 4593 | Example : |
| 4594 | # Use /haproxy_test to report haproxy's status |
| 4595 | frontend www |
| 4596 | mode http |
| 4597 | monitor-uri /haproxy_test |
| 4598 | |
| 4599 | See also : "monitor fail", "monitor-net" |
| 4600 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 4601 | |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4602 | option abortonclose |
| 4603 | no option abortonclose |
| 4604 | Enable or disable early dropping of aborted requests pending in queues. |
| 4605 | May be used in sections : defaults | frontend | listen | backend |
| 4606 | yes | no | yes | yes |
| 4607 | Arguments : none |
| 4608 | |
| 4609 | In presence of very high loads, the servers will take some time to respond. |
| 4610 | The per-instance connection queue will inflate, and the response time will |
| 4611 | increase respective to the size of the queue times the average per-session |
| 4612 | response time. When clients will wait for more than a few seconds, they will |
Willy Tarreau | 198a744 | 2008-01-17 12:05:32 +0100 | [diff] [blame] | 4613 | often hit the "STOP" button on their browser, leaving a useless request in |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4614 | the queue, and slowing down other users, and the servers as well, because the |
| 4615 | request will eventually be served, then aborted at the first error |
| 4616 | encountered while delivering the response. |
| 4617 | |
| 4618 | As there is no way to distinguish between a full STOP and a simple output |
| 4619 | close on the client side, HTTP agents should be conservative and consider |
| 4620 | that the client might only have closed its output channel while waiting for |
| 4621 | the response. However, this introduces risks of congestion when lots of users |
| 4622 | do the same, and is completely useless nowadays because probably no client at |
| 4623 | all will close the session while waiting for the response. Some HTTP agents |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 4624 | support this behaviour (Squid, Apache, HAProxy), and others do not (TUX, most |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4625 | hardware-based load balancers). So the probability for a closed input channel |
Willy Tarreau | 198a744 | 2008-01-17 12:05:32 +0100 | [diff] [blame] | 4626 | to represent a user hitting the "STOP" button is close to 100%, and the risk |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4627 | of being the single component to break rare but valid traffic is extremely |
| 4628 | low, which adds to the temptation to be able to abort a session early while |
| 4629 | still not served and not pollute the servers. |
| 4630 | |
| 4631 | In HAProxy, the user can choose the desired behaviour using the option |
| 4632 | "abortonclose". By default (without the option) the behaviour is HTTP |
| 4633 | compliant and aborted requests will be served. But when the option is |
| 4634 | specified, a session with an incoming channel closed will be aborted while |
| 4635 | it is still possible, either pending in the queue for a connection slot, or |
| 4636 | during the connection establishment if the server has not yet acknowledged |
| 4637 | the connection request. This considerably reduces the queue size and the load |
| 4638 | on saturated servers when users are tempted to click on STOP, which in turn |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 4639 | reduces the response time for other users. |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4640 | |
| 4641 | If this option has been enabled in a "defaults" section, it can be disabled |
| 4642 | in a specific instance by prepending the "no" keyword before it. |
| 4643 | |
| 4644 | See also : "timeout queue" and server's "maxconn" and "maxqueue" parameters |
| 4645 | |
| 4646 | |
Willy Tarreau | 4076a15 | 2009-04-02 15:18:36 +0200 | [diff] [blame] | 4647 | option accept-invalid-http-request |
| 4648 | no option accept-invalid-http-request |
| 4649 | Enable or disable relaxing of HTTP request parsing |
| 4650 | May be used in sections : defaults | frontend | listen | backend |
| 4651 | yes | yes | yes | no |
| 4652 | Arguments : none |
| 4653 | |
Willy Tarreau | 91852eb | 2015-05-01 13:26:00 +0200 | [diff] [blame] | 4654 | By default, HAProxy complies with RFC7230 in terms of message parsing. This |
Willy Tarreau | 4076a15 | 2009-04-02 15:18:36 +0200 | [diff] [blame] | 4655 | means that invalid characters in header names are not permitted and cause an |
| 4656 | error to be returned to the client. This is the desired behaviour as such |
| 4657 | forbidden characters are essentially used to build attacks exploiting server |
| 4658 | weaknesses, and bypass security filtering. Sometimes, a buggy browser or |
| 4659 | server will emit invalid header names for whatever reason (configuration, |
| 4660 | implementation) and the issue will not be immediately fixed. In such a case, |
| 4661 | it is possible to relax HAProxy's header name parser to accept any character |
Willy Tarreau | 422246e | 2012-01-07 23:54:13 +0100 | [diff] [blame] | 4662 | even if that does not make sense, by specifying this option. Similarly, the |
| 4663 | list of characters allowed to appear in a URI is well defined by RFC3986, and |
| 4664 | chars 0-31, 32 (space), 34 ('"'), 60 ('<'), 62 ('>'), 92 ('\'), 94 ('^'), 96 |
| 4665 | ('`'), 123 ('{'), 124 ('|'), 125 ('}'), 127 (delete) and anything above are |
| 4666 | not allowed at all. Haproxy always blocks a number of them (0..32, 127). The |
Willy Tarreau | 91852eb | 2015-05-01 13:26:00 +0200 | [diff] [blame] | 4667 | remaining ones are blocked by default unless this option is enabled. This |
Willy Tarreau | 1331766 | 2015-05-01 13:47:08 +0200 | [diff] [blame] | 4668 | option also relaxes the test on the HTTP version, it allows HTTP/0.9 requests |
| 4669 | to pass through (no version specified) and multiple digits for both the major |
| 4670 | and the minor version. |
Willy Tarreau | 4076a15 | 2009-04-02 15:18:36 +0200 | [diff] [blame] | 4671 | |
| 4672 | This option should never be enabled by default as it hides application bugs |
| 4673 | and open security breaches. It should only be deployed after a problem has |
| 4674 | been confirmed. |
| 4675 | |
| 4676 | When this option is enabled, erroneous header names will still be accepted in |
| 4677 | requests, but the complete request will be captured in order to permit later |
Willy Tarreau | 422246e | 2012-01-07 23:54:13 +0100 | [diff] [blame] | 4678 | analysis using the "show errors" request on the UNIX stats socket. Similarly, |
| 4679 | requests containing invalid chars in the URI part will be logged. Doing this |
Willy Tarreau | 4076a15 | 2009-04-02 15:18:36 +0200 | [diff] [blame] | 4680 | also helps confirming that the issue has been solved. |
| 4681 | |
| 4682 | If this option has been enabled in a "defaults" section, it can be disabled |
| 4683 | in a specific instance by prepending the "no" keyword before it. |
| 4684 | |
| 4685 | See also : "option accept-invalid-http-response" and "show errors" on the |
| 4686 | stats socket. |
| 4687 | |
| 4688 | |
| 4689 | option accept-invalid-http-response |
| 4690 | no option accept-invalid-http-response |
| 4691 | Enable or disable relaxing of HTTP response parsing |
| 4692 | May be used in sections : defaults | frontend | listen | backend |
| 4693 | yes | no | yes | yes |
| 4694 | Arguments : none |
| 4695 | |
Willy Tarreau | 91852eb | 2015-05-01 13:26:00 +0200 | [diff] [blame] | 4696 | By default, HAProxy complies with RFC7230 in terms of message parsing. This |
Willy Tarreau | 4076a15 | 2009-04-02 15:18:36 +0200 | [diff] [blame] | 4697 | means that invalid characters in header names are not permitted and cause an |
| 4698 | error to be returned to the client. This is the desired behaviour as such |
| 4699 | forbidden characters are essentially used to build attacks exploiting server |
| 4700 | weaknesses, and bypass security filtering. Sometimes, a buggy browser or |
| 4701 | server will emit invalid header names for whatever reason (configuration, |
| 4702 | implementation) and the issue will not be immediately fixed. In such a case, |
| 4703 | it is possible to relax HAProxy's header name parser to accept any character |
Willy Tarreau | 91852eb | 2015-05-01 13:26:00 +0200 | [diff] [blame] | 4704 | even if that does not make sense, by specifying this option. This option also |
| 4705 | relaxes the test on the HTTP version format, it allows multiple digits for |
| 4706 | both the major and the minor version. |
Willy Tarreau | 4076a15 | 2009-04-02 15:18:36 +0200 | [diff] [blame] | 4707 | |
| 4708 | This option should never be enabled by default as it hides application bugs |
| 4709 | and open security breaches. It should only be deployed after a problem has |
| 4710 | been confirmed. |
| 4711 | |
| 4712 | When this option is enabled, erroneous header names will still be accepted in |
| 4713 | responses, but the complete response will be captured in order to permit |
| 4714 | later analysis using the "show errors" request on the UNIX stats socket. |
| 4715 | Doing this also helps confirming that the issue has been solved. |
| 4716 | |
| 4717 | If this option has been enabled in a "defaults" section, it can be disabled |
| 4718 | in a specific instance by prepending the "no" keyword before it. |
| 4719 | |
| 4720 | See also : "option accept-invalid-http-request" and "show errors" on the |
| 4721 | stats socket. |
| 4722 | |
| 4723 | |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4724 | option allbackups |
| 4725 | no option allbackups |
| 4726 | Use either all backup servers at a time or only the first one |
| 4727 | May be used in sections : defaults | frontend | listen | backend |
| 4728 | yes | no | yes | yes |
| 4729 | Arguments : none |
| 4730 | |
| 4731 | By default, the first operational backup server gets all traffic when normal |
| 4732 | servers are all down. Sometimes, it may be preferred to use multiple backups |
| 4733 | at once, because one will not be enough. When "option allbackups" is enabled, |
| 4734 | the load balancing will be performed among all backup servers when all normal |
| 4735 | ones are unavailable. The same load balancing algorithm will be used and the |
| 4736 | servers' weights will be respected. Thus, there will not be any priority |
| 4737 | order between the backup servers anymore. |
| 4738 | |
| 4739 | This option is mostly used with static server farms dedicated to return a |
| 4740 | "sorry" page when an application is completely offline. |
| 4741 | |
| 4742 | If this option has been enabled in a "defaults" section, it can be disabled |
| 4743 | in a specific instance by prepending the "no" keyword before it. |
| 4744 | |
| 4745 | |
| 4746 | option checkcache |
| 4747 | no option checkcache |
Godbach | 7056a35 | 2013-12-11 20:01:07 +0800 | [diff] [blame] | 4748 | Analyze all server responses and block responses with cacheable cookies |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4749 | May be used in sections : defaults | frontend | listen | backend |
| 4750 | yes | no | yes | yes |
| 4751 | Arguments : none |
| 4752 | |
| 4753 | Some high-level frameworks set application cookies everywhere and do not |
| 4754 | always let enough control to the developer to manage how the responses should |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 4755 | be cached. When a session cookie is returned on a cacheable object, there is a |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4756 | high risk of session crossing or stealing between users traversing the same |
| 4757 | caches. In some situations, it is better to block the response than to let |
Willy Tarreau | 3c92c5f | 2011-08-28 09:45:47 +0200 | [diff] [blame] | 4758 | some sensitive session information go in the wild. |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4759 | |
| 4760 | The option "checkcache" enables deep inspection of all server responses for |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 4761 | strict compliance with HTTP specification in terms of cacheability. It |
Willy Tarreau | 198a744 | 2008-01-17 12:05:32 +0100 | [diff] [blame] | 4762 | carefully checks "Cache-control", "Pragma" and "Set-cookie" headers in server |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4763 | response to check if there's a risk of caching a cookie on a client-side |
| 4764 | proxy. When this option is enabled, the only responses which can be delivered |
Willy Tarreau | 198a744 | 2008-01-17 12:05:32 +0100 | [diff] [blame] | 4765 | to the client are : |
| 4766 | - all those without "Set-Cookie" header ; |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4767 | - all those with a return code other than 200, 203, 206, 300, 301, 410, |
Willy Tarreau | 198a744 | 2008-01-17 12:05:32 +0100 | [diff] [blame] | 4768 | provided that the server has not set a "Cache-control: public" header ; |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4769 | - all those that come from a POST request, provided that the server has not |
| 4770 | set a 'Cache-Control: public' header ; |
| 4771 | - those with a 'Pragma: no-cache' header |
| 4772 | - those with a 'Cache-control: private' header |
| 4773 | - those with a 'Cache-control: no-store' header |
| 4774 | - those with a 'Cache-control: max-age=0' header |
| 4775 | - those with a 'Cache-control: s-maxage=0' header |
| 4776 | - those with a 'Cache-control: no-cache' header |
| 4777 | - those with a 'Cache-control: no-cache="set-cookie"' header |
| 4778 | - those with a 'Cache-control: no-cache="set-cookie,' header |
| 4779 | (allowing other fields after set-cookie) |
| 4780 | |
| 4781 | If a response doesn't respect these requirements, then it will be blocked |
Willy Tarreau | 198a744 | 2008-01-17 12:05:32 +0100 | [diff] [blame] | 4782 | just as if it was from an "rspdeny" filter, with an "HTTP 502 bad gateway". |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4783 | The session state shows "PH--" meaning that the proxy blocked the response |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 4784 | during headers processing. Additionally, an alert will be sent in the logs so |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4785 | that admins are informed that there's something to be fixed. |
| 4786 | |
| 4787 | Due to the high impact on the application, the application should be tested |
| 4788 | in depth with the option enabled before going to production. It is also a |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 4789 | good practice to always activate it during tests, even if it is not used in |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4790 | production, as it will report potentially dangerous application behaviours. |
| 4791 | |
| 4792 | If this option has been enabled in a "defaults" section, it can be disabled |
| 4793 | in a specific instance by prepending the "no" keyword before it. |
| 4794 | |
| 4795 | |
| 4796 | option clitcpka |
| 4797 | no option clitcpka |
| 4798 | Enable or disable the sending of TCP keepalive packets on the client side |
| 4799 | May be used in sections : defaults | frontend | listen | backend |
| 4800 | yes | yes | yes | no |
| 4801 | Arguments : none |
| 4802 | |
| 4803 | When there is a firewall or any session-aware component between a client and |
| 4804 | a server, and when the protocol involves very long sessions with long idle |
| 4805 | periods (eg: remote desktops), there is a risk that one of the intermediate |
| 4806 | components decides to expire a session which has remained idle for too long. |
| 4807 | |
| 4808 | Enabling socket-level TCP keep-alives makes the system regularly send packets |
| 4809 | to the other end of the connection, leaving it active. The delay between |
| 4810 | keep-alive probes is controlled by the system only and depends both on the |
| 4811 | operating system and its tuning parameters. |
| 4812 | |
| 4813 | It is important to understand that keep-alive packets are neither emitted nor |
| 4814 | received at the application level. It is only the network stacks which sees |
| 4815 | them. For this reason, even if one side of the proxy already uses keep-alives |
| 4816 | to maintain its connection alive, those keep-alive packets will not be |
| 4817 | forwarded to the other side of the proxy. |
| 4818 | |
| 4819 | Please note that this has nothing to do with HTTP keep-alive. |
| 4820 | |
| 4821 | Using option "clitcpka" enables the emission of TCP keep-alive probes on the |
| 4822 | client side of a connection, which should help when session expirations are |
| 4823 | noticed between HAProxy and a client. |
| 4824 | |
| 4825 | If this option has been enabled in a "defaults" section, it can be disabled |
| 4826 | in a specific instance by prepending the "no" keyword before it. |
| 4827 | |
| 4828 | See also : "option srvtcpka", "option tcpka" |
| 4829 | |
| 4830 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 4831 | option contstats |
| 4832 | Enable continuous traffic statistics updates |
| 4833 | May be used in sections : defaults | frontend | listen | backend |
| 4834 | yes | yes | yes | no |
| 4835 | Arguments : none |
| 4836 | |
| 4837 | By default, counters used for statistics calculation are incremented |
| 4838 | only when a session finishes. It works quite well when serving small |
| 4839 | objects, but with big ones (for example large images or archives) or |
| 4840 | with A/V streaming, a graph generated from haproxy counters looks like |
| 4841 | a hedgehog. With this option enabled counters get incremented continuously, |
| 4842 | during a whole session. Recounting touches a hotpath directly so |
| 4843 | it is not enabled by default, as it has small performance impact (~0.5%). |
| 4844 | |
| 4845 | |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 4846 | option dontlog-normal |
| 4847 | no option dontlog-normal |
| 4848 | Enable or disable logging of normal, successful connections |
| 4849 | May be used in sections : defaults | frontend | listen | backend |
| 4850 | yes | yes | yes | no |
| 4851 | Arguments : none |
| 4852 | |
| 4853 | There are large sites dealing with several thousand connections per second |
| 4854 | and for which logging is a major pain. Some of them are even forced to turn |
| 4855 | logs off and cannot debug production issues. Setting this option ensures that |
| 4856 | normal connections, those which experience no error, no timeout, no retry nor |
| 4857 | redispatch, will not be logged. This leaves disk space for anomalies. In HTTP |
| 4858 | mode, the response status code is checked and return codes 5xx will still be |
| 4859 | logged. |
| 4860 | |
| 4861 | It is strongly discouraged to use this option as most of the time, the key to |
| 4862 | complex issues is in the normal logs which will not be logged here. If you |
| 4863 | need to separate logs, see the "log-separate-errors" option instead. |
| 4864 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 4865 | See also : "log", "dontlognull", "log-separate-errors" and section 8 about |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 4866 | logging. |
| 4867 | |
| 4868 | |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4869 | option dontlognull |
| 4870 | no option dontlognull |
| 4871 | Enable or disable logging of null connections |
| 4872 | May be used in sections : defaults | frontend | listen | backend |
| 4873 | yes | yes | yes | no |
| 4874 | Arguments : none |
| 4875 | |
| 4876 | In certain environments, there are components which will regularly connect to |
| 4877 | various systems to ensure that they are still alive. It can be the case from |
| 4878 | another load balancer as well as from monitoring systems. By default, even a |
| 4879 | simple port probe or scan will produce a log. If those connections pollute |
| 4880 | the logs too much, it is possible to enable option "dontlognull" to indicate |
| 4881 | that a connection on which no data has been transferred will not be logged, |
Willy Tarreau | 0f228a0 | 2015-05-01 15:37:53 +0200 | [diff] [blame] | 4882 | which typically corresponds to those probes. Note that errors will still be |
| 4883 | returned to the client and accounted for in the stats. If this is not what is |
| 4884 | desired, option http-ignore-probes can be used instead. |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4885 | |
| 4886 | It is generally recommended not to use this option in uncontrolled |
| 4887 | environments (eg: internet), otherwise scans and other malicious activities |
| 4888 | would not be logged. |
| 4889 | |
| 4890 | If this option has been enabled in a "defaults" section, it can be disabled |
| 4891 | in a specific instance by prepending the "no" keyword before it. |
| 4892 | |
Willy Tarreau | 0f228a0 | 2015-05-01 15:37:53 +0200 | [diff] [blame] | 4893 | See also : "log", "http-ignore-probes", "monitor-net", "monitor-uri", and |
| 4894 | section 8 about logging. |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4895 | |
| 4896 | |
| 4897 | option forceclose |
| 4898 | no option forceclose |
| 4899 | Enable or disable active connection closing after response is transferred. |
| 4900 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | a31e5df | 2009-12-30 01:10:35 +0100 | [diff] [blame] | 4901 | yes | yes | yes | yes |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4902 | Arguments : none |
| 4903 | |
| 4904 | Some HTTP servers do not necessarily close the connections when they receive |
| 4905 | the "Connection: close" set by "option httpclose", and if the client does not |
| 4906 | close either, then the connection remains open till the timeout expires. This |
| 4907 | causes high number of simultaneous connections on the servers and shows high |
| 4908 | global session times in the logs. |
| 4909 | |
| 4910 | When this happens, it is possible to use "option forceclose". It will |
Willy Tarreau | 82eeaf2 | 2009-12-29 12:09:05 +0100 | [diff] [blame] | 4911 | actively close the outgoing server channel as soon as the server has finished |
Cyril Bonté | 653dcd6 | 2014-02-20 00:13:15 +0100 | [diff] [blame] | 4912 | to respond and release some resources earlier than with "option httpclose". |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4913 | |
Willy Tarreau | 8a8e1d9 | 2010-04-05 16:15:16 +0200 | [diff] [blame] | 4914 | This option may also be combined with "option http-pretend-keepalive", which |
| 4915 | will disable sending of the "Connection: close" header, but will still cause |
| 4916 | the connection to be closed once the whole response is received. |
| 4917 | |
Cyril Bonté | 653dcd6 | 2014-02-20 00:13:15 +0100 | [diff] [blame] | 4918 | This option disables and replaces any previous "option httpclose", "option |
| 4919 | http-server-close", "option http-keep-alive", or "option http-tunnel". |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4920 | |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4921 | If this option has been enabled in a "defaults" section, it can be disabled |
| 4922 | in a specific instance by prepending the "no" keyword before it. |
| 4923 | |
Willy Tarreau | 8a8e1d9 | 2010-04-05 16:15:16 +0200 | [diff] [blame] | 4924 | See also : "option httpclose" and "option http-pretend-keepalive" |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 4925 | |
| 4926 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4927 | option forwardfor [ except <network> ] [ header <name> ] [ if-none ] |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 4928 | Enable insertion of the X-Forwarded-For header to requests sent to servers |
| 4929 | May be used in sections : defaults | frontend | listen | backend |
| 4930 | yes | yes | yes | yes |
| 4931 | Arguments : |
| 4932 | <network> is an optional argument used to disable this option for sources |
| 4933 | matching <network> |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4934 | <name> an optional argument to specify a different "X-Forwarded-For" |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 4935 | header name. |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 4936 | |
| 4937 | Since HAProxy works in reverse-proxy mode, the servers see its IP address as |
| 4938 | their client address. This is sometimes annoying when the client's IP address |
| 4939 | is expected in server logs. To solve this problem, the well-known HTTP header |
| 4940 | "X-Forwarded-For" may be added by HAProxy to all requests sent to the server. |
| 4941 | This header contains a value representing the client's IP address. Since this |
| 4942 | header is always appended at the end of the existing header list, the server |
| 4943 | must be configured to always use the last occurrence of this header only. See |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4944 | the server's manual to find how to enable use of this standard header. Note |
| 4945 | that only the last occurrence of the header must be used, since it is really |
| 4946 | possible that the client has already brought one. |
| 4947 | |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 4948 | The keyword "header" may be used to supply a different header name to replace |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4949 | the default "X-Forwarded-For". This can be useful where you might already |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 4950 | have a "X-Forwarded-For" header from a different application (eg: stunnel), |
| 4951 | and you need preserve it. Also if your backend server doesn't use the |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4952 | "X-Forwarded-For" header and requires different one (eg: Zeus Web Servers |
| 4953 | require "X-Cluster-Client-IP"). |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 4954 | |
| 4955 | Sometimes, a same HAProxy instance may be shared between a direct client |
| 4956 | access and a reverse-proxy access (for instance when an SSL reverse-proxy is |
| 4957 | used to decrypt HTTPS traffic). It is possible to disable the addition of the |
| 4958 | header for a known source address or network by adding the "except" keyword |
| 4959 | followed by the network address. In this case, any source IP matching the |
| 4960 | network will not cause an addition of this header. Most common uses are with |
| 4961 | private networks or 127.0.0.1. |
| 4962 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4963 | Alternatively, the keyword "if-none" states that the header will only be |
| 4964 | added if it is not present. This should only be used in perfectly trusted |
| 4965 | environment, as this might cause a security issue if headers reaching haproxy |
| 4966 | are under the control of the end-user. |
| 4967 | |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 4968 | This option may be specified either in the frontend or in the backend. If at |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4969 | least one of them uses it, the header will be added. Note that the backend's |
| 4970 | setting of the header subargument takes precedence over the frontend's if |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4971 | both are defined. In the case of the "if-none" argument, if at least one of |
| 4972 | the frontend or the backend does not specify it, it wants the addition to be |
| 4973 | mandatory, so it wins. |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 4974 | |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4975 | Examples : |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 4976 | # Public HTTP address also used by stunnel on the same machine |
| 4977 | frontend www |
| 4978 | mode http |
| 4979 | option forwardfor except 127.0.0.1 # stunnel already adds the header |
| 4980 | |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4981 | # Those servers want the IP Address in X-Client |
| 4982 | backend www |
| 4983 | mode http |
| 4984 | option forwardfor header X-Client |
| 4985 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4986 | See also : "option httpclose", "option http-server-close", |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 4987 | "option forceclose", "option http-keep-alive" |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 4988 | |
Willy Tarreau | 8a8e1d9 | 2010-04-05 16:15:16 +0200 | [diff] [blame] | 4989 | |
Willy Tarreau | 9fbe18e | 2015-05-01 22:42:08 +0200 | [diff] [blame] | 4990 | option http-buffer-request |
| 4991 | no option http-buffer-request |
| 4992 | Enable or disable waiting for whole HTTP request body before proceeding |
| 4993 | May be used in sections : defaults | frontend | listen | backend |
| 4994 | yes | yes | yes | yes |
| 4995 | Arguments : none |
| 4996 | |
| 4997 | It is sometimes desirable to wait for the body of an HTTP request before |
| 4998 | taking a decision. This is what is being done by "balance url_param" for |
| 4999 | example. The first use case is to buffer requests from slow clients before |
| 5000 | connecting to the server. Another use case consists in taking the routing |
| 5001 | decision based on the request body's contents. This option placed in a |
| 5002 | frontend or backend forces the HTTP processing to wait until either the whole |
| 5003 | body is received, or the request buffer is full, or the first chunk is |
| 5004 | complete in case of chunked encoding. It can have undesired side effects with |
| 5005 | some applications abusing HTTP by expecting unbufferred transmissions between |
| 5006 | the frontend and the backend, so this should definitely not be used by |
| 5007 | default. |
| 5008 | |
| 5009 | See also : "option http-no-delay" |
| 5010 | |
| 5011 | |
Willy Tarreau | 0f228a0 | 2015-05-01 15:37:53 +0200 | [diff] [blame] | 5012 | option http-ignore-probes |
| 5013 | no option http-ignore-probes |
| 5014 | Enable or disable logging of null connections and request timeouts |
| 5015 | May be used in sections : defaults | frontend | listen | backend |
| 5016 | yes | yes | yes | no |
| 5017 | Arguments : none |
| 5018 | |
| 5019 | Recently some browsers started to implement a "pre-connect" feature |
| 5020 | consisting in speculatively connecting to some recently visited web sites |
| 5021 | just in case the user would like to visit them. This results in many |
| 5022 | connections being established to web sites, which end up in 408 Request |
| 5023 | Timeout if the timeout strikes first, or 400 Bad Request when the browser |
| 5024 | decides to close them first. These ones pollute the log and feed the error |
| 5025 | counters. There was already "option dontlognull" but it's insufficient in |
| 5026 | this case. Instead, this option does the following things : |
| 5027 | - prevent any 400/408 message from being sent to the client if nothing |
| 5028 | was received over a connection before it was closed ; |
| 5029 | - prevent any log from being emitted in this situation ; |
| 5030 | - prevent any error counter from being incremented |
| 5031 | |
| 5032 | That way the empty connection is silently ignored. Note that it is better |
| 5033 | not to use this unless it is clear that it is needed, because it will hide |
| 5034 | real problems. The most common reason for not receiving a request and seeing |
| 5035 | a 408 is due to an MTU inconsistency between the client and an intermediary |
| 5036 | element such as a VPN, which blocks too large packets. These issues are |
| 5037 | generally seen with POST requests as well as GET with large cookies. The logs |
| 5038 | are often the only way to detect them. |
| 5039 | |
| 5040 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5041 | in a specific instance by prepending the "no" keyword before it. |
| 5042 | |
| 5043 | See also : "log", "dontlognull", "errorfile", and section 8 about logging. |
| 5044 | |
| 5045 | |
Willy Tarreau | 16bfb02 | 2010-01-16 19:48:41 +0100 | [diff] [blame] | 5046 | option http-keep-alive |
| 5047 | no option http-keep-alive |
| 5048 | Enable or disable HTTP keep-alive from client to server |
| 5049 | May be used in sections : defaults | frontend | listen | backend |
| 5050 | yes | yes | yes | yes |
| 5051 | Arguments : none |
| 5052 | |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 5053 | By default HAProxy operates in keep-alive mode with regards to persistent |
| 5054 | connections: for each connection it processes each request and response, and |
| 5055 | leaves the connection idle on both sides between the end of a response and the |
| 5056 | start of a new request. This mode may be changed by several options such as |
| 5057 | "option http-server-close", "option forceclose", "option httpclose" or |
| 5058 | "option http-tunnel". This option allows to set back the keep-alive mode, |
| 5059 | which can be useful when another mode was used in a defaults section. |
| 5060 | |
| 5061 | Setting "option http-keep-alive" enables HTTP keep-alive mode on the client- |
| 5062 | and server- sides. This provides the lowest latency on the client side (slow |
Willy Tarreau | 16bfb02 | 2010-01-16 19:48:41 +0100 | [diff] [blame] | 5063 | network) and the fastest session reuse on the server side at the expense |
| 5064 | of maintaining idle connections to the servers. In general, it is possible |
| 5065 | with this option to achieve approximately twice the request rate that the |
| 5066 | "http-server-close" option achieves on small objects. There are mainly two |
| 5067 | situations where this option may be useful : |
| 5068 | |
| 5069 | - when the server is non-HTTP compliant and authenticates the connection |
| 5070 | instead of requests (eg: NTLM authentication) |
| 5071 | |
| 5072 | - when the cost of establishing the connection to the server is significant |
| 5073 | compared to the cost of retrieving the associated object from the server. |
| 5074 | |
| 5075 | This last case can happen when the server is a fast static server of cache. |
| 5076 | In this case, the server will need to be properly tuned to support high enough |
| 5077 | connection counts because connections will last until the client sends another |
| 5078 | request. |
| 5079 | |
| 5080 | If the client request has to go to another backend or another server due to |
| 5081 | content switching or the load balancing algorithm, the idle connection will |
Willy Tarreau | 9420b12 | 2013-12-15 18:58:25 +0100 | [diff] [blame] | 5082 | immediately be closed and a new one re-opened. Option "prefer-last-server" is |
| 5083 | available to try optimize server selection so that if the server currently |
| 5084 | attached to an idle connection is usable, it will be used. |
Willy Tarreau | 16bfb02 | 2010-01-16 19:48:41 +0100 | [diff] [blame] | 5085 | |
| 5086 | In general it is preferred to use "option http-server-close" with application |
| 5087 | servers, and some static servers might benefit from "option http-keep-alive". |
| 5088 | |
| 5089 | At the moment, logs will not indicate whether requests came from the same |
| 5090 | session or not. The accept date reported in the logs corresponds to the end |
| 5091 | of the previous request, and the request time corresponds to the time spent |
| 5092 | waiting for a new request. The keep-alive request time is still bound to the |
| 5093 | timeout defined by "timeout http-keep-alive" or "timeout http-request" if |
| 5094 | not set. |
| 5095 | |
Cyril Bonté | 653dcd6 | 2014-02-20 00:13:15 +0100 | [diff] [blame] | 5096 | This option disables and replaces any previous "option httpclose", "option |
| 5097 | http-server-close", "option forceclose" or "option http-tunnel". When backend |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 5098 | and frontend options differ, all of these 4 options have precedence over |
Cyril Bonté | 653dcd6 | 2014-02-20 00:13:15 +0100 | [diff] [blame] | 5099 | "option http-keep-alive". |
Willy Tarreau | 16bfb02 | 2010-01-16 19:48:41 +0100 | [diff] [blame] | 5100 | |
| 5101 | See also : "option forceclose", "option http-server-close", |
Willy Tarreau | 9420b12 | 2013-12-15 18:58:25 +0100 | [diff] [blame] | 5102 | "option prefer-last-server", "option http-pretend-keepalive", |
| 5103 | "option httpclose", and "1.1. The HTTP transaction model". |
Willy Tarreau | 16bfb02 | 2010-01-16 19:48:41 +0100 | [diff] [blame] | 5104 | |
| 5105 | |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 5106 | option http-no-delay |
| 5107 | no option http-no-delay |
| 5108 | Instruct the system to favor low interactive delays over performance in HTTP |
| 5109 | May be used in sections : defaults | frontend | listen | backend |
| 5110 | yes | yes | yes | yes |
| 5111 | Arguments : none |
| 5112 | |
| 5113 | In HTTP, each payload is unidirectional and has no notion of interactivity. |
| 5114 | Any agent is expected to queue data somewhat for a reasonably low delay. |
| 5115 | There are some very rare server-to-server applications that abuse the HTTP |
| 5116 | protocol and expect the payload phase to be highly interactive, with many |
| 5117 | interleaved data chunks in both directions within a single request. This is |
| 5118 | absolutely not supported by the HTTP specification and will not work across |
| 5119 | most proxies or servers. When such applications attempt to do this through |
| 5120 | haproxy, it works but they will experience high delays due to the network |
| 5121 | optimizations which favor performance by instructing the system to wait for |
| 5122 | enough data to be available in order to only send full packets. Typical |
| 5123 | delays are around 200 ms per round trip. Note that this only happens with |
| 5124 | abnormal uses. Normal uses such as CONNECT requests nor WebSockets are not |
| 5125 | affected. |
| 5126 | |
| 5127 | When "option http-no-delay" is present in either the frontend or the backend |
| 5128 | used by a connection, all such optimizations will be disabled in order to |
| 5129 | make the exchanges as fast as possible. Of course this offers no guarantee on |
| 5130 | the functionality, as it may break at any other place. But if it works via |
| 5131 | HAProxy, it will work as fast as possible. This option should never be used |
| 5132 | by default, and should never be used at all unless such a buggy application |
| 5133 | is discovered. The impact of using this option is an increase of bandwidth |
| 5134 | usage and CPU usage, which may significantly lower performance in high |
| 5135 | latency environments. |
| 5136 | |
Willy Tarreau | 9fbe18e | 2015-05-01 22:42:08 +0200 | [diff] [blame] | 5137 | See also : "option http-buffer-request" |
| 5138 | |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 5139 | |
Willy Tarreau | 8a8e1d9 | 2010-04-05 16:15:16 +0200 | [diff] [blame] | 5140 | option http-pretend-keepalive |
| 5141 | no option http-pretend-keepalive |
| 5142 | Define whether haproxy will announce keepalive to the server or not |
| 5143 | May be used in sections : defaults | frontend | listen | backend |
| 5144 | yes | yes | yes | yes |
| 5145 | Arguments : none |
| 5146 | |
| 5147 | When running with "option http-server-close" or "option forceclose", haproxy |
| 5148 | adds a "Connection: close" header to the request forwarded to the server. |
| 5149 | Unfortunately, when some servers see this header, they automatically refrain |
| 5150 | from using the chunked encoding for responses of unknown length, while this |
| 5151 | is totally unrelated. The immediate effect is that this prevents haproxy from |
| 5152 | maintaining the client connection alive. A second effect is that a client or |
| 5153 | a cache could receive an incomplete response without being aware of it, and |
| 5154 | consider the response complete. |
| 5155 | |
| 5156 | By setting "option http-pretend-keepalive", haproxy will make the server |
| 5157 | believe it will keep the connection alive. The server will then not fall back |
| 5158 | to the abnormal undesired above. When haproxy gets the whole response, it |
| 5159 | will close the connection with the server just as it would do with the |
| 5160 | "forceclose" option. That way the client gets a normal response and the |
| 5161 | connection is correctly closed on the server side. |
| 5162 | |
| 5163 | It is recommended not to enable this option by default, because most servers |
| 5164 | will more efficiently close the connection themselves after the last packet, |
| 5165 | and release its buffers slightly earlier. Also, the added packet on the |
| 5166 | network could slightly reduce the overall peak performance. However it is |
| 5167 | worth noting that when this option is enabled, haproxy will have slightly |
| 5168 | less work to do. So if haproxy is the bottleneck on the whole architecture, |
| 5169 | enabling this option might save a few CPU cycles. |
| 5170 | |
| 5171 | This option may be set both in a frontend and in a backend. It is enabled if |
| 5172 | at least one of the frontend or backend holding a connection has it enabled. |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 5173 | This option may be combined with "option httpclose", which will cause |
Willy Tarreau | 22a9534 | 2010-09-29 14:31:41 +0200 | [diff] [blame] | 5174 | keepalive to be announced to the server and close to be announced to the |
| 5175 | client. This practice is discouraged though. |
Willy Tarreau | 8a8e1d9 | 2010-04-05 16:15:16 +0200 | [diff] [blame] | 5176 | |
| 5177 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5178 | in a specific instance by prepending the "no" keyword before it. |
| 5179 | |
Willy Tarreau | 16bfb02 | 2010-01-16 19:48:41 +0100 | [diff] [blame] | 5180 | See also : "option forceclose", "option http-server-close", and |
| 5181 | "option http-keep-alive" |
Willy Tarreau | 8a8e1d9 | 2010-04-05 16:15:16 +0200 | [diff] [blame] | 5182 | |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5183 | |
Willy Tarreau | b608feb | 2010-01-02 22:47:18 +0100 | [diff] [blame] | 5184 | option http-server-close |
| 5185 | no option http-server-close |
| 5186 | Enable or disable HTTP connection closing on the server side |
| 5187 | May be used in sections : defaults | frontend | listen | backend |
| 5188 | yes | yes | yes | yes |
| 5189 | Arguments : none |
| 5190 | |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 5191 | By default HAProxy operates in keep-alive mode with regards to persistent |
| 5192 | connections: for each connection it processes each request and response, and |
| 5193 | leaves the connection idle on both sides between the end of a response and |
| 5194 | the start of a new request. This mode may be changed by several options such |
| 5195 | as "option http-server-close", "option forceclose", "option httpclose" or |
| 5196 | "option http-tunnel". Setting "option http-server-close" enables HTTP |
| 5197 | connection-close mode on the server side while keeping the ability to support |
| 5198 | HTTP keep-alive and pipelining on the client side. This provides the lowest |
| 5199 | latency on the client side (slow network) and the fastest session reuse on |
| 5200 | the server side to save server resources, similarly to "option forceclose". |
| 5201 | It also permits non-keepalive capable servers to be served in keep-alive mode |
| 5202 | to the clients if they conform to the requirements of RFC2616. Please note |
| 5203 | that some servers do not always conform to those requirements when they see |
| 5204 | "Connection: close" in the request. The effect will be that keep-alive will |
| 5205 | never be used. A workaround consists in enabling "option |
| 5206 | http-pretend-keepalive". |
Willy Tarreau | b608feb | 2010-01-02 22:47:18 +0100 | [diff] [blame] | 5207 | |
| 5208 | At the moment, logs will not indicate whether requests came from the same |
| 5209 | session or not. The accept date reported in the logs corresponds to the end |
| 5210 | of the previous request, and the request time corresponds to the time spent |
| 5211 | waiting for a new request. The keep-alive request time is still bound to the |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 5212 | timeout defined by "timeout http-keep-alive" or "timeout http-request" if |
| 5213 | not set. |
Willy Tarreau | b608feb | 2010-01-02 22:47:18 +0100 | [diff] [blame] | 5214 | |
| 5215 | This option may be set both in a frontend and in a backend. It is enabled if |
| 5216 | at least one of the frontend or backend holding a connection has it enabled. |
Cyril Bonté | 653dcd6 | 2014-02-20 00:13:15 +0100 | [diff] [blame] | 5217 | It disables and replaces any previous "option httpclose", "option forceclose", |
| 5218 | "option http-tunnel" or "option http-keep-alive". Please check section 4 |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 5219 | ("Proxies") to see how this option combines with others when frontend and |
| 5220 | backend options differ. |
Willy Tarreau | b608feb | 2010-01-02 22:47:18 +0100 | [diff] [blame] | 5221 | |
| 5222 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5223 | in a specific instance by prepending the "no" keyword before it. |
| 5224 | |
Patrick Mezard | 9ec2ec4 | 2010-06-12 17:02:45 +0200 | [diff] [blame] | 5225 | See also : "option forceclose", "option http-pretend-keepalive", |
Willy Tarreau | 16bfb02 | 2010-01-16 19:48:41 +0100 | [diff] [blame] | 5226 | "option httpclose", "option http-keep-alive", and |
| 5227 | "1.1. The HTTP transaction model". |
Willy Tarreau | b608feb | 2010-01-02 22:47:18 +0100 | [diff] [blame] | 5228 | |
| 5229 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 5230 | option http-tunnel |
| 5231 | no option http-tunnel |
| 5232 | Disable or enable HTTP connection processing after first transaction |
| 5233 | May be used in sections : defaults | frontend | listen | backend |
| 5234 | yes | yes | yes | yes |
| 5235 | Arguments : none |
| 5236 | |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 5237 | By default HAProxy operates in keep-alive mode with regards to persistent |
| 5238 | connections: for each connection it processes each request and response, and |
| 5239 | leaves the connection idle on both sides between the end of a response and |
| 5240 | the start of a new request. This mode may be changed by several options such |
| 5241 | as "option http-server-close", "option forceclose", "option httpclose" or |
| 5242 | "option http-tunnel". |
| 5243 | |
| 5244 | Option "http-tunnel" disables any HTTP processing past the first request and |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 5245 | the first response. This is the mode which was used by default in versions |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 5246 | 1.0 to 1.5-dev21. It is the mode with the lowest processing overhead, which |
| 5247 | is normally not needed anymore unless in very specific cases such as when |
| 5248 | using an in-house protocol that looks like HTTP but is not compatible, or |
| 5249 | just to log one request per client in order to reduce log size. Note that |
| 5250 | everything which works at the HTTP level, including header parsing/addition, |
| 5251 | cookie processing or content switching will only work for the first request |
| 5252 | and will be ignored after the first response. |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 5253 | |
| 5254 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5255 | in a specific instance by prepending the "no" keyword before it. |
| 5256 | |
| 5257 | See also : "option forceclose", "option http-server-close", |
| 5258 | "option httpclose", "option http-keep-alive", and |
| 5259 | "1.1. The HTTP transaction model". |
| 5260 | |
| 5261 | |
Willy Tarreau | 88d349d | 2010-01-25 12:15:43 +0100 | [diff] [blame] | 5262 | option http-use-proxy-header |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 5263 | no option http-use-proxy-header |
Willy Tarreau | 88d349d | 2010-01-25 12:15:43 +0100 | [diff] [blame] | 5264 | Make use of non-standard Proxy-Connection header instead of Connection |
| 5265 | May be used in sections : defaults | frontend | listen | backend |
| 5266 | yes | yes | yes | no |
| 5267 | Arguments : none |
| 5268 | |
| 5269 | While RFC2616 explicitly states that HTTP/1.1 agents must use the |
| 5270 | Connection header to indicate their wish of persistent or non-persistent |
| 5271 | connections, both browsers and proxies ignore this header for proxied |
| 5272 | connections and make use of the undocumented, non-standard Proxy-Connection |
| 5273 | header instead. The issue begins when trying to put a load balancer between |
| 5274 | browsers and such proxies, because there will be a difference between what |
| 5275 | haproxy understands and what the client and the proxy agree on. |
| 5276 | |
| 5277 | By setting this option in a frontend, haproxy can automatically switch to use |
| 5278 | that non-standard header if it sees proxied requests. A proxied request is |
| 5279 | defined here as one where the URI begins with neither a '/' nor a '*'. The |
| 5280 | choice of header only affects requests passing through proxies making use of |
| 5281 | one of the "httpclose", "forceclose" and "http-server-close" options. Note |
| 5282 | that this option can only be specified in a frontend and will affect the |
| 5283 | request along its whole life. |
| 5284 | |
Willy Tarreau | 844a7e7 | 2010-01-31 21:46:18 +0100 | [diff] [blame] | 5285 | Also, when this option is set, a request which requires authentication will |
| 5286 | automatically switch to use proxy authentication headers if it is itself a |
| 5287 | proxied request. That makes it possible to check or enforce authentication in |
| 5288 | front of an existing proxy. |
| 5289 | |
Willy Tarreau | 88d349d | 2010-01-25 12:15:43 +0100 | [diff] [blame] | 5290 | This option should normally never be used, except in front of a proxy. |
| 5291 | |
| 5292 | See also : "option httpclose", "option forceclose" and "option |
| 5293 | http-server-close". |
| 5294 | |
| 5295 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 5296 | option httpchk |
| 5297 | option httpchk <uri> |
| 5298 | option httpchk <method> <uri> |
| 5299 | option httpchk <method> <uri> <version> |
| 5300 | Enable HTTP protocol to check on the servers health |
| 5301 | May be used in sections : defaults | frontend | listen | backend |
| 5302 | yes | no | yes | yes |
| 5303 | Arguments : |
| 5304 | <method> is the optional HTTP method used with the requests. When not set, |
| 5305 | the "OPTIONS" method is used, as it generally requires low server |
| 5306 | processing and is easy to filter out from the logs. Any method |
| 5307 | may be used, though it is not recommended to invent non-standard |
| 5308 | ones. |
| 5309 | |
| 5310 | <uri> is the URI referenced in the HTTP requests. It defaults to " / " |
| 5311 | which is accessible by default on almost any server, but may be |
| 5312 | changed to any other URI. Query strings are permitted. |
| 5313 | |
| 5314 | <version> is the optional HTTP version string. It defaults to "HTTP/1.0" |
| 5315 | but some servers might behave incorrectly in HTTP 1.0, so turning |
| 5316 | it to HTTP/1.1 may sometimes help. Note that the Host field is |
| 5317 | mandatory in HTTP/1.1, and as a trick, it is possible to pass it |
| 5318 | after "\r\n" following the version string. |
| 5319 | |
| 5320 | By default, server health checks only consist in trying to establish a TCP |
| 5321 | connection. When "option httpchk" is specified, a complete HTTP request is |
| 5322 | sent once the TCP connection is established, and responses 2xx and 3xx are |
| 5323 | considered valid, while all other ones indicate a server failure, including |
| 5324 | the lack of any response. |
| 5325 | |
| 5326 | The port and interval are specified in the server configuration. |
| 5327 | |
| 5328 | This option does not necessarily require an HTTP backend, it also works with |
| 5329 | plain TCP backends. This is particularly useful to check simple scripts bound |
| 5330 | to some dedicated ports using the inetd daemon. |
| 5331 | |
| 5332 | Examples : |
| 5333 | # Relay HTTPS traffic to Apache instance and check service availability |
| 5334 | # using HTTP request "OPTIONS * HTTP/1.1" on port 80. |
| 5335 | backend https_relay |
| 5336 | mode tcp |
| 5337 | option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www |
| 5338 | server apache1 192.168.1.1:443 check port 80 |
| 5339 | |
Simon Horman | afc47ee | 2013-11-25 10:46:35 +0900 | [diff] [blame] | 5340 | See also : "option ssl-hello-chk", "option smtpchk", "option mysql-check", |
| 5341 | "option pgsql-check", "http-check" and the "check", "port" and |
| 5342 | "inter" server options. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 5343 | |
| 5344 | |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5345 | option httpclose |
| 5346 | no option httpclose |
| 5347 | Enable or disable passive HTTP connection closing |
| 5348 | May be used in sections : defaults | frontend | listen | backend |
| 5349 | yes | yes | yes | yes |
| 5350 | Arguments : none |
| 5351 | |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 5352 | By default HAProxy operates in keep-alive mode with regards to persistent |
| 5353 | connections: for each connection it processes each request and response, and |
| 5354 | leaves the connection idle on both sides between the end of a response and |
| 5355 | the start of a new request. This mode may be changed by several options such |
Cyril Bonté | 653dcd6 | 2014-02-20 00:13:15 +0100 | [diff] [blame] | 5356 | as "option http-server-close", "option forceclose", "option httpclose" or |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 5357 | "option http-tunnel". |
| 5358 | |
| 5359 | If "option httpclose" is set, HAProxy will work in HTTP tunnel mode and check |
| 5360 | if a "Connection: close" header is already set in each direction, and will |
| 5361 | add one if missing. Each end should react to this by actively closing the TCP |
| 5362 | connection after each transfer, thus resulting in a switch to the HTTP close |
| 5363 | mode. Any "Connection" header different from "close" will also be removed. |
| 5364 | Note that this option is deprecated since what it does is very cheap but not |
| 5365 | reliable. Using "option http-server-close" or "option forceclose" is strongly |
| 5366 | recommended instead. |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5367 | |
| 5368 | It seldom happens that some servers incorrectly ignore this header and do not |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 5369 | close the connection even though they reply "Connection: close". For this |
Willy Tarreau | 0dfdf19 | 2010-01-05 11:33:11 +0100 | [diff] [blame] | 5370 | reason, they are not compatible with older HTTP 1.0 browsers. If this happens |
| 5371 | it is possible to use the "option forceclose" which actively closes the |
| 5372 | request connection once the server responds. Option "forceclose" also |
| 5373 | releases the server connection earlier because it does not have to wait for |
| 5374 | the client to acknowledge it. |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5375 | |
| 5376 | This option may be set both in a frontend and in a backend. It is enabled if |
| 5377 | at least one of the frontend or backend holding a connection has it enabled. |
Cyril Bonté | 653dcd6 | 2014-02-20 00:13:15 +0100 | [diff] [blame] | 5378 | It disables and replaces any previous "option http-server-close", |
| 5379 | "option forceclose", "option http-keep-alive" or "option http-tunnel". Please |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 5380 | check section 4 ("Proxies") to see how this option combines with others when |
| 5381 | frontend and backend options differ. |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5382 | |
| 5383 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5384 | in a specific instance by prepending the "no" keyword before it. |
| 5385 | |
Patrick Mezard | 9ec2ec4 | 2010-06-12 17:02:45 +0200 | [diff] [blame] | 5386 | See also : "option forceclose", "option http-server-close" and |
| 5387 | "1.1. The HTTP transaction model". |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5388 | |
| 5389 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 5390 | option httplog [ clf ] |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5391 | Enable logging of HTTP request, session state and timers |
| 5392 | May be used in sections : defaults | frontend | listen | backend |
| 5393 | yes | yes | yes | yes |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 5394 | Arguments : |
| 5395 | clf if the "clf" argument is added, then the output format will be |
| 5396 | the CLF format instead of HAProxy's default HTTP format. You can |
| 5397 | use this when you need to feed HAProxy's logs through a specific |
| 5398 | log analyser which only support the CLF format and which is not |
| 5399 | extensible. |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5400 | |
| 5401 | By default, the log output format is very poor, as it only contains the |
| 5402 | source and destination addresses, and the instance name. By specifying |
| 5403 | "option httplog", each log line turns into a much richer format including, |
| 5404 | but not limited to, the HTTP request, the connection timers, the session |
| 5405 | status, the connections numbers, the captured headers and cookies, the |
| 5406 | frontend, backend and server name, and of course the source address and |
| 5407 | ports. |
| 5408 | |
| 5409 | This option may be set either in the frontend or the backend. |
| 5410 | |
PiBa-NL | bd556bf | 2014-12-11 21:31:54 +0100 | [diff] [blame] | 5411 | Specifying only "option httplog" will automatically clear the 'clf' mode |
| 5412 | if it was set by default. |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 5413 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 5414 | See also : section 8 about logging. |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5415 | |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 5416 | |
| 5417 | option http_proxy |
| 5418 | no option http_proxy |
| 5419 | Enable or disable plain HTTP proxy mode |
| 5420 | May be used in sections : defaults | frontend | listen | backend |
| 5421 | yes | yes | yes | yes |
| 5422 | Arguments : none |
| 5423 | |
| 5424 | It sometimes happens that people need a pure HTTP proxy which understands |
| 5425 | basic proxy requests without caching nor any fancy feature. In this case, |
| 5426 | it may be worth setting up an HAProxy instance with the "option http_proxy" |
| 5427 | set. In this mode, no server is declared, and the connection is forwarded to |
| 5428 | the IP address and port found in the URL after the "http://" scheme. |
| 5429 | |
| 5430 | No host address resolution is performed, so this only works when pure IP |
| 5431 | addresses are passed. Since this option's usage perimeter is rather limited, |
| 5432 | it will probably be used only by experts who know they need exactly it. Last, |
| 5433 | if the clients are susceptible of sending keep-alive requests, it will be |
Cyril Bonté | 2409e68 | 2010-12-14 22:47:51 +0100 | [diff] [blame] | 5434 | needed to add "option httpclose" to ensure that all requests will correctly |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 5435 | be analyzed. |
| 5436 | |
| 5437 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5438 | in a specific instance by prepending the "no" keyword before it. |
| 5439 | |
| 5440 | Example : |
| 5441 | # this backend understands HTTP proxy requests and forwards them directly. |
| 5442 | backend direct_forward |
| 5443 | option httpclose |
| 5444 | option http_proxy |
| 5445 | |
| 5446 | See also : "option httpclose" |
| 5447 | |
Willy Tarreau | 211ad24 | 2009-10-03 21:45:07 +0200 | [diff] [blame] | 5448 | |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 5449 | option independent-streams |
| 5450 | no option independent-streams |
| 5451 | Enable or disable independent timeout processing for both directions |
Willy Tarreau | f27b5ea | 2009-10-03 22:01:18 +0200 | [diff] [blame] | 5452 | May be used in sections : defaults | frontend | listen | backend |
| 5453 | yes | yes | yes | yes |
| 5454 | Arguments : none |
| 5455 | |
| 5456 | By default, when data is sent over a socket, both the write timeout and the |
| 5457 | read timeout for that socket are refreshed, because we consider that there is |
| 5458 | activity on that socket, and we have no other means of guessing if we should |
| 5459 | receive data or not. |
| 5460 | |
| 5461 | While this default behaviour is desirable for almost all applications, there |
| 5462 | exists a situation where it is desirable to disable it, and only refresh the |
| 5463 | read timeout if there are incoming data. This happens on sessions with large |
| 5464 | timeouts and low amounts of exchanged data such as telnet session. If the |
| 5465 | server suddenly disappears, the output data accumulates in the system's |
| 5466 | socket buffers, both timeouts are correctly refreshed, and there is no way |
| 5467 | to know the server does not receive them, so we don't timeout. However, when |
| 5468 | the underlying protocol always echoes sent data, it would be enough by itself |
| 5469 | to detect the issue using the read timeout. Note that this problem does not |
| 5470 | happen with more verbose protocols because data won't accumulate long in the |
| 5471 | socket buffers. |
| 5472 | |
| 5473 | When this option is set on the frontend, it will disable read timeout updates |
| 5474 | on data sent to the client. There probably is little use of this case. When |
| 5475 | the option is set on the backend, it will disable read timeout updates on |
| 5476 | data sent to the server. Doing so will typically break large HTTP posts from |
| 5477 | slow lines, so use it with caution. |
| 5478 | |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 5479 | Note: older versions used to call this setting "option independent-streams" |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 5480 | with a spelling mistake. This spelling is still supported but |
| 5481 | deprecated. |
| 5482 | |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 5483 | See also : "timeout client", "timeout server" and "timeout tunnel" |
Willy Tarreau | f27b5ea | 2009-10-03 22:01:18 +0200 | [diff] [blame] | 5484 | |
| 5485 | |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5486 | option ldap-check |
| 5487 | Use LDAPv3 health checks for server testing |
| 5488 | May be used in sections : defaults | frontend | listen | backend |
| 5489 | yes | no | yes | yes |
| 5490 | Arguments : none |
| 5491 | |
| 5492 | It is possible to test that the server correctly talks LDAPv3 instead of just |
| 5493 | testing that it accepts the TCP connection. When this option is set, an |
| 5494 | LDAPv3 anonymous simple bind message is sent to the server, and the response |
| 5495 | is analyzed to find an LDAPv3 bind response message. |
| 5496 | |
| 5497 | The server is considered valid only when the LDAP response contains success |
| 5498 | resultCode (http://tools.ietf.org/html/rfc4511#section-4.1.9). |
| 5499 | |
| 5500 | Logging of bind requests is server dependent see your documentation how to |
| 5501 | configure it. |
| 5502 | |
| 5503 | Example : |
| 5504 | option ldap-check |
| 5505 | |
| 5506 | See also : "option httpchk" |
| 5507 | |
| 5508 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5509 | option external-check |
| 5510 | Use external processes for server health checks |
| 5511 | May be used in sections : defaults | frontend | listen | backend |
| 5512 | yes | no | yes | yes |
| 5513 | |
| 5514 | It is possible to test the health of a server using an external command. |
| 5515 | This is achieved by running the executable set using "external-check |
| 5516 | command". |
| 5517 | |
| 5518 | Requires the "external-check" global to be set. |
| 5519 | |
| 5520 | See also : "external-check", "external-check command", "external-check path" |
| 5521 | |
| 5522 | |
Willy Tarreau | 211ad24 | 2009-10-03 21:45:07 +0200 | [diff] [blame] | 5523 | option log-health-checks |
| 5524 | no option log-health-checks |
Willy Tarreau | bef1b32 | 2014-05-13 21:01:39 +0200 | [diff] [blame] | 5525 | Enable or disable logging of health checks status updates |
Willy Tarreau | 211ad24 | 2009-10-03 21:45:07 +0200 | [diff] [blame] | 5526 | May be used in sections : defaults | frontend | listen | backend |
| 5527 | yes | no | yes | yes |
| 5528 | Arguments : none |
| 5529 | |
Willy Tarreau | bef1b32 | 2014-05-13 21:01:39 +0200 | [diff] [blame] | 5530 | By default, failed health check are logged if server is UP and successful |
| 5531 | health checks are logged if server is DOWN, so the amount of additional |
| 5532 | information is limited. |
Willy Tarreau | 211ad24 | 2009-10-03 21:45:07 +0200 | [diff] [blame] | 5533 | |
Willy Tarreau | bef1b32 | 2014-05-13 21:01:39 +0200 | [diff] [blame] | 5534 | When this option is enabled, any change of the health check status or to |
| 5535 | the server's health will be logged, so that it becomes possible to know |
| 5536 | that a server was failing occasional checks before crashing, or exactly when |
| 5537 | it failed to respond a valid HTTP status, then when the port started to |
| 5538 | reject connections, then when the server stopped responding at all. |
| 5539 | |
| 5540 | Note that status changes not caused by health checks (eg: enable/disable on |
| 5541 | the CLI) are intentionally not logged by this option. |
Willy Tarreau | 211ad24 | 2009-10-03 21:45:07 +0200 | [diff] [blame] | 5542 | |
Willy Tarreau | bef1b32 | 2014-05-13 21:01:39 +0200 | [diff] [blame] | 5543 | See also: "option httpchk", "option ldap-check", "option mysql-check", |
| 5544 | "option pgsql-check", "option redis-check", "option smtpchk", |
| 5545 | "option tcp-check", "log" and section 8 about logging. |
Willy Tarreau | 211ad24 | 2009-10-03 21:45:07 +0200 | [diff] [blame] | 5546 | |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 5547 | |
| 5548 | option log-separate-errors |
| 5549 | no option log-separate-errors |
| 5550 | Change log level for non-completely successful connections |
| 5551 | May be used in sections : defaults | frontend | listen | backend |
| 5552 | yes | yes | yes | no |
| 5553 | Arguments : none |
| 5554 | |
| 5555 | Sometimes looking for errors in logs is not easy. This option makes haproxy |
| 5556 | raise the level of logs containing potentially interesting information such |
| 5557 | as errors, timeouts, retries, redispatches, or HTTP status codes 5xx. The |
| 5558 | level changes from "info" to "err". This makes it possible to log them |
| 5559 | separately to a different file with most syslog daemons. Be careful not to |
| 5560 | remove them from the original file, otherwise you would lose ordering which |
| 5561 | provides very important information. |
| 5562 | |
| 5563 | Using this option, large sites dealing with several thousand connections per |
| 5564 | second may log normal traffic to a rotating buffer and only archive smaller |
| 5565 | error logs. |
| 5566 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 5567 | See also : "log", "dontlognull", "dontlog-normal" and section 8 about |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 5568 | logging. |
| 5569 | |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5570 | |
| 5571 | option logasap |
| 5572 | no option logasap |
| 5573 | Enable or disable early logging of HTTP requests |
| 5574 | May be used in sections : defaults | frontend | listen | backend |
| 5575 | yes | yes | yes | no |
| 5576 | Arguments : none |
| 5577 | |
| 5578 | By default, HTTP requests are logged upon termination so that the total |
| 5579 | transfer time and the number of bytes appear in the logs. When large objects |
| 5580 | are being transferred, it may take a while before the request appears in the |
| 5581 | logs. Using "option logasap", the request gets logged as soon as the server |
| 5582 | sends the complete headers. The only missing information in the logs will be |
| 5583 | the total number of bytes which will indicate everything except the amount |
| 5584 | of data transferred, and the total time which will not take the transfer |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 5585 | time into account. In such a situation, it's a good practice to capture the |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5586 | "Content-Length" response header so that the logs at least indicate how many |
| 5587 | bytes are expected to be transferred. |
| 5588 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 5589 | Examples : |
| 5590 | listen http_proxy 0.0.0.0:80 |
| 5591 | mode http |
| 5592 | option httplog |
| 5593 | option logasap |
| 5594 | log 192.168.2.200 local3 |
| 5595 | |
| 5596 | >>> Feb 6 12:14:14 localhost \ |
| 5597 | haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in \ |
| 5598 | static/srv1 9/10/7/14/+30 200 +243 - - ---- 3/1/1/1/0 1/0 \ |
| 5599 | "GET /image.iso HTTP/1.0" |
| 5600 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 5601 | See also : "option httplog", "capture response header", and section 8 about |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 5602 | logging. |
| 5603 | |
| 5604 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5605 | option mysql-check [ user <username> [ post-41 ] ] |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5606 | Use MySQL health checks for server testing |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5607 | May be used in sections : defaults | frontend | listen | backend |
| 5608 | yes | no | yes | yes |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5609 | Arguments : |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 5610 | <username> This is the username which will be used when connecting to MySQL |
| 5611 | server. |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5612 | post-41 Send post v4.1 client compatible checks |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5613 | |
| 5614 | If you specify a username, the check consists of sending two MySQL packet, |
| 5615 | one Client Authentication packet, and one QUIT packet, to correctly close |
| 5616 | MySQL session. We then parse the MySQL Handshake Initialisation packet and/or |
| 5617 | Error packet. It is a basic but useful test which does not produce error nor |
| 5618 | aborted connect on the server. However, it requires adding an authorization |
| 5619 | in the MySQL table, like this : |
| 5620 | |
| 5621 | USE mysql; |
| 5622 | INSERT INTO user (Host,User) values ('<ip_of_haproxy>','<username>'); |
| 5623 | FLUSH PRIVILEGES; |
| 5624 | |
| 5625 | If you don't specify a username (it is deprecated and not recommended), the |
| 5626 | check only consists in parsing the Mysql Handshake Initialisation packet or |
| 5627 | Error packet, we don't send anything in this mode. It was reported that it |
| 5628 | can generate lockout if check is too frequent and/or if there is not enough |
| 5629 | traffic. In fact, you need in this case to check MySQL "max_connect_errors" |
| 5630 | value as if a connection is established successfully within fewer than MySQL |
| 5631 | "max_connect_errors" attempts after a previous connection was interrupted, |
| 5632 | the error count for the host is cleared to zero. If HAProxy's server get |
| 5633 | blocked, the "FLUSH HOSTS" statement is the only way to unblock it. |
| 5634 | |
| 5635 | Remember that this does not check database presence nor database consistency. |
| 5636 | To do this, you can use an external check with xinetd for example. |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5637 | |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 5638 | The check requires MySQL >=3.22, for older version, please use TCP check. |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5639 | |
| 5640 | Most often, an incoming MySQL server needs to see the client's IP address for |
| 5641 | various purposes, including IP privilege matching and connection logging. |
| 5642 | When possible, it is often wise to masquerade the client's IP address when |
| 5643 | connecting to the server using the "usesrc" argument of the "source" keyword, |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 5644 | which requires the transparent proxy feature to be compiled in, and the MySQL |
| 5645 | server to route the client via the machine hosting haproxy. |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5646 | |
| 5647 | See also: "option httpchk" |
| 5648 | |
| 5649 | |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 5650 | option nolinger |
| 5651 | no option nolinger |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 5652 | Enable or disable immediate session resource cleaning after close |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 5653 | May be used in sections: defaults | frontend | listen | backend |
| 5654 | yes | yes | yes | yes |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 5655 | Arguments : none |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 5656 | |
| 5657 | When clients or servers abort connections in a dirty way (eg: they are |
| 5658 | physically disconnected), the session timeouts triggers and the session is |
| 5659 | closed. But it will remain in FIN_WAIT1 state for some time in the system, |
| 5660 | using some resources and possibly limiting the ability to establish newer |
| 5661 | connections. |
| 5662 | |
| 5663 | When this happens, it is possible to activate "option nolinger" which forces |
| 5664 | the system to immediately remove any socket's pending data on close. Thus, |
| 5665 | the session is instantly purged from the system's tables. This usually has |
| 5666 | side effects such as increased number of TCP resets due to old retransmits |
| 5667 | getting immediately rejected. Some firewalls may sometimes complain about |
| 5668 | this too. |
| 5669 | |
| 5670 | For this reason, it is not recommended to use this option when not absolutely |
| 5671 | needed. You know that you need it when you have thousands of FIN_WAIT1 |
| 5672 | sessions on your system (TIME_WAIT ones do not count). |
| 5673 | |
| 5674 | This option may be used both on frontends and backends, depending on the side |
| 5675 | where it is required. Use it on the frontend for clients, and on the backend |
| 5676 | for servers. |
| 5677 | |
| 5678 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5679 | in a specific instance by prepending the "no" keyword before it. |
| 5680 | |
| 5681 | |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 5682 | option originalto [ except <network> ] [ header <name> ] |
| 5683 | Enable insertion of the X-Original-To header to requests sent to servers |
| 5684 | May be used in sections : defaults | frontend | listen | backend |
| 5685 | yes | yes | yes | yes |
| 5686 | Arguments : |
| 5687 | <network> is an optional argument used to disable this option for sources |
| 5688 | matching <network> |
| 5689 | <name> an optional argument to specify a different "X-Original-To" |
| 5690 | header name. |
| 5691 | |
| 5692 | Since HAProxy can work in transparent mode, every request from a client can |
| 5693 | be redirected to the proxy and HAProxy itself can proxy every request to a |
| 5694 | complex SQUID environment and the destination host from SO_ORIGINAL_DST will |
| 5695 | be lost. This is annoying when you want access rules based on destination ip |
| 5696 | addresses. To solve this problem, a new HTTP header "X-Original-To" may be |
| 5697 | added by HAProxy to all requests sent to the server. This header contains a |
| 5698 | value representing the original destination IP address. Since this must be |
| 5699 | configured to always use the last occurrence of this header only. Note that |
| 5700 | only the last occurrence of the header must be used, since it is really |
| 5701 | possible that the client has already brought one. |
| 5702 | |
| 5703 | The keyword "header" may be used to supply a different header name to replace |
| 5704 | the default "X-Original-To". This can be useful where you might already |
| 5705 | have a "X-Original-To" header from a different application, and you need |
| 5706 | preserve it. Also if your backend server doesn't use the "X-Original-To" |
| 5707 | header and requires different one. |
| 5708 | |
| 5709 | Sometimes, a same HAProxy instance may be shared between a direct client |
| 5710 | access and a reverse-proxy access (for instance when an SSL reverse-proxy is |
| 5711 | used to decrypt HTTPS traffic). It is possible to disable the addition of the |
| 5712 | header for a known source address or network by adding the "except" keyword |
| 5713 | followed by the network address. In this case, any source IP matching the |
| 5714 | network will not cause an addition of this header. Most common uses are with |
| 5715 | private networks or 127.0.0.1. |
| 5716 | |
| 5717 | This option may be specified either in the frontend or in the backend. If at |
| 5718 | least one of them uses it, the header will be added. Note that the backend's |
| 5719 | setting of the header subargument takes precedence over the frontend's if |
| 5720 | both are defined. |
| 5721 | |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 5722 | Examples : |
| 5723 | # Original Destination address |
| 5724 | frontend www |
| 5725 | mode http |
| 5726 | option originalto except 127.0.0.1 |
| 5727 | |
| 5728 | # Those servers want the IP Address in X-Client-Dst |
| 5729 | backend www |
| 5730 | mode http |
| 5731 | option originalto header X-Client-Dst |
| 5732 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5733 | See also : "option httpclose", "option http-server-close", |
| 5734 | "option forceclose" |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 5735 | |
| 5736 | |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 5737 | option persist |
| 5738 | no option persist |
| 5739 | Enable or disable forced persistence on down servers |
| 5740 | May be used in sections: defaults | frontend | listen | backend |
| 5741 | yes | no | yes | yes |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 5742 | Arguments : none |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 5743 | |
| 5744 | When an HTTP request reaches a backend with a cookie which references a dead |
| 5745 | server, by default it is redispatched to another server. It is possible to |
| 5746 | force the request to be sent to the dead server first using "option persist" |
| 5747 | if absolutely needed. A common use case is when servers are under extreme |
| 5748 | load and spend their time flapping. In this case, the users would still be |
| 5749 | directed to the server they opened the session on, in the hope they would be |
| 5750 | correctly served. It is recommended to use "option redispatch" in conjunction |
| 5751 | with this option so that in the event it would not be possible to connect to |
| 5752 | the server at all (server definitely dead), the client would finally be |
| 5753 | redirected to another valid server. |
| 5754 | |
| 5755 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5756 | in a specific instance by prepending the "no" keyword before it. |
| 5757 | |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 5758 | See also : "option redispatch", "retries", "force-persist" |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 5759 | |
| 5760 | |
Willy Tarreau | 0c12282 | 2013-12-15 18:49:01 +0100 | [diff] [blame] | 5761 | option pgsql-check [ user <username> ] |
| 5762 | Use PostgreSQL health checks for server testing |
| 5763 | May be used in sections : defaults | frontend | listen | backend |
| 5764 | yes | no | yes | yes |
| 5765 | Arguments : |
| 5766 | <username> This is the username which will be used when connecting to |
| 5767 | PostgreSQL server. |
| 5768 | |
| 5769 | The check sends a PostgreSQL StartupMessage and waits for either |
| 5770 | Authentication request or ErrorResponse message. It is a basic but useful |
| 5771 | test which does not produce error nor aborted connect on the server. |
| 5772 | This check is identical with the "mysql-check". |
| 5773 | |
| 5774 | See also: "option httpchk" |
| 5775 | |
| 5776 | |
Willy Tarreau | 9420b12 | 2013-12-15 18:58:25 +0100 | [diff] [blame] | 5777 | option prefer-last-server |
| 5778 | no option prefer-last-server |
| 5779 | Allow multiple load balanced requests to remain on the same server |
| 5780 | May be used in sections: defaults | frontend | listen | backend |
| 5781 | yes | no | yes | yes |
| 5782 | Arguments : none |
| 5783 | |
| 5784 | When the load balancing algorithm in use is not deterministic, and a previous |
| 5785 | request was sent to a server to which haproxy still holds a connection, it is |
| 5786 | sometimes desirable that subsequent requests on a same session go to the same |
| 5787 | server as much as possible. Note that this is different from persistence, as |
| 5788 | we only indicate a preference which haproxy tries to apply without any form |
| 5789 | of warranty. The real use is for keep-alive connections sent to servers. When |
| 5790 | this option is used, haproxy will try to reuse the same connection that is |
| 5791 | attached to the server instead of rebalancing to another server, causing a |
| 5792 | close of the connection. This can make sense for static file servers. It does |
Willy Tarreau | 068621e | 2013-12-23 15:11:25 +0100 | [diff] [blame] | 5793 | not make much sense to use this in combination with hashing algorithms. Note, |
| 5794 | haproxy already automatically tries to stick to a server which sends a 401 or |
| 5795 | to a proxy which sends a 407 (authentication required). This is mandatory for |
| 5796 | use with the broken NTLM authentication challenge, and significantly helps in |
| 5797 | troubleshooting some faulty applications. Option prefer-last-server might be |
| 5798 | desirable in these environments as well, to avoid redistributing the traffic |
| 5799 | after every other response. |
Willy Tarreau | 9420b12 | 2013-12-15 18:58:25 +0100 | [diff] [blame] | 5800 | |
| 5801 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5802 | in a specific instance by prepending the "no" keyword before it. |
| 5803 | |
| 5804 | See also: "option http-keep-alive" |
| 5805 | |
| 5806 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 5807 | option redispatch |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 5808 | option redispatch <interval> |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 5809 | no option redispatch |
| 5810 | Enable or disable session redistribution in case of connection failure |
| 5811 | May be used in sections: defaults | frontend | listen | backend |
| 5812 | yes | no | yes | yes |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 5813 | Arguments : |
| 5814 | <interval> The optional integer value that controls how often redispatches |
| 5815 | occur when retrying connections. Positive value P indicates a |
| 5816 | redispatch is desired on every Pth retry, and negative value |
| 5817 | N indicate a redispath is desired on the Nth retry prior to the |
| 5818 | last retry. For example, the default of -1 preserves the |
| 5819 | historical behaviour of redispatching on the last retry, a |
| 5820 | positive value of 1 would indicate a redispatch on every retry, |
| 5821 | and a positive value of 3 would indicate a redispatch on every |
| 5822 | third retry. You can disable redispatches with a value of 0. |
| 5823 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 5824 | |
| 5825 | In HTTP mode, if a server designated by a cookie is down, clients may |
| 5826 | definitely stick to it because they cannot flush the cookie, so they will not |
| 5827 | be able to access the service anymore. |
| 5828 | |
| 5829 | Specifying "option redispatch" will allow the proxy to break their |
| 5830 | persistence and redistribute them to a working server. |
| 5831 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 5832 | It also allows to retry connections to another server in case of multiple |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 5833 | connection failures. Of course, it requires having "retries" set to a nonzero |
| 5834 | value. |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 5835 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 5836 | This form is the preferred form, which replaces both the "redispatch" and |
| 5837 | "redisp" keywords. |
| 5838 | |
| 5839 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5840 | in a specific instance by prepending the "no" keyword before it. |
| 5841 | |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 5842 | See also : "redispatch", "retries", "force-persist" |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 5843 | |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 5844 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5845 | option redis-check |
| 5846 | Use redis health checks for server testing |
| 5847 | May be used in sections : defaults | frontend | listen | backend |
| 5848 | yes | no | yes | yes |
| 5849 | Arguments : none |
| 5850 | |
| 5851 | It is possible to test that the server correctly talks REDIS protocol instead |
| 5852 | of just testing that it accepts the TCP connection. When this option is set, |
| 5853 | a PING redis command is sent to the server, and the response is analyzed to |
| 5854 | find the "+PONG" response message. |
| 5855 | |
| 5856 | Example : |
| 5857 | option redis-check |
| 5858 | |
| 5859 | See also : "option httpchk" |
| 5860 | |
| 5861 | |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 5862 | option smtpchk |
| 5863 | option smtpchk <hello> <domain> |
| 5864 | Use SMTP health checks for server testing |
| 5865 | May be used in sections : defaults | frontend | listen | backend |
| 5866 | yes | no | yes | yes |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 5867 | Arguments : |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 5868 | <hello> is an optional argument. It is the "hello" command to use. It can |
| 5869 | be either "HELO" (for SMTP) or "EHLO" (for ESTMP). All other |
| 5870 | values will be turned into the default command ("HELO"). |
| 5871 | |
| 5872 | <domain> is the domain name to present to the server. It may only be |
| 5873 | specified (and is mandatory) if the hello command has been |
| 5874 | specified. By default, "localhost" is used. |
| 5875 | |
| 5876 | When "option smtpchk" is set, the health checks will consist in TCP |
| 5877 | connections followed by an SMTP command. By default, this command is |
| 5878 | "HELO localhost". The server's return code is analyzed and only return codes |
| 5879 | starting with a "2" will be considered as valid. All other responses, |
| 5880 | including a lack of response will constitute an error and will indicate a |
| 5881 | dead server. |
| 5882 | |
| 5883 | This test is meant to be used with SMTP servers or relays. Depending on the |
| 5884 | request, it is possible that some servers do not log each connection attempt, |
| 5885 | so you may want to experiment to improve the behaviour. Using telnet on port |
| 5886 | 25 is often easier than adjusting the configuration. |
| 5887 | |
| 5888 | Most often, an incoming SMTP server needs to see the client's IP address for |
| 5889 | various purposes, including spam filtering, anti-spoofing and logging. When |
| 5890 | possible, it is often wise to masquerade the client's IP address when |
| 5891 | connecting to the server using the "usesrc" argument of the "source" keyword, |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 5892 | which requires the transparent proxy feature to be compiled in. |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 5893 | |
| 5894 | Example : |
| 5895 | option smtpchk HELO mydomain.org |
| 5896 | |
| 5897 | See also : "option httpchk", "source" |
| 5898 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 5899 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 5900 | option socket-stats |
| 5901 | no option socket-stats |
| 5902 | |
| 5903 | Enable or disable collecting & providing separate statistics for each socket. |
| 5904 | May be used in sections : defaults | frontend | listen | backend |
| 5905 | yes | yes | yes | no |
| 5906 | |
| 5907 | Arguments : none |
| 5908 | |
| 5909 | |
Willy Tarreau | ff4f82d | 2009-02-06 11:28:13 +0100 | [diff] [blame] | 5910 | option splice-auto |
| 5911 | no option splice-auto |
| 5912 | Enable or disable automatic kernel acceleration on sockets in both directions |
| 5913 | May be used in sections : defaults | frontend | listen | backend |
| 5914 | yes | yes | yes | yes |
| 5915 | Arguments : none |
| 5916 | |
| 5917 | When this option is enabled either on a frontend or on a backend, haproxy |
| 5918 | will automatically evaluate the opportunity to use kernel tcp splicing to |
| 5919 | forward data between the client and the server, in either direction. Haproxy |
| 5920 | uses heuristics to estimate if kernel splicing might improve performance or |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 5921 | not. Both directions are handled independently. Note that the heuristics used |
Willy Tarreau | ff4f82d | 2009-02-06 11:28:13 +0100 | [diff] [blame] | 5922 | are not much aggressive in order to limit excessive use of splicing. This |
| 5923 | option requires splicing to be enabled at compile time, and may be globally |
| 5924 | disabled with the global option "nosplice". Since splice uses pipes, using it |
| 5925 | requires that there are enough spare pipes. |
| 5926 | |
| 5927 | Important note: kernel-based TCP splicing is a Linux-specific feature which |
| 5928 | first appeared in kernel 2.6.25. It offers kernel-based acceleration to |
| 5929 | transfer data between sockets without copying these data to user-space, thus |
| 5930 | providing noticeable performance gains and CPU cycles savings. Since many |
| 5931 | early implementations are buggy, corrupt data and/or are inefficient, this |
| 5932 | feature is not enabled by default, and it should be used with extreme care. |
| 5933 | While it is not possible to detect the correctness of an implementation, |
| 5934 | 2.6.29 is the first version offering a properly working implementation. In |
| 5935 | case of doubt, splicing may be globally disabled using the global "nosplice" |
| 5936 | keyword. |
| 5937 | |
| 5938 | Example : |
| 5939 | option splice-auto |
| 5940 | |
| 5941 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5942 | in a specific instance by prepending the "no" keyword before it. |
| 5943 | |
| 5944 | See also : "option splice-request", "option splice-response", and global |
| 5945 | options "nosplice" and "maxpipes" |
| 5946 | |
| 5947 | |
| 5948 | option splice-request |
| 5949 | no option splice-request |
| 5950 | Enable or disable automatic kernel acceleration on sockets for requests |
| 5951 | May be used in sections : defaults | frontend | listen | backend |
| 5952 | yes | yes | yes | yes |
| 5953 | Arguments : none |
| 5954 | |
| 5955 | When this option is enabled either on a frontend or on a backend, haproxy |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 5956 | will use kernel tcp splicing whenever possible to forward data going from |
Willy Tarreau | ff4f82d | 2009-02-06 11:28:13 +0100 | [diff] [blame] | 5957 | the client to the server. It might still use the recv/send scheme if there |
| 5958 | are no spare pipes left. This option requires splicing to be enabled at |
| 5959 | compile time, and may be globally disabled with the global option "nosplice". |
| 5960 | Since splice uses pipes, using it requires that there are enough spare pipes. |
| 5961 | |
| 5962 | Important note: see "option splice-auto" for usage limitations. |
| 5963 | |
| 5964 | Example : |
| 5965 | option splice-request |
| 5966 | |
| 5967 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5968 | in a specific instance by prepending the "no" keyword before it. |
| 5969 | |
| 5970 | See also : "option splice-auto", "option splice-response", and global options |
| 5971 | "nosplice" and "maxpipes" |
| 5972 | |
| 5973 | |
| 5974 | option splice-response |
| 5975 | no option splice-response |
| 5976 | Enable or disable automatic kernel acceleration on sockets for responses |
| 5977 | May be used in sections : defaults | frontend | listen | backend |
| 5978 | yes | yes | yes | yes |
| 5979 | Arguments : none |
| 5980 | |
| 5981 | When this option is enabled either on a frontend or on a backend, haproxy |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 5982 | will use kernel tcp splicing whenever possible to forward data going from |
Willy Tarreau | ff4f82d | 2009-02-06 11:28:13 +0100 | [diff] [blame] | 5983 | the server to the client. It might still use the recv/send scheme if there |
| 5984 | are no spare pipes left. This option requires splicing to be enabled at |
| 5985 | compile time, and may be globally disabled with the global option "nosplice". |
| 5986 | Since splice uses pipes, using it requires that there are enough spare pipes. |
| 5987 | |
| 5988 | Important note: see "option splice-auto" for usage limitations. |
| 5989 | |
| 5990 | Example : |
| 5991 | option splice-response |
| 5992 | |
| 5993 | If this option has been enabled in a "defaults" section, it can be disabled |
| 5994 | in a specific instance by prepending the "no" keyword before it. |
| 5995 | |
| 5996 | See also : "option splice-auto", "option splice-request", and global options |
| 5997 | "nosplice" and "maxpipes" |
| 5998 | |
| 5999 | |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 6000 | option srvtcpka |
| 6001 | no option srvtcpka |
| 6002 | Enable or disable the sending of TCP keepalive packets on the server side |
| 6003 | May be used in sections : defaults | frontend | listen | backend |
| 6004 | yes | no | yes | yes |
| 6005 | Arguments : none |
| 6006 | |
| 6007 | When there is a firewall or any session-aware component between a client and |
| 6008 | a server, and when the protocol involves very long sessions with long idle |
| 6009 | periods (eg: remote desktops), there is a risk that one of the intermediate |
| 6010 | components decides to expire a session which has remained idle for too long. |
| 6011 | |
| 6012 | Enabling socket-level TCP keep-alives makes the system regularly send packets |
| 6013 | to the other end of the connection, leaving it active. The delay between |
| 6014 | keep-alive probes is controlled by the system only and depends both on the |
| 6015 | operating system and its tuning parameters. |
| 6016 | |
| 6017 | It is important to understand that keep-alive packets are neither emitted nor |
| 6018 | received at the application level. It is only the network stacks which sees |
| 6019 | them. For this reason, even if one side of the proxy already uses keep-alives |
| 6020 | to maintain its connection alive, those keep-alive packets will not be |
| 6021 | forwarded to the other side of the proxy. |
| 6022 | |
| 6023 | Please note that this has nothing to do with HTTP keep-alive. |
| 6024 | |
| 6025 | Using option "srvtcpka" enables the emission of TCP keep-alive probes on the |
| 6026 | server side of a connection, which should help when session expirations are |
| 6027 | noticed between HAProxy and a server. |
| 6028 | |
| 6029 | If this option has been enabled in a "defaults" section, it can be disabled |
| 6030 | in a specific instance by prepending the "no" keyword before it. |
| 6031 | |
| 6032 | See also : "option clitcpka", "option tcpka" |
| 6033 | |
| 6034 | |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 6035 | option ssl-hello-chk |
| 6036 | Use SSLv3 client hello health checks for server testing |
| 6037 | May be used in sections : defaults | frontend | listen | backend |
| 6038 | yes | no | yes | yes |
| 6039 | Arguments : none |
| 6040 | |
| 6041 | When some SSL-based protocols are relayed in TCP mode through HAProxy, it is |
| 6042 | possible to test that the server correctly talks SSL instead of just testing |
| 6043 | that it accepts the TCP connection. When "option ssl-hello-chk" is set, pure |
| 6044 | SSLv3 client hello messages are sent once the connection is established to |
| 6045 | the server, and the response is analyzed to find an SSL server hello message. |
| 6046 | The server is considered valid only when the response contains this server |
| 6047 | hello message. |
| 6048 | |
| 6049 | All servers tested till there correctly reply to SSLv3 client hello messages, |
| 6050 | and most servers tested do not even log the requests containing only hello |
| 6051 | messages, which is appreciable. |
| 6052 | |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 6053 | Note that this check works even when SSL support was not built into haproxy |
| 6054 | because it forges the SSL message. When SSL support is available, it is best |
| 6055 | to use native SSL health checks instead of this one. |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 6056 | |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 6057 | See also: "option httpchk", "check-ssl" |
| 6058 | |
Willy Tarreau | a453bdd | 2008-01-08 19:50:52 +0100 | [diff] [blame] | 6059 | |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6060 | option tcp-check |
| 6061 | Perform health checks using tcp-check send/expect sequences |
| 6062 | May be used in sections: defaults | frontend | listen | backend |
| 6063 | yes | no | yes | yes |
| 6064 | |
| 6065 | This health check method is intended to be combined with "tcp-check" command |
| 6066 | lists in order to support send/expect types of health check sequences. |
| 6067 | |
| 6068 | TCP checks currently support 4 modes of operations : |
| 6069 | - no "tcp-check" directive : the health check only consists in a connection |
| 6070 | attempt, which remains the default mode. |
| 6071 | |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 6072 | - "tcp-check send" or "tcp-check send-binary" only is mentioned : this is |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6073 | used to send a string along with a connection opening. With some |
| 6074 | protocols, it helps sending a "QUIT" message for example that prevents |
| 6075 | the server from logging a connection error for each health check. The |
| 6076 | check result will still be based on the ability to open the connection |
| 6077 | only. |
| 6078 | |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 6079 | - "tcp-check expect" only is mentioned : this is used to test a banner. |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6080 | The connection is opened and haproxy waits for the server to present some |
| 6081 | contents which must validate some rules. The check result will be based |
| 6082 | on the matching between the contents and the rules. This is suited for |
| 6083 | POP, IMAP, SMTP, FTP, SSH, TELNET. |
| 6084 | |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 6085 | - both "tcp-check send" and "tcp-check expect" are mentioned : this is |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6086 | used to test a hello-type protocol. Haproxy sends a message, the server |
| 6087 | responds and its response is analysed. the check result will be based on |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 6088 | the matching between the response contents and the rules. This is often |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6089 | suited for protocols which require a binding or a request/response model. |
| 6090 | LDAP, MySQL, Redis and SSL are example of such protocols, though they |
| 6091 | already all have their dedicated checks with a deeper understanding of |
| 6092 | the respective protocols. |
| 6093 | In this mode, many questions may be sent and many answers may be |
| 6094 | analysed. |
| 6095 | |
Baptiste Assmann | d60a9e5 | 2015-04-25 16:27:23 +0200 | [diff] [blame] | 6096 | A fifth mode can be used to insert comments in different steps of the |
| 6097 | script. |
| 6098 | |
| 6099 | For each tcp-check rule you create, you can add a "comment" directive, |
| 6100 | followed by a string. This string will be reported in the log and stderr |
| 6101 | in debug mode. It is useful to make user-friendly error reporting. |
| 6102 | The "comment" is of course optional. |
| 6103 | |
| 6104 | |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6105 | Examples : |
| 6106 | # perform a POP check (analyse only server's banner) |
| 6107 | option tcp-check |
Baptiste Assmann | d60a9e5 | 2015-04-25 16:27:23 +0200 | [diff] [blame] | 6108 | tcp-check expect string +OK\ POP3\ ready comment POP\ protocol |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6109 | |
| 6110 | # perform an IMAP check (analyse only server's banner) |
| 6111 | option tcp-check |
Baptiste Assmann | d60a9e5 | 2015-04-25 16:27:23 +0200 | [diff] [blame] | 6112 | tcp-check expect string *\ OK\ IMAP4\ ready comment IMAP\ protocol |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6113 | |
| 6114 | # look for the redis master server after ensuring it speaks well |
| 6115 | # redis protocol, then it exits properly. |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 6116 | # (send a command then analyse the response 3 times) |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6117 | option tcp-check |
Baptiste Assmann | d60a9e5 | 2015-04-25 16:27:23 +0200 | [diff] [blame] | 6118 | tcp-check comment PING\ phase |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6119 | tcp-check send PING\r\n |
Baptiste Assmann | a332299 | 2015-08-04 10:12:18 +0200 | [diff] [blame] | 6120 | tcp-check expect string +PONG |
Baptiste Assmann | d60a9e5 | 2015-04-25 16:27:23 +0200 | [diff] [blame] | 6121 | tcp-check comment role\ check |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6122 | tcp-check send info\ replication\r\n |
| 6123 | tcp-check expect string role:master |
Baptiste Assmann | d60a9e5 | 2015-04-25 16:27:23 +0200 | [diff] [blame] | 6124 | tcp-check comment QUIT\ phase |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6125 | tcp-check send QUIT\r\n |
| 6126 | tcp-check expect string +OK |
| 6127 | |
| 6128 | forge a HTTP request, then analyse the response |
| 6129 | (send many headers before analyzing) |
| 6130 | option tcp-check |
Baptiste Assmann | d60a9e5 | 2015-04-25 16:27:23 +0200 | [diff] [blame] | 6131 | tcp-check comment forge\ and\ send\ HTTP\ request |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6132 | tcp-check send HEAD\ /\ HTTP/1.1\r\n |
| 6133 | tcp-check send Host:\ www.mydomain.com\r\n |
| 6134 | tcp-check send User-Agent:\ HAProxy\ tcpcheck\r\n |
| 6135 | tcp-check send \r\n |
Baptiste Assmann | d60a9e5 | 2015-04-25 16:27:23 +0200 | [diff] [blame] | 6136 | tcp-check expect rstring HTTP/1\..\ (2..|3..) comment check\ HTTP\ response |
Willy Tarreau | ed17985 | 2013-12-16 01:07:00 +0100 | [diff] [blame] | 6137 | |
| 6138 | |
| 6139 | See also : "tcp-check expect", "tcp-check send" |
| 6140 | |
| 6141 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6142 | option tcp-smart-accept |
| 6143 | no option tcp-smart-accept |
| 6144 | Enable or disable the saving of one ACK packet during the accept sequence |
| 6145 | May be used in sections : defaults | frontend | listen | backend |
| 6146 | yes | yes | yes | no |
| 6147 | Arguments : none |
| 6148 | |
| 6149 | When an HTTP connection request comes in, the system acknowledges it on |
| 6150 | behalf of HAProxy, then the client immediately sends its request, and the |
| 6151 | system acknowledges it too while it is notifying HAProxy about the new |
| 6152 | connection. HAProxy then reads the request and responds. This means that we |
| 6153 | have one TCP ACK sent by the system for nothing, because the request could |
| 6154 | very well be acknowledged by HAProxy when it sends its response. |
| 6155 | |
| 6156 | For this reason, in HTTP mode, HAProxy automatically asks the system to avoid |
| 6157 | sending this useless ACK on platforms which support it (currently at least |
| 6158 | Linux). It must not cause any problem, because the system will send it anyway |
| 6159 | after 40 ms if the response takes more time than expected to come. |
| 6160 | |
| 6161 | During complex network debugging sessions, it may be desirable to disable |
| 6162 | this optimization because delayed ACKs can make troubleshooting more complex |
| 6163 | when trying to identify where packets are delayed. It is then possible to |
| 6164 | fall back to normal behaviour by specifying "no option tcp-smart-accept". |
| 6165 | |
| 6166 | It is also possible to force it for non-HTTP proxies by simply specifying |
| 6167 | "option tcp-smart-accept". For instance, it can make sense with some services |
| 6168 | such as SMTP where the server speaks first. |
| 6169 | |
| 6170 | It is recommended to avoid forcing this option in a defaults section. In case |
| 6171 | of doubt, consider setting it back to automatic values by prepending the |
| 6172 | "default" keyword before it, or disabling it using the "no" keyword. |
| 6173 | |
Willy Tarreau | d88edf2 | 2009-06-14 15:48:17 +0200 | [diff] [blame] | 6174 | See also : "option tcp-smart-connect" |
| 6175 | |
| 6176 | |
| 6177 | option tcp-smart-connect |
| 6178 | no option tcp-smart-connect |
| 6179 | Enable or disable the saving of one ACK packet during the connect sequence |
| 6180 | May be used in sections : defaults | frontend | listen | backend |
| 6181 | yes | no | yes | yes |
| 6182 | Arguments : none |
| 6183 | |
| 6184 | On certain systems (at least Linux), HAProxy can ask the kernel not to |
| 6185 | immediately send an empty ACK upon a connection request, but to directly |
| 6186 | send the buffer request instead. This saves one packet on the network and |
| 6187 | thus boosts performance. It can also be useful for some servers, because they |
| 6188 | immediately get the request along with the incoming connection. |
| 6189 | |
| 6190 | This feature is enabled when "option tcp-smart-connect" is set in a backend. |
| 6191 | It is not enabled by default because it makes network troubleshooting more |
| 6192 | complex. |
| 6193 | |
| 6194 | It only makes sense to enable it with protocols where the client speaks first |
| 6195 | such as HTTP. In other situations, if there is no data to send in place of |
| 6196 | the ACK, a normal ACK is sent. |
| 6197 | |
| 6198 | If this option has been enabled in a "defaults" section, it can be disabled |
| 6199 | in a specific instance by prepending the "no" keyword before it. |
| 6200 | |
| 6201 | See also : "option tcp-smart-accept" |
| 6202 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6203 | |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 6204 | option tcpka |
| 6205 | Enable or disable the sending of TCP keepalive packets on both sides |
| 6206 | May be used in sections : defaults | frontend | listen | backend |
| 6207 | yes | yes | yes | yes |
| 6208 | Arguments : none |
| 6209 | |
| 6210 | When there is a firewall or any session-aware component between a client and |
| 6211 | a server, and when the protocol involves very long sessions with long idle |
| 6212 | periods (eg: remote desktops), there is a risk that one of the intermediate |
| 6213 | components decides to expire a session which has remained idle for too long. |
| 6214 | |
| 6215 | Enabling socket-level TCP keep-alives makes the system regularly send packets |
| 6216 | to the other end of the connection, leaving it active. The delay between |
| 6217 | keep-alive probes is controlled by the system only and depends both on the |
| 6218 | operating system and its tuning parameters. |
| 6219 | |
| 6220 | It is important to understand that keep-alive packets are neither emitted nor |
| 6221 | received at the application level. It is only the network stacks which sees |
| 6222 | them. For this reason, even if one side of the proxy already uses keep-alives |
| 6223 | to maintain its connection alive, those keep-alive packets will not be |
| 6224 | forwarded to the other side of the proxy. |
| 6225 | |
| 6226 | Please note that this has nothing to do with HTTP keep-alive. |
| 6227 | |
| 6228 | Using option "tcpka" enables the emission of TCP keep-alive probes on both |
| 6229 | the client and server sides of a connection. Note that this is meaningful |
| 6230 | only in "defaults" or "listen" sections. If this option is used in a |
| 6231 | frontend, only the client side will get keep-alives, and if this option is |
| 6232 | used in a backend, only the server side will get keep-alives. For this |
| 6233 | reason, it is strongly recommended to explicitly use "option clitcpka" and |
| 6234 | "option srvtcpka" when the configuration is split between frontends and |
| 6235 | backends. |
| 6236 | |
| 6237 | See also : "option clitcpka", "option srvtcpka" |
| 6238 | |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 6239 | |
| 6240 | option tcplog |
| 6241 | Enable advanced logging of TCP connections with session state and timers |
| 6242 | May be used in sections : defaults | frontend | listen | backend |
| 6243 | yes | yes | yes | yes |
| 6244 | Arguments : none |
| 6245 | |
| 6246 | By default, the log output format is very poor, as it only contains the |
| 6247 | source and destination addresses, and the instance name. By specifying |
| 6248 | "option tcplog", each log line turns into a much richer format including, but |
| 6249 | not limited to, the connection timers, the session status, the connections |
| 6250 | numbers, the frontend, backend and server name, and of course the source |
| 6251 | address and ports. This option is useful for pure TCP proxies in order to |
| 6252 | find which of the client or server disconnects or times out. For normal HTTP |
| 6253 | proxies, it's better to use "option httplog" which is even more complete. |
| 6254 | |
| 6255 | This option may be set either in the frontend or the backend. |
| 6256 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 6257 | See also : "option httplog", and section 8 about logging. |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 6258 | |
| 6259 | |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 6260 | option transparent |
| 6261 | no option transparent |
| 6262 | Enable client-side transparent proxying |
| 6263 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | 4b1f859 | 2008-12-23 23:13:55 +0100 | [diff] [blame] | 6264 | yes | no | yes | yes |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 6265 | Arguments : none |
| 6266 | |
| 6267 | This option was introduced in order to provide layer 7 persistence to layer 3 |
| 6268 | load balancers. The idea is to use the OS's ability to redirect an incoming |
| 6269 | connection for a remote address to a local process (here HAProxy), and let |
| 6270 | this process know what address was initially requested. When this option is |
| 6271 | used, sessions without cookies will be forwarded to the original destination |
| 6272 | IP address of the incoming request (which should match that of another |
| 6273 | equipment), while requests with cookies will still be forwarded to the |
| 6274 | appropriate server. |
| 6275 | |
| 6276 | Note that contrary to a common belief, this option does NOT make HAProxy |
| 6277 | present the client's IP to the server when establishing the connection. |
| 6278 | |
Willy Tarreau | a114605 | 2011-03-01 09:51:54 +0100 | [diff] [blame] | 6279 | See also: the "usesrc" argument of the "source" keyword, and the |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 6280 | "transparent" option of the "bind" keyword. |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 6281 | |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 6282 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 6283 | external-check command <command> |
| 6284 | Executable to run when performing an external-check |
| 6285 | May be used in sections : defaults | frontend | listen | backend |
| 6286 | yes | no | yes | yes |
| 6287 | |
| 6288 | Arguments : |
| 6289 | <command> is the external command to run |
| 6290 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 6291 | The arguments passed to the to the command are: |
| 6292 | |
Cyril Bonté | 777be86 | 2014-12-02 21:21:35 +0100 | [diff] [blame] | 6293 | <proxy_address> <proxy_port> <server_address> <server_port> |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 6294 | |
Cyril Bonté | 777be86 | 2014-12-02 21:21:35 +0100 | [diff] [blame] | 6295 | The <proxy_address> and <proxy_port> are derived from the first listener |
| 6296 | that is either IPv4, IPv6 or a UNIX socket. In the case of a UNIX socket |
| 6297 | listener the proxy_address will be the path of the socket and the |
| 6298 | <proxy_port> will be the string "NOT_USED". In a backend section, it's not |
| 6299 | possible to determine a listener, and both <proxy_address> and <proxy_port> |
| 6300 | will have the string value "NOT_USED". |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 6301 | |
Cyril Bonté | 72cda2a | 2014-12-27 22:28:39 +0100 | [diff] [blame] | 6302 | Some values are also provided through environment variables. |
| 6303 | |
| 6304 | Environment variables : |
| 6305 | HAPROXY_PROXY_ADDR The first bind address if available (or empty if not |
| 6306 | applicable, for example in a "backend" section). |
| 6307 | |
| 6308 | HAPROXY_PROXY_ID The backend id. |
| 6309 | |
| 6310 | HAPROXY_PROXY_NAME The backend name. |
| 6311 | |
| 6312 | HAPROXY_PROXY_PORT The first bind port if available (or empty if not |
| 6313 | applicable, for example in a "backend" section or |
| 6314 | for a UNIX socket). |
| 6315 | |
| 6316 | HAPROXY_SERVER_ADDR The server address. |
| 6317 | |
| 6318 | HAPROXY_SERVER_CURCONN The current number of connections on the server. |
| 6319 | |
| 6320 | HAPROXY_SERVER_ID The server id. |
| 6321 | |
| 6322 | HAPROXY_SERVER_MAXCONN The server max connections. |
| 6323 | |
| 6324 | HAPROXY_SERVER_NAME The server name. |
| 6325 | |
| 6326 | HAPROXY_SERVER_PORT The server port if available (or empty for a UNIX |
| 6327 | socket). |
| 6328 | |
| 6329 | PATH The PATH environment variable used when executing |
| 6330 | the command may be set using "external-check path". |
| 6331 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 6332 | If the command executed and exits with a zero status then the check is |
| 6333 | considered to have passed, otherwise the check is considered to have |
| 6334 | failed. |
| 6335 | |
| 6336 | Example : |
| 6337 | external-check command /bin/true |
| 6338 | |
| 6339 | See also : "external-check", "option external-check", "external-check path" |
| 6340 | |
| 6341 | |
| 6342 | external-check path <path> |
| 6343 | The value of the PATH environment variable used when running an external-check |
| 6344 | May be used in sections : defaults | frontend | listen | backend |
| 6345 | yes | no | yes | yes |
| 6346 | |
| 6347 | Arguments : |
| 6348 | <path> is the path used when executing external command to run |
| 6349 | |
| 6350 | The default path is "". |
| 6351 | |
| 6352 | Example : |
| 6353 | external-check path "/usr/bin:/bin" |
| 6354 | |
| 6355 | See also : "external-check", "option external-check", |
| 6356 | "external-check command" |
| 6357 | |
| 6358 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 6359 | persist rdp-cookie |
Hervé COMMOWICK | a3eb39c | 2011-08-05 18:48:51 +0200 | [diff] [blame] | 6360 | persist rdp-cookie(<name>) |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 6361 | Enable RDP cookie-based persistence |
| 6362 | May be used in sections : defaults | frontend | listen | backend |
| 6363 | yes | no | yes | yes |
| 6364 | Arguments : |
| 6365 | <name> is the optional name of the RDP cookie to check. If omitted, the |
Willy Tarreau | 61e28f2 | 2010-05-16 22:31:05 +0200 | [diff] [blame] | 6366 | default cookie name "msts" will be used. There currently is no |
| 6367 | valid reason to change this name. |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 6368 | |
| 6369 | This statement enables persistence based on an RDP cookie. The RDP cookie |
| 6370 | contains all information required to find the server in the list of known |
| 6371 | servers. So when this option is set in the backend, the request is analysed |
| 6372 | and if an RDP cookie is found, it is decoded. If it matches a known server |
| 6373 | which is still UP (or if "option persist" is set), then the connection is |
| 6374 | forwarded to this server. |
| 6375 | |
| 6376 | Note that this only makes sense in a TCP backend, but for this to work, the |
| 6377 | frontend must have waited long enough to ensure that an RDP cookie is present |
| 6378 | in the request buffer. This is the same requirement as with the "rdp-cookie" |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 6379 | load-balancing method. Thus it is highly recommended to put all statements in |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 6380 | a single "listen" section. |
| 6381 | |
Willy Tarreau | 61e28f2 | 2010-05-16 22:31:05 +0200 | [diff] [blame] | 6382 | Also, it is important to understand that the terminal server will emit this |
| 6383 | RDP cookie only if it is configured for "token redirection mode", which means |
| 6384 | that the "IP address redirection" option is disabled. |
| 6385 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 6386 | Example : |
| 6387 | listen tse-farm |
| 6388 | bind :3389 |
| 6389 | # wait up to 5s for an RDP cookie in the request |
| 6390 | tcp-request inspect-delay 5s |
| 6391 | tcp-request content accept if RDP_COOKIE |
| 6392 | # apply RDP cookie persistence |
| 6393 | persist rdp-cookie |
| 6394 | # if server is unknown, let's balance on the same cookie. |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 6395 | # alternatively, "balance leastconn" may be useful too. |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 6396 | balance rdp-cookie |
| 6397 | server srv1 1.1.1.1:3389 |
| 6398 | server srv2 1.1.1.2:3389 |
| 6399 | |
Simon Horman | ab814e0 | 2011-06-24 14:50:20 +0900 | [diff] [blame] | 6400 | See also : "balance rdp-cookie", "tcp-request", the "req_rdp_cookie" ACL and |
| 6401 | the rdp_cookie pattern fetch function. |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 6402 | |
| 6403 | |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 6404 | rate-limit sessions <rate> |
| 6405 | Set a limit on the number of new sessions accepted per second on a frontend |
| 6406 | May be used in sections : defaults | frontend | listen | backend |
| 6407 | yes | yes | yes | no |
| 6408 | Arguments : |
| 6409 | <rate> The <rate> parameter is an integer designating the maximum number |
| 6410 | of new sessions per second to accept on the frontend. |
| 6411 | |
| 6412 | When the frontend reaches the specified number of new sessions per second, it |
| 6413 | stops accepting new connections until the rate drops below the limit again. |
| 6414 | During this time, the pending sessions will be kept in the socket's backlog |
| 6415 | (in system buffers) and haproxy will not even be aware that sessions are |
| 6416 | pending. When applying very low limit on a highly loaded service, it may make |
| 6417 | sense to increase the socket's backlog using the "backlog" keyword. |
| 6418 | |
| 6419 | This feature is particularly efficient at blocking connection-based attacks |
| 6420 | or service abuse on fragile servers. Since the session rate is measured every |
| 6421 | millisecond, it is extremely accurate. Also, the limit applies immediately, |
| 6422 | no delay is needed at all to detect the threshold. |
| 6423 | |
| 6424 | Example : limit the connection rate on SMTP to 10 per second max |
| 6425 | listen smtp |
| 6426 | mode tcp |
| 6427 | bind :25 |
| 6428 | rate-limit sessions 10 |
| 6429 | server 127.0.0.1:1025 |
| 6430 | |
Willy Tarreau | a17c2d9 | 2011-07-25 08:16:20 +0200 | [diff] [blame] | 6431 | Note : when the maximum rate is reached, the frontend's status is not changed |
| 6432 | but its sockets appear as "WAITING" in the statistics if the |
| 6433 | "socket-stats" option is enabled. |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 6434 | |
| 6435 | See also : the "backlog" keyword and the "fe_sess_rate" ACL criterion. |
| 6436 | |
| 6437 | |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 6438 | redirect location <loc> [code <code>] <option> [{if | unless} <condition>] |
| 6439 | redirect prefix <pfx> [code <code>] <option> [{if | unless} <condition>] |
| 6440 | redirect scheme <sch> [code <code>] <option> [{if | unless} <condition>] |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 6441 | Return an HTTP redirection if/unless a condition is matched |
| 6442 | May be used in sections : defaults | frontend | listen | backend |
| 6443 | no | yes | yes | yes |
| 6444 | |
| 6445 | If/unless the condition is matched, the HTTP request will lead to a redirect |
Willy Tarreau | f285f54 | 2010-01-03 20:03:03 +0100 | [diff] [blame] | 6446 | response. If no condition is specified, the redirect applies unconditionally. |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 6447 | |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 6448 | Arguments : |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 6449 | <loc> With "redirect location", the exact value in <loc> is placed into |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 6450 | the HTTP "Location" header. When used in an "http-request" rule, |
| 6451 | <loc> value follows the log-format rules and can include some |
| 6452 | dynamic values (see Custom Log Format in section 8.2.4). |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 6453 | |
| 6454 | <pfx> With "redirect prefix", the "Location" header is built from the |
| 6455 | concatenation of <pfx> and the complete URI path, including the |
| 6456 | query string, unless the "drop-query" option is specified (see |
| 6457 | below). As a special case, if <pfx> equals exactly "/", then |
| 6458 | nothing is inserted before the original URI. It allows one to |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 6459 | redirect to the same URL (for instance, to insert a cookie). When |
| 6460 | used in an "http-request" rule, <pfx> value follows the log-format |
| 6461 | rules and can include some dynamic values (see Custom Log Format |
| 6462 | in section 8.2.4). |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 6463 | |
| 6464 | <sch> With "redirect scheme", then the "Location" header is built by |
| 6465 | concatenating <sch> with "://" then the first occurrence of the |
| 6466 | "Host" header, and then the URI path, including the query string |
| 6467 | unless the "drop-query" option is specified (see below). If no |
| 6468 | path is found or if the path is "*", then "/" is used instead. If |
| 6469 | no "Host" header is found, then an empty host component will be |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 6470 | returned, which most recent browsers interpret as redirecting to |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 6471 | the same host. This directive is mostly used to redirect HTTP to |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 6472 | HTTPS. When used in an "http-request" rule, <sch> value follows |
| 6473 | the log-format rules and can include some dynamic values (see |
| 6474 | Custom Log Format in section 8.2.4). |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 6475 | |
| 6476 | <code> The code is optional. It indicates which type of HTTP redirection |
Willy Tarreau | b67fdc4 | 2013-03-29 19:28:11 +0100 | [diff] [blame] | 6477 | is desired. Only codes 301, 302, 303, 307 and 308 are supported, |
| 6478 | with 302 used by default if no code is specified. 301 means |
| 6479 | "Moved permanently", and a browser may cache the Location. 302 |
Baptiste Assmann | ea849c0 | 2015-08-03 11:42:50 +0200 | [diff] [blame] | 6480 | means "Moved temporarily" and means that the browser should not |
Willy Tarreau | b67fdc4 | 2013-03-29 19:28:11 +0100 | [diff] [blame] | 6481 | cache the redirection. 303 is equivalent to 302 except that the |
| 6482 | browser will fetch the location with a GET method. 307 is just |
| 6483 | like 302 but makes it clear that the same method must be reused. |
| 6484 | Likewise, 308 replaces 301 if the same method must be used. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 6485 | |
| 6486 | <option> There are several options which can be specified to adjust the |
| 6487 | expected behaviour of a redirection : |
| 6488 | |
| 6489 | - "drop-query" |
| 6490 | When this keyword is used in a prefix-based redirection, then the |
| 6491 | location will be set without any possible query-string, which is useful |
| 6492 | for directing users to a non-secure page for instance. It has no effect |
| 6493 | with a location-type redirect. |
| 6494 | |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 6495 | - "append-slash" |
| 6496 | This keyword may be used in conjunction with "drop-query" to redirect |
| 6497 | users who use a URL not ending with a '/' to the same one with the '/'. |
| 6498 | It can be useful to ensure that search engines will only see one URL. |
| 6499 | For this, a return code 301 is preferred. |
| 6500 | |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 6501 | - "set-cookie NAME[=value]" |
| 6502 | A "Set-Cookie" header will be added with NAME (and optionally "=value") |
| 6503 | to the response. This is sometimes used to indicate that a user has |
| 6504 | been seen, for instance to protect against some types of DoS. No other |
| 6505 | cookie option is added, so the cookie will be a session cookie. Note |
| 6506 | that for a browser, a sole cookie name without an equal sign is |
| 6507 | different from a cookie with an equal sign. |
| 6508 | |
| 6509 | - "clear-cookie NAME[=]" |
| 6510 | A "Set-Cookie" header will be added with NAME (and optionally "="), but |
| 6511 | with the "Max-Age" attribute set to zero. This will tell the browser to |
| 6512 | delete this cookie. It is useful for instance on logout pages. It is |
| 6513 | important to note that clearing the cookie "NAME" will not remove a |
| 6514 | cookie set with "NAME=value". You have to clear the cookie "NAME=" for |
| 6515 | that, because the browser makes the difference. |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 6516 | |
| 6517 | Example: move the login URL only to HTTPS. |
| 6518 | acl clear dst_port 80 |
| 6519 | acl secure dst_port 8080 |
| 6520 | acl login_page url_beg /login |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 6521 | acl logout url_beg /logout |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 6522 | acl uid_given url_reg /login?userid=[^&]+ |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 6523 | acl cookie_set hdr_sub(cookie) SEEN=1 |
| 6524 | |
| 6525 | redirect prefix https://mysite.com set-cookie SEEN=1 if !cookie_set |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 6526 | redirect prefix https://mysite.com if login_page !secure |
| 6527 | redirect prefix http://mysite.com drop-query if login_page !uid_given |
| 6528 | redirect location http://mysite.com/ if !login_page secure |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 6529 | redirect location / clear-cookie USERID= if logout |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 6530 | |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 6531 | Example: send redirects for request for articles without a '/'. |
| 6532 | acl missing_slash path_reg ^/article/[^/]*$ |
| 6533 | redirect code 301 prefix / drop-query append-slash if missing_slash |
| 6534 | |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 6535 | Example: redirect all HTTP traffic to HTTPS when SSL is handled by haproxy. |
David BERARD | e715304 | 2012-11-03 00:11:31 +0100 | [diff] [blame] | 6536 | redirect scheme https if !{ ssl_fc } |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 6537 | |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 6538 | Example: append 'www.' prefix in front of all hosts not having it |
| 6539 | http-request redirect code 301 location www.%[hdr(host)]%[req.uri] \ |
| 6540 | unless { hdr_beg(host) -i www } |
| 6541 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 6542 | See section 7 about ACL usage. |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 6543 | |
| 6544 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 6545 | redisp (deprecated) |
| 6546 | redispatch (deprecated) |
| 6547 | Enable or disable session redistribution in case of connection failure |
| 6548 | May be used in sections: defaults | frontend | listen | backend |
| 6549 | yes | no | yes | yes |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 6550 | Arguments : none |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 6551 | |
| 6552 | In HTTP mode, if a server designated by a cookie is down, clients may |
| 6553 | definitely stick to it because they cannot flush the cookie, so they will not |
| 6554 | be able to access the service anymore. |
| 6555 | |
| 6556 | Specifying "redispatch" will allow the proxy to break their persistence and |
| 6557 | redistribute them to a working server. |
| 6558 | |
| 6559 | It also allows to retry last connection to another server in case of multiple |
| 6560 | connection failures. Of course, it requires having "retries" set to a nonzero |
| 6561 | value. |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 6562 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 6563 | This form is deprecated, do not use it in any new configuration, use the new |
| 6564 | "option redispatch" instead. |
| 6565 | |
| 6566 | See also : "option redispatch" |
| 6567 | |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 6568 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6569 | reqadd <string> [{if | unless} <cond>] |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6570 | Add a header at the end of the HTTP request |
| 6571 | May be used in sections : defaults | frontend | listen | backend |
| 6572 | no | yes | yes | yes |
| 6573 | Arguments : |
| 6574 | <string> is the complete line to be added. Any space or known delimiter |
| 6575 | must be escaped using a backslash ('\'). Please refer to section |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 6576 | 6 about HTTP header manipulation for more information. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6577 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6578 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6579 | possible to ignore this rule when other conditions are not met. |
| 6580 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6581 | A new line consisting in <string> followed by a line feed will be added after |
| 6582 | the last header of an HTTP request. |
| 6583 | |
| 6584 | Header transformations only apply to traffic which passes through HAProxy, |
| 6585 | and not to traffic generated by HAProxy, such as health-checks or error |
| 6586 | responses. |
| 6587 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6588 | Example : add "X-Proto: SSL" to requests coming via port 81 |
| 6589 | acl is-ssl dst_port 81 |
| 6590 | reqadd X-Proto:\ SSL if is-ssl |
| 6591 | |
| 6592 | See also: "rspadd", section 6 about HTTP header manipulation, and section 7 |
| 6593 | about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6594 | |
| 6595 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6596 | reqallow <search> [{if | unless} <cond>] |
| 6597 | reqiallow <search> [{if | unless} <cond>] (ignore case) |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6598 | Definitely allow an HTTP request if a line matches a regular expression |
| 6599 | May be used in sections : defaults | frontend | listen | backend |
| 6600 | no | yes | yes | yes |
| 6601 | Arguments : |
| 6602 | <search> is the regular expression applied to HTTP headers and to the |
| 6603 | request line. This is an extended regular expression. Parenthesis |
| 6604 | grouping is supported and no preliminary backslash is required. |
| 6605 | Any space or known delimiter must be escaped using a backslash |
| 6606 | ('\'). The pattern applies to a full line at a time. The |
| 6607 | "reqallow" keyword strictly matches case while "reqiallow" |
| 6608 | ignores case. |
| 6609 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6610 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6611 | possible to ignore this rule when other conditions are not met. |
| 6612 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6613 | A request containing any line which matches extended regular expression |
| 6614 | <search> will mark the request as allowed, even if any later test would |
| 6615 | result in a deny. The test applies both to the request line and to request |
| 6616 | headers. Keep in mind that URLs in request line are case-sensitive while |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 6617 | header names are not. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6618 | |
| 6619 | It is easier, faster and more powerful to use ACLs to write access policies. |
| 6620 | Reqdeny, reqallow and reqpass should be avoided in new designs. |
| 6621 | |
| 6622 | Example : |
| 6623 | # allow www.* but refuse *.local |
| 6624 | reqiallow ^Host:\ www\. |
| 6625 | reqideny ^Host:\ .*\.local |
| 6626 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6627 | See also: "reqdeny", "block", section 6 about HTTP header manipulation, and |
| 6628 | section 7 about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6629 | |
| 6630 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6631 | reqdel <search> [{if | unless} <cond>] |
| 6632 | reqidel <search> [{if | unless} <cond>] (ignore case) |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6633 | Delete all headers matching a regular expression in an HTTP request |
| 6634 | May be used in sections : defaults | frontend | listen | backend |
| 6635 | no | yes | yes | yes |
| 6636 | Arguments : |
| 6637 | <search> is the regular expression applied to HTTP headers and to the |
| 6638 | request line. This is an extended regular expression. Parenthesis |
| 6639 | grouping is supported and no preliminary backslash is required. |
| 6640 | Any space or known delimiter must be escaped using a backslash |
| 6641 | ('\'). The pattern applies to a full line at a time. The "reqdel" |
| 6642 | keyword strictly matches case while "reqidel" ignores case. |
| 6643 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6644 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6645 | possible to ignore this rule when other conditions are not met. |
| 6646 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6647 | Any header line matching extended regular expression <search> in the request |
| 6648 | will be completely deleted. Most common use of this is to remove unwanted |
| 6649 | and/or dangerous headers or cookies from a request before passing it to the |
| 6650 | next servers. |
| 6651 | |
| 6652 | Header transformations only apply to traffic which passes through HAProxy, |
| 6653 | and not to traffic generated by HAProxy, such as health-checks or error |
| 6654 | responses. Keep in mind that header names are not case-sensitive. |
| 6655 | |
| 6656 | Example : |
| 6657 | # remove X-Forwarded-For header and SERVER cookie |
| 6658 | reqidel ^X-Forwarded-For:.* |
| 6659 | reqidel ^Cookie:.*SERVER= |
| 6660 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6661 | See also: "reqadd", "reqrep", "rspdel", section 6 about HTTP header |
| 6662 | manipulation, and section 7 about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6663 | |
| 6664 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6665 | reqdeny <search> [{if | unless} <cond>] |
| 6666 | reqideny <search> [{if | unless} <cond>] (ignore case) |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6667 | Deny an HTTP request if a line matches a regular expression |
| 6668 | May be used in sections : defaults | frontend | listen | backend |
| 6669 | no | yes | yes | yes |
| 6670 | Arguments : |
| 6671 | <search> is the regular expression applied to HTTP headers and to the |
| 6672 | request line. This is an extended regular expression. Parenthesis |
| 6673 | grouping is supported and no preliminary backslash is required. |
| 6674 | Any space or known delimiter must be escaped using a backslash |
| 6675 | ('\'). The pattern applies to a full line at a time. The |
| 6676 | "reqdeny" keyword strictly matches case while "reqideny" ignores |
| 6677 | case. |
| 6678 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6679 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6680 | possible to ignore this rule when other conditions are not met. |
| 6681 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6682 | A request containing any line which matches extended regular expression |
| 6683 | <search> will mark the request as denied, even if any later test would |
| 6684 | result in an allow. The test applies both to the request line and to request |
| 6685 | headers. Keep in mind that URLs in request line are case-sensitive while |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 6686 | header names are not. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6687 | |
Willy Tarreau | ced2701 | 2008-01-17 20:35:34 +0100 | [diff] [blame] | 6688 | A denied request will generate an "HTTP 403 forbidden" response once the |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 6689 | complete request has been parsed. This is consistent with what is practiced |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 6690 | using ACLs. |
Willy Tarreau | ced2701 | 2008-01-17 20:35:34 +0100 | [diff] [blame] | 6691 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6692 | It is easier, faster and more powerful to use ACLs to write access policies. |
| 6693 | Reqdeny, reqallow and reqpass should be avoided in new designs. |
| 6694 | |
| 6695 | Example : |
| 6696 | # refuse *.local, then allow www.* |
| 6697 | reqideny ^Host:\ .*\.local |
| 6698 | reqiallow ^Host:\ www\. |
| 6699 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6700 | See also: "reqallow", "rspdeny", "block", section 6 about HTTP header |
| 6701 | manipulation, and section 7 about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6702 | |
| 6703 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6704 | reqpass <search> [{if | unless} <cond>] |
| 6705 | reqipass <search> [{if | unless} <cond>] (ignore case) |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6706 | Ignore any HTTP request line matching a regular expression in next rules |
| 6707 | May be used in sections : defaults | frontend | listen | backend |
| 6708 | no | yes | yes | yes |
| 6709 | Arguments : |
| 6710 | <search> is the regular expression applied to HTTP headers and to the |
| 6711 | request line. This is an extended regular expression. Parenthesis |
| 6712 | grouping is supported and no preliminary backslash is required. |
| 6713 | Any space or known delimiter must be escaped using a backslash |
| 6714 | ('\'). The pattern applies to a full line at a time. The |
| 6715 | "reqpass" keyword strictly matches case while "reqipass" ignores |
| 6716 | case. |
| 6717 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6718 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6719 | possible to ignore this rule when other conditions are not met. |
| 6720 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6721 | A request containing any line which matches extended regular expression |
| 6722 | <search> will skip next rules, without assigning any deny or allow verdict. |
| 6723 | The test applies both to the request line and to request headers. Keep in |
| 6724 | mind that URLs in request line are case-sensitive while header names are not. |
| 6725 | |
| 6726 | It is easier, faster and more powerful to use ACLs to write access policies. |
| 6727 | Reqdeny, reqallow and reqpass should be avoided in new designs. |
| 6728 | |
| 6729 | Example : |
| 6730 | # refuse *.local, then allow www.*, but ignore "www.private.local" |
| 6731 | reqipass ^Host:\ www.private\.local |
| 6732 | reqideny ^Host:\ .*\.local |
| 6733 | reqiallow ^Host:\ www\. |
| 6734 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6735 | See also: "reqallow", "reqdeny", "block", section 6 about HTTP header |
| 6736 | manipulation, and section 7 about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6737 | |
| 6738 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6739 | reqrep <search> <string> [{if | unless} <cond>] |
| 6740 | reqirep <search> <string> [{if | unless} <cond>] (ignore case) |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6741 | Replace a regular expression with a string in an HTTP request line |
| 6742 | May be used in sections : defaults | frontend | listen | backend |
| 6743 | no | yes | yes | yes |
| 6744 | Arguments : |
| 6745 | <search> is the regular expression applied to HTTP headers and to the |
| 6746 | request line. This is an extended regular expression. Parenthesis |
| 6747 | grouping is supported and no preliminary backslash is required. |
| 6748 | Any space or known delimiter must be escaped using a backslash |
| 6749 | ('\'). The pattern applies to a full line at a time. The "reqrep" |
| 6750 | keyword strictly matches case while "reqirep" ignores case. |
| 6751 | |
| 6752 | <string> is the complete line to be added. Any space or known delimiter |
| 6753 | must be escaped using a backslash ('\'). References to matched |
| 6754 | pattern groups are possible using the common \N form, with N |
| 6755 | being a single digit between 0 and 9. Please refer to section |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 6756 | 6 about HTTP header manipulation for more information. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6757 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6758 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6759 | possible to ignore this rule when other conditions are not met. |
| 6760 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6761 | Any line matching extended regular expression <search> in the request (both |
| 6762 | the request line and header lines) will be completely replaced with <string>. |
| 6763 | Most common use of this is to rewrite URLs or domain names in "Host" headers. |
| 6764 | |
| 6765 | Header transformations only apply to traffic which passes through HAProxy, |
| 6766 | and not to traffic generated by HAProxy, such as health-checks or error |
| 6767 | responses. Note that for increased readability, it is suggested to add enough |
| 6768 | spaces between the request and the response. Keep in mind that URLs in |
| 6769 | request line are case-sensitive while header names are not. |
| 6770 | |
| 6771 | Example : |
| 6772 | # replace "/static/" with "/" at the beginning of any request path. |
Dmitry Sivachenko | 7823de3 | 2012-05-16 14:00:26 +0400 | [diff] [blame] | 6773 | reqrep ^([^\ :]*)\ /static/(.*) \1\ /\2 |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6774 | # replace "www.mydomain.com" with "www" in the host name. |
| 6775 | reqirep ^Host:\ www.mydomain.com Host:\ www |
| 6776 | |
Dmitry Sivachenko | f6f4f7b | 2012-10-21 18:10:25 +0400 | [diff] [blame] | 6777 | See also: "reqadd", "reqdel", "rsprep", "tune.bufsize", section 6 about |
| 6778 | HTTP header manipulation, and section 7 about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6779 | |
| 6780 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6781 | reqtarpit <search> [{if | unless} <cond>] |
| 6782 | reqitarpit <search> [{if | unless} <cond>] (ignore case) |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6783 | Tarpit an HTTP request containing a line matching a regular expression |
| 6784 | May be used in sections : defaults | frontend | listen | backend |
| 6785 | no | yes | yes | yes |
| 6786 | Arguments : |
| 6787 | <search> is the regular expression applied to HTTP headers and to the |
| 6788 | request line. This is an extended regular expression. Parenthesis |
| 6789 | grouping is supported and no preliminary backslash is required. |
| 6790 | Any space or known delimiter must be escaped using a backslash |
| 6791 | ('\'). The pattern applies to a full line at a time. The |
| 6792 | "reqtarpit" keyword strictly matches case while "reqitarpit" |
| 6793 | ignores case. |
| 6794 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6795 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6796 | possible to ignore this rule when other conditions are not met. |
| 6797 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6798 | A request containing any line which matches extended regular expression |
| 6799 | <search> will be tarpitted, which means that it will connect to nowhere, will |
Willy Tarreau | ced2701 | 2008-01-17 20:35:34 +0100 | [diff] [blame] | 6800 | be kept open for a pre-defined time, then will return an HTTP error 500 so |
| 6801 | that the attacker does not suspect it has been tarpitted. The status 500 will |
| 6802 | be reported in the logs, but the completion flags will indicate "PT". The |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6803 | delay is defined by "timeout tarpit", or "timeout connect" if the former is |
| 6804 | not set. |
| 6805 | |
| 6806 | The goal of the tarpit is to slow down robots attacking servers with |
| 6807 | identifiable requests. Many robots limit their outgoing number of connections |
| 6808 | and stay connected waiting for a reply which can take several minutes to |
| 6809 | come. Depending on the environment and attack, it may be particularly |
| 6810 | efficient at reducing the load on the network and firewalls. |
| 6811 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6812 | Examples : |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6813 | # ignore user-agents reporting any flavour of "Mozilla" or "MSIE", but |
| 6814 | # block all others. |
| 6815 | reqipass ^User-Agent:\.*(Mozilla|MSIE) |
| 6816 | reqitarpit ^User-Agent: |
| 6817 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6818 | # block bad guys |
| 6819 | acl badguys src 10.1.0.3 172.16.13.20/28 |
| 6820 | reqitarpit . if badguys |
| 6821 | |
| 6822 | See also: "reqallow", "reqdeny", "reqpass", section 6 about HTTP header |
| 6823 | manipulation, and section 7 about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6824 | |
| 6825 | |
Willy Tarreau | e5c5ce9 | 2008-06-20 17:27:19 +0200 | [diff] [blame] | 6826 | retries <value> |
| 6827 | Set the number of retries to perform on a server after a connection failure |
| 6828 | May be used in sections: defaults | frontend | listen | backend |
| 6829 | yes | no | yes | yes |
| 6830 | Arguments : |
| 6831 | <value> is the number of times a connection attempt should be retried on |
| 6832 | a server when a connection either is refused or times out. The |
| 6833 | default value is 3. |
| 6834 | |
| 6835 | It is important to understand that this value applies to the number of |
| 6836 | connection attempts, not full requests. When a connection has effectively |
| 6837 | been established to a server, there will be no more retry. |
| 6838 | |
| 6839 | In order to avoid immediate reconnections to a server which is restarting, |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 6840 | a turn-around timer of min("timeout connect", one second) is applied before |
| 6841 | a retry occurs. |
Willy Tarreau | e5c5ce9 | 2008-06-20 17:27:19 +0200 | [diff] [blame] | 6842 | |
| 6843 | When "option redispatch" is set, the last retry may be performed on another |
| 6844 | server even if a cookie references a different server. |
| 6845 | |
| 6846 | See also : "option redispatch" |
| 6847 | |
| 6848 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6849 | rspadd <string> [{if | unless} <cond>] |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6850 | Add a header at the end of the HTTP response |
| 6851 | May be used in sections : defaults | frontend | listen | backend |
| 6852 | no | yes | yes | yes |
| 6853 | Arguments : |
| 6854 | <string> is the complete line to be added. Any space or known delimiter |
| 6855 | must be escaped using a backslash ('\'). Please refer to section |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 6856 | 6 about HTTP header manipulation for more information. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6857 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6858 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6859 | possible to ignore this rule when other conditions are not met. |
| 6860 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6861 | A new line consisting in <string> followed by a line feed will be added after |
| 6862 | the last header of an HTTP response. |
| 6863 | |
| 6864 | Header transformations only apply to traffic which passes through HAProxy, |
| 6865 | and not to traffic generated by HAProxy, such as health-checks or error |
| 6866 | responses. |
| 6867 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6868 | See also: "reqadd", section 6 about HTTP header manipulation, and section 7 |
| 6869 | about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6870 | |
| 6871 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6872 | rspdel <search> [{if | unless} <cond>] |
| 6873 | rspidel <search> [{if | unless} <cond>] (ignore case) |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6874 | Delete all headers matching a regular expression in an HTTP response |
| 6875 | May be used in sections : defaults | frontend | listen | backend |
| 6876 | no | yes | yes | yes |
| 6877 | Arguments : |
| 6878 | <search> is the regular expression applied to HTTP headers and to the |
| 6879 | response line. This is an extended regular expression, so |
| 6880 | parenthesis grouping is supported and no preliminary backslash |
| 6881 | is required. Any space or known delimiter must be escaped using |
| 6882 | a backslash ('\'). The pattern applies to a full line at a time. |
| 6883 | The "rspdel" keyword strictly matches case while "rspidel" |
| 6884 | ignores case. |
| 6885 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6886 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6887 | possible to ignore this rule when other conditions are not met. |
| 6888 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6889 | Any header line matching extended regular expression <search> in the response |
| 6890 | will be completely deleted. Most common use of this is to remove unwanted |
Willy Tarreau | 3c92c5f | 2011-08-28 09:45:47 +0200 | [diff] [blame] | 6891 | and/or sensitive headers or cookies from a response before passing it to the |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6892 | client. |
| 6893 | |
| 6894 | Header transformations only apply to traffic which passes through HAProxy, |
| 6895 | and not to traffic generated by HAProxy, such as health-checks or error |
| 6896 | responses. Keep in mind that header names are not case-sensitive. |
| 6897 | |
| 6898 | Example : |
| 6899 | # remove the Server header from responses |
Willy Tarreau | 5e80e02 | 2013-05-25 08:31:25 +0200 | [diff] [blame] | 6900 | rspidel ^Server:.* |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6901 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6902 | See also: "rspadd", "rsprep", "reqdel", section 6 about HTTP header |
| 6903 | manipulation, and section 7 about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6904 | |
| 6905 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6906 | rspdeny <search> [{if | unless} <cond>] |
| 6907 | rspideny <search> [{if | unless} <cond>] (ignore case) |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6908 | Block an HTTP response if a line matches a regular expression |
| 6909 | May be used in sections : defaults | frontend | listen | backend |
| 6910 | no | yes | yes | yes |
| 6911 | Arguments : |
| 6912 | <search> is the regular expression applied to HTTP headers and to the |
| 6913 | response line. This is an extended regular expression, so |
| 6914 | parenthesis grouping is supported and no preliminary backslash |
| 6915 | is required. Any space or known delimiter must be escaped using |
| 6916 | a backslash ('\'). The pattern applies to a full line at a time. |
| 6917 | The "rspdeny" keyword strictly matches case while "rspideny" |
| 6918 | ignores case. |
| 6919 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6920 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6921 | possible to ignore this rule when other conditions are not met. |
| 6922 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6923 | A response containing any line which matches extended regular expression |
| 6924 | <search> will mark the request as denied. The test applies both to the |
| 6925 | response line and to response headers. Keep in mind that header names are not |
| 6926 | case-sensitive. |
| 6927 | |
| 6928 | Main use of this keyword is to prevent sensitive information leak and to |
Willy Tarreau | ced2701 | 2008-01-17 20:35:34 +0100 | [diff] [blame] | 6929 | block the response before it reaches the client. If a response is denied, it |
| 6930 | will be replaced with an HTTP 502 error so that the client never retrieves |
| 6931 | any sensitive data. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6932 | |
| 6933 | It is easier, faster and more powerful to use ACLs to write access policies. |
| 6934 | Rspdeny should be avoided in new designs. |
| 6935 | |
| 6936 | Example : |
| 6937 | # Ensure that no content type matching ms-word will leak |
| 6938 | rspideny ^Content-type:\.*/ms-word |
| 6939 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6940 | See also: "reqdeny", "acl", "block", section 6 about HTTP header manipulation |
| 6941 | and section 7 about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6942 | |
| 6943 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6944 | rsprep <search> <string> [{if | unless} <cond>] |
| 6945 | rspirep <search> <string> [{if | unless} <cond>] (ignore case) |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6946 | Replace a regular expression with a string in an HTTP response line |
| 6947 | May be used in sections : defaults | frontend | listen | backend |
| 6948 | no | yes | yes | yes |
| 6949 | Arguments : |
| 6950 | <search> is the regular expression applied to HTTP headers and to the |
| 6951 | response line. This is an extended regular expression, so |
| 6952 | parenthesis grouping is supported and no preliminary backslash |
| 6953 | is required. Any space or known delimiter must be escaped using |
| 6954 | a backslash ('\'). The pattern applies to a full line at a time. |
| 6955 | The "rsprep" keyword strictly matches case while "rspirep" |
| 6956 | ignores case. |
| 6957 | |
| 6958 | <string> is the complete line to be added. Any space or known delimiter |
| 6959 | must be escaped using a backslash ('\'). References to matched |
| 6960 | pattern groups are possible using the common \N form, with N |
| 6961 | being a single digit between 0 and 9. Please refer to section |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 6962 | 6 about HTTP header manipulation for more information. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6963 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6964 | <cond> is an optional matching condition built from ACLs. It makes it |
| 6965 | possible to ignore this rule when other conditions are not met. |
| 6966 | |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6967 | Any line matching extended regular expression <search> in the response (both |
| 6968 | the response line and header lines) will be completely replaced with |
| 6969 | <string>. Most common use of this is to rewrite Location headers. |
| 6970 | |
| 6971 | Header transformations only apply to traffic which passes through HAProxy, |
| 6972 | and not to traffic generated by HAProxy, such as health-checks or error |
| 6973 | responses. Note that for increased readability, it is suggested to add enough |
| 6974 | spaces between the request and the response. Keep in mind that header names |
| 6975 | are not case-sensitive. |
| 6976 | |
| 6977 | Example : |
| 6978 | # replace "Location: 127.0.0.1:8080" with "Location: www.mydomain.com" |
| 6979 | rspirep ^Location:\ 127.0.0.1:8080 Location:\ www.mydomain.com |
| 6980 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6981 | See also: "rspadd", "rspdel", "reqrep", section 6 about HTTP header |
| 6982 | manipulation, and section 7 about ACLs. |
Willy Tarreau | 303c035 | 2008-01-17 19:01:39 +0100 | [diff] [blame] | 6983 | |
| 6984 | |
David du Colombier | 486df47 | 2011-03-17 10:40:26 +0100 | [diff] [blame] | 6985 | server <name> <address>[:[port]] [param*] |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 6986 | Declare a server in a backend |
| 6987 | May be used in sections : defaults | frontend | listen | backend |
| 6988 | no | no | yes | yes |
| 6989 | Arguments : |
| 6990 | <name> is the internal name assigned to this server. This name will |
Cyril Bonté | 941a0c6 | 2012-10-15 19:44:24 +0200 | [diff] [blame] | 6991 | appear in logs and alerts. If "http-send-name-header" is |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 6992 | set, it will be added to the request header sent to the server. |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 6993 | |
David du Colombier | 486df47 | 2011-03-17 10:40:26 +0100 | [diff] [blame] | 6994 | <address> is the IPv4 or IPv6 address of the server. Alternatively, a |
| 6995 | resolvable hostname is supported, but this name will be resolved |
| 6996 | during start-up. Address "0.0.0.0" or "*" has a special meaning. |
| 6997 | It indicates that the connection will be forwarded to the same IP |
Willy Tarreau | d669a4f | 2010-07-13 14:49:50 +0200 | [diff] [blame] | 6998 | address as the one from the client connection. This is useful in |
| 6999 | transparent proxy architectures where the client's connection is |
| 7000 | intercepted and haproxy must forward to the original destination |
| 7001 | address. This is more or less what the "transparent" keyword does |
| 7002 | except that with a server it's possible to limit concurrency and |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 7003 | to report statistics. Optionally, an address family prefix may be |
| 7004 | used before the address to force the family regardless of the |
| 7005 | address format, which can be useful to specify a path to a unix |
| 7006 | socket with no slash ('/'). Currently supported prefixes are : |
| 7007 | - 'ipv4@' -> address is always IPv4 |
| 7008 | - 'ipv6@' -> address is always IPv6 |
| 7009 | - 'unix@' -> address is a path to a local unix socket |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 7010 | - 'abns@' -> address is in abstract namespace (Linux only) |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7011 | You may want to reference some environment variables in the |
| 7012 | address parameter, see section 2.3 about environment |
| 7013 | variables. |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7014 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 7015 | <port> is an optional port specification. If set, all connections will |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7016 | be sent to this port. If unset, the same port the client |
| 7017 | connected to will be used. The port may also be prefixed by a "+" |
| 7018 | or a "-". In this case, the server's port will be determined by |
| 7019 | adding this value to the client's port. |
| 7020 | |
| 7021 | <param*> is a list of parameters for this server. The "server" keywords |
| 7022 | accepts an important number of options and has a complete section |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 7023 | dedicated to it. Please refer to section 5 for more details. |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7024 | |
| 7025 | Examples : |
| 7026 | server first 10.1.1.1:1080 cookie first check inter 1000 |
| 7027 | server second 10.1.1.2:1080 cookie second check inter 1000 |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 7028 | server transp ipv4@ |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7029 | server backup "${SRV_BACKUP}:1080" backup |
| 7030 | server www1_dc1 "${LAN_DC1}.101:80" |
| 7031 | server www1_dc2 "${LAN_DC2}.101:80" |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7032 | |
Willy Tarreau | 55dcaf6 | 2015-09-27 15:03:15 +0200 | [diff] [blame] | 7033 | Note: regarding Linux's abstract namespace sockets, HAProxy uses the whole |
| 7034 | sun_path length is used for the address length. Some other programs |
| 7035 | such as socat use the string length only by default. Pass the option |
| 7036 | ",unix-tightsocklen=0" to any abstract socket definition in socat to |
| 7037 | make it compatible with HAProxy's. |
| 7038 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 7039 | See also: "default-server", "http-send-name-header" and section 5 about |
| 7040 | server options |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7041 | |
Baptiste Assmann | 01c6cc3 | 2015-08-23 11:45:29 +0200 | [diff] [blame] | 7042 | server-state-file-name [<file>] |
| 7043 | Set the server state file to read, load and apply to servers available in |
| 7044 | this backend. It only applies when the directive "load-server-state-from-file" |
| 7045 | is set to "local". When <file> is not provided or if this directive is not |
| 7046 | set, then backend name is used. If <file> starts with a slash '/', then it is |
| 7047 | considered as an absolute path. Otherwise, <file> is concatenated to the |
| 7048 | global directive "server-state-file-base". |
| 7049 | |
| 7050 | Example: the minimal configuration below would make HAProxy look for the |
| 7051 | state server file '/etc/haproxy/states/bk': |
| 7052 | |
| 7053 | global |
| 7054 | server-state-file-base /etc/haproxy/states |
| 7055 | |
| 7056 | backend bk |
| 7057 | load-server-state-from-file |
| 7058 | |
| 7059 | See also: "server-state-file-base", "load-server-state-from-file", and |
| 7060 | "show servers state" |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7061 | |
| 7062 | source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | client | clientip } ] |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7063 | source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | hdr_ip(<hdr>[,<occ>]) } ] |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 7064 | source <addr>[:<port>] [interface <name>] |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7065 | Set the source address for outgoing connections |
| 7066 | May be used in sections : defaults | frontend | listen | backend |
| 7067 | yes | no | yes | yes |
| 7068 | Arguments : |
| 7069 | <addr> is the IPv4 address HAProxy will bind to before connecting to a |
| 7070 | server. This address is also used as a source for health checks. |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 7071 | |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7072 | The default value of 0.0.0.0 means that the system will select |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 7073 | the most appropriate address to reach its destination. Optionally |
| 7074 | an address family prefix may be used before the address to force |
| 7075 | the family regardless of the address format, which can be useful |
| 7076 | to specify a path to a unix socket with no slash ('/'). Currently |
| 7077 | supported prefixes are : |
| 7078 | - 'ipv4@' -> address is always IPv4 |
| 7079 | - 'ipv6@' -> address is always IPv6 |
| 7080 | - 'unix@' -> address is a path to a local unix socket |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 7081 | - 'abns@' -> address is in abstract namespace (Linux only) |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7082 | You may want to reference some environment variables in the address |
| 7083 | parameter, see section 2.3 about environment variables. |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7084 | |
| 7085 | <port> is an optional port. It is normally not needed but may be useful |
| 7086 | in some very specific contexts. The default value of zero means |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 7087 | the system will select a free port. Note that port ranges are not |
| 7088 | supported in the backend. If you want to force port ranges, you |
| 7089 | have to specify them on each "server" line. |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7090 | |
| 7091 | <addr2> is the IP address to present to the server when connections are |
| 7092 | forwarded in full transparent proxy mode. This is currently only |
| 7093 | supported on some patched Linux kernels. When this address is |
| 7094 | specified, clients connecting to the server will be presented |
| 7095 | with this address, while health checks will still use the address |
| 7096 | <addr>. |
| 7097 | |
| 7098 | <port2> is the optional port to present to the server when connections |
| 7099 | are forwarded in full transparent proxy mode (see <addr2> above). |
| 7100 | The default value of zero means the system will select a free |
| 7101 | port. |
| 7102 | |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7103 | <hdr> is the name of a HTTP header in which to fetch the IP to bind to. |
| 7104 | This is the name of a comma-separated header list which can |
| 7105 | contain multiple IP addresses. By default, the last occurrence is |
| 7106 | used. This is designed to work with the X-Forwarded-For header |
Baptiste Assmann | ea3e73b | 2013-02-02 23:47:49 +0100 | [diff] [blame] | 7107 | and to automatically bind to the client's IP address as seen |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7108 | by previous proxy, typically Stunnel. In order to use another |
| 7109 | occurrence from the last one, please see the <occ> parameter |
| 7110 | below. When the header (or occurrence) is not found, no binding |
| 7111 | is performed so that the proxy's default IP address is used. Also |
| 7112 | keep in mind that the header name is case insensitive, as for any |
| 7113 | HTTP header. |
| 7114 | |
| 7115 | <occ> is the occurrence number of a value to be used in a multi-value |
| 7116 | header. This is to be used in conjunction with "hdr_ip(<hdr>)", |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 7117 | in order to specify which occurrence to use for the source IP |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7118 | address. Positive values indicate a position from the first |
| 7119 | occurrence, 1 being the first one. Negative values indicate |
| 7120 | positions relative to the last one, -1 being the last one. This |
| 7121 | is helpful for situations where an X-Forwarded-For header is set |
| 7122 | at the entry point of an infrastructure and must be used several |
| 7123 | proxy layers away. When this value is not specified, -1 is |
| 7124 | assumed. Passing a zero here disables the feature. |
| 7125 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 7126 | <name> is an optional interface name to which to bind to for outgoing |
| 7127 | traffic. On systems supporting this features (currently, only |
| 7128 | Linux), this allows one to bind all traffic to the server to |
| 7129 | this interface even if it is not the one the system would select |
| 7130 | based on routing tables. This should be used with extreme care. |
| 7131 | Note that using this option requires root privileges. |
| 7132 | |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7133 | The "source" keyword is useful in complex environments where a specific |
| 7134 | address only is allowed to connect to the servers. It may be needed when a |
| 7135 | private address must be used through a public gateway for instance, and it is |
| 7136 | known that the system cannot determine the adequate source address by itself. |
| 7137 | |
| 7138 | An extension which is available on certain patched Linux kernels may be used |
| 7139 | through the "usesrc" optional keyword. It makes it possible to connect to the |
| 7140 | servers with an IP address which does not belong to the system itself. This |
| 7141 | is called "full transparent proxy mode". For this to work, the destination |
| 7142 | servers have to route their traffic back to this address through the machine |
| 7143 | running HAProxy, and IP forwarding must generally be enabled on this machine. |
| 7144 | |
| 7145 | In this "full transparent proxy" mode, it is possible to force a specific IP |
| 7146 | address to be presented to the servers. This is not much used in fact. A more |
| 7147 | common use is to tell HAProxy to present the client's IP address. For this, |
| 7148 | there are two methods : |
| 7149 | |
| 7150 | - present the client's IP and port addresses. This is the most transparent |
| 7151 | mode, but it can cause problems when IP connection tracking is enabled on |
| 7152 | the machine, because a same connection may be seen twice with different |
| 7153 | states. However, this solution presents the huge advantage of not |
| 7154 | limiting the system to the 64k outgoing address+port couples, because all |
| 7155 | of the client ranges may be used. |
| 7156 | |
| 7157 | - present only the client's IP address and select a spare port. This |
| 7158 | solution is still quite elegant but slightly less transparent (downstream |
| 7159 | firewalls logs will not match upstream's). It also presents the downside |
| 7160 | of limiting the number of concurrent connections to the usual 64k ports. |
| 7161 | However, since the upstream and downstream ports are different, local IP |
| 7162 | connection tracking on the machine will not be upset by the reuse of the |
| 7163 | same session. |
| 7164 | |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7165 | This option sets the default source for all servers in the backend. It may |
| 7166 | also be specified in a "defaults" section. Finer source address specification |
| 7167 | is possible at the server level using the "source" server option. Refer to |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 7168 | section 5 for more information. |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7169 | |
Baptiste Assmann | 91bd337 | 2015-07-17 21:59:42 +0200 | [diff] [blame] | 7170 | In order to work, "usesrc" requires root privileges. |
| 7171 | |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7172 | Examples : |
| 7173 | backend private |
| 7174 | # Connect to the servers using our 192.168.1.200 source address |
| 7175 | source 192.168.1.200 |
| 7176 | |
| 7177 | backend transparent_ssl1 |
| 7178 | # Connect to the SSL farm from the client's source address |
| 7179 | source 192.168.1.200 usesrc clientip |
| 7180 | |
| 7181 | backend transparent_ssl2 |
| 7182 | # Connect to the SSL farm from the client's source address and port |
| 7183 | # not recommended if IP conntrack is present on the local machine. |
| 7184 | source 192.168.1.200 usesrc client |
| 7185 | |
| 7186 | backend transparent_ssl3 |
| 7187 | # Connect to the SSL farm from the client's source address. It |
| 7188 | # is more conntrack-friendly. |
| 7189 | source 192.168.1.200 usesrc clientip |
| 7190 | |
| 7191 | backend transparent_smtp |
| 7192 | # Connect to the SMTP farm from the client's source address/port |
| 7193 | # with Tproxy version 4. |
| 7194 | source 0.0.0.0 usesrc clientip |
| 7195 | |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7196 | backend transparent_http |
| 7197 | # Connect to the servers using the client's IP as seen by previous |
| 7198 | # proxy. |
| 7199 | source 0.0.0.0 usesrc hdr_ip(x-forwarded-for,-1) |
| 7200 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 7201 | See also : the "source" server option in section 5, the Tproxy patches for |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7202 | the Linux kernel on www.balabit.com, the "bind" keyword. |
| 7203 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 7204 | |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 7205 | srvtimeout <timeout> (deprecated) |
| 7206 | Set the maximum inactivity time on the server side. |
| 7207 | May be used in sections : defaults | frontend | listen | backend |
| 7208 | yes | no | yes | yes |
| 7209 | Arguments : |
| 7210 | <timeout> is the timeout value specified in milliseconds by default, but |
| 7211 | can be in any other unit if the number is suffixed by the unit, |
| 7212 | as explained at the top of this document. |
| 7213 | |
| 7214 | The inactivity timeout applies when the server is expected to acknowledge or |
| 7215 | send data. In HTTP mode, this timeout is particularly important to consider |
| 7216 | during the first phase of the server's response, when it has to send the |
| 7217 | headers, as it directly represents the server's processing time for the |
| 7218 | request. To find out what value to put there, it's often good to start with |
| 7219 | what would be considered as unacceptable response times, then check the logs |
| 7220 | to observe the response time distribution, and adjust the value accordingly. |
| 7221 | |
| 7222 | The value is specified in milliseconds by default, but can be in any other |
| 7223 | unit if the number is suffixed by the unit, as specified at the top of this |
| 7224 | document. In TCP mode (and to a lesser extent, in HTTP mode), it is highly |
| 7225 | recommended that the client timeout remains equal to the server timeout in |
| 7226 | order to avoid complex situations to debug. Whatever the expected server |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 7227 | response times, it is a good practice to cover at least one or several TCP |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 7228 | packet losses by specifying timeouts that are slightly above multiples of 3 |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 7229 | seconds (eg: 4 or 5 seconds minimum). |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 7230 | |
| 7231 | This parameter is specific to backends, but can be specified once for all in |
| 7232 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 7233 | forget about it. An unspecified timeout results in an infinite timeout, which |
| 7234 | is not recommended. Such a usage is accepted and works but reports a warning |
| 7235 | during startup because it may results in accumulation of expired sessions in |
| 7236 | the system if the system's timeouts are not configured either. |
| 7237 | |
| 7238 | This parameter is provided for compatibility but is currently deprecated. |
| 7239 | Please use "timeout server" instead. |
| 7240 | |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 7241 | See also : "timeout server", "timeout tunnel", "timeout client" and |
| 7242 | "clitimeout". |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 7243 | |
| 7244 | |
Cyril Bonté | 66c327d | 2010-10-12 00:14:37 +0200 | [diff] [blame] | 7245 | stats admin { if | unless } <cond> |
| 7246 | Enable statistics admin level if/unless a condition is matched |
| 7247 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7248 | no | yes | yes | yes |
Cyril Bonté | 66c327d | 2010-10-12 00:14:37 +0200 | [diff] [blame] | 7249 | |
| 7250 | This statement enables the statistics admin level if/unless a condition is |
| 7251 | matched. |
| 7252 | |
| 7253 | The admin level allows to enable/disable servers from the web interface. By |
| 7254 | default, statistics page is read-only for security reasons. |
| 7255 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7256 | Note : Consider not using this feature in multi-process mode (nbproc > 1) |
| 7257 | unless you know what you do : memory is not shared between the |
| 7258 | processes, which can result in random behaviours. |
| 7259 | |
Cyril Bonté | 23b39d9 | 2011-02-10 22:54:44 +0100 | [diff] [blame] | 7260 | Currently, the POST request is limited to the buffer size minus the reserved |
| 7261 | buffer space, which means that if the list of servers is too long, the |
| 7262 | request won't be processed. It is recommended to alter few servers at a |
| 7263 | time. |
Cyril Bonté | 66c327d | 2010-10-12 00:14:37 +0200 | [diff] [blame] | 7264 | |
| 7265 | Example : |
| 7266 | # statistics admin level only for localhost |
| 7267 | backend stats_localhost |
| 7268 | stats enable |
| 7269 | stats admin if LOCALHOST |
| 7270 | |
| 7271 | Example : |
| 7272 | # statistics admin level always enabled because of the authentication |
| 7273 | backend stats_auth |
| 7274 | stats enable |
| 7275 | stats auth admin:AdMiN123 |
| 7276 | stats admin if TRUE |
| 7277 | |
| 7278 | Example : |
| 7279 | # statistics admin level depends on the authenticated user |
| 7280 | userlist stats-auth |
| 7281 | group admin users admin |
| 7282 | user admin insecure-password AdMiN123 |
| 7283 | group readonly users haproxy |
| 7284 | user haproxy insecure-password haproxy |
| 7285 | |
| 7286 | backend stats_auth |
| 7287 | stats enable |
| 7288 | acl AUTH http_auth(stats-auth) |
| 7289 | acl AUTH_ADMIN http_auth_group(stats-auth) admin |
| 7290 | stats http-request auth unless AUTH |
| 7291 | stats admin if AUTH_ADMIN |
| 7292 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7293 | See also : "stats enable", "stats auth", "stats http-request", "nbproc", |
| 7294 | "bind-process", section 3.4 about userlists and section 7 about |
| 7295 | ACL usage. |
Cyril Bonté | 66c327d | 2010-10-12 00:14:37 +0200 | [diff] [blame] | 7296 | |
| 7297 | |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7298 | stats auth <user>:<passwd> |
| 7299 | Enable statistics with authentication and grant access to an account |
| 7300 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7301 | yes | yes | yes | yes |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7302 | Arguments : |
| 7303 | <user> is a user name to grant access to |
| 7304 | |
| 7305 | <passwd> is the cleartext password associated to this user |
| 7306 | |
| 7307 | This statement enables statistics with default settings, and restricts access |
| 7308 | to declared users only. It may be repeated as many times as necessary to |
| 7309 | allow as many users as desired. When a user tries to access the statistics |
| 7310 | without a valid account, a "401 Forbidden" response will be returned so that |
| 7311 | the browser asks the user to provide a valid user and password. The real |
| 7312 | which will be returned to the browser is configurable using "stats realm". |
| 7313 | |
| 7314 | Since the authentication method is HTTP Basic Authentication, the passwords |
| 7315 | circulate in cleartext on the network. Thus, it was decided that the |
| 7316 | configuration file would also use cleartext passwords to remind the users |
Willy Tarreau | 3c92c5f | 2011-08-28 09:45:47 +0200 | [diff] [blame] | 7317 | that those ones should not be sensitive and not shared with any other account. |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7318 | |
| 7319 | It is also possible to reduce the scope of the proxies which appear in the |
| 7320 | report using "stats scope". |
| 7321 | |
| 7322 | Though this statement alone is enough to enable statistics reporting, it is |
| 7323 | recommended to set all other settings in order to avoid relying on default |
| 7324 | unobvious parameters. |
| 7325 | |
| 7326 | Example : |
| 7327 | # public access (limited to this backend only) |
| 7328 | backend public_www |
| 7329 | server srv1 192.168.0.1:80 |
| 7330 | stats enable |
| 7331 | stats hide-version |
| 7332 | stats scope . |
| 7333 | stats uri /admin?stats |
| 7334 | stats realm Haproxy\ Statistics |
| 7335 | stats auth admin1:AdMiN123 |
| 7336 | stats auth admin2:AdMiN321 |
| 7337 | |
| 7338 | # internal monitoring access (unlimited) |
| 7339 | backend private_monitoring |
| 7340 | stats enable |
| 7341 | stats uri /admin?stats |
| 7342 | stats refresh 5s |
| 7343 | |
| 7344 | See also : "stats enable", "stats realm", "stats scope", "stats uri" |
| 7345 | |
| 7346 | |
| 7347 | stats enable |
| 7348 | Enable statistics reporting with default settings |
| 7349 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7350 | yes | yes | yes | yes |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7351 | Arguments : none |
| 7352 | |
| 7353 | This statement enables statistics reporting with default settings defined |
| 7354 | at build time. Unless stated otherwise, these settings are used : |
| 7355 | - stats uri : /haproxy?stats |
| 7356 | - stats realm : "HAProxy Statistics" |
| 7357 | - stats auth : no authentication |
| 7358 | - stats scope : no restriction |
| 7359 | |
| 7360 | Though this statement alone is enough to enable statistics reporting, it is |
| 7361 | recommended to set all other settings in order to avoid relying on default |
| 7362 | unobvious parameters. |
| 7363 | |
| 7364 | Example : |
| 7365 | # public access (limited to this backend only) |
| 7366 | backend public_www |
| 7367 | server srv1 192.168.0.1:80 |
| 7368 | stats enable |
| 7369 | stats hide-version |
| 7370 | stats scope . |
| 7371 | stats uri /admin?stats |
| 7372 | stats realm Haproxy\ Statistics |
| 7373 | stats auth admin1:AdMiN123 |
| 7374 | stats auth admin2:AdMiN321 |
| 7375 | |
| 7376 | # internal monitoring access (unlimited) |
| 7377 | backend private_monitoring |
| 7378 | stats enable |
| 7379 | stats uri /admin?stats |
| 7380 | stats refresh 5s |
| 7381 | |
| 7382 | See also : "stats auth", "stats realm", "stats uri" |
| 7383 | |
| 7384 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7385 | stats hide-version |
| 7386 | Enable statistics and hide HAProxy version reporting |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 7387 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7388 | yes | yes | yes | yes |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7389 | Arguments : none |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 7390 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7391 | By default, the stats page reports some useful status information along with |
| 7392 | the statistics. Among them is HAProxy's version. However, it is generally |
| 7393 | considered dangerous to report precise version to anyone, as it can help them |
| 7394 | target known weaknesses with specific attacks. The "stats hide-version" |
| 7395 | statement removes the version from the statistics report. This is recommended |
| 7396 | for public sites or any site with a weak login/password. |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 7397 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 7398 | Though this statement alone is enough to enable statistics reporting, it is |
| 7399 | recommended to set all other settings in order to avoid relying on default |
| 7400 | unobvious parameters. |
| 7401 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7402 | Example : |
| 7403 | # public access (limited to this backend only) |
| 7404 | backend public_www |
| 7405 | server srv1 192.168.0.1:80 |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 7406 | stats enable |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7407 | stats hide-version |
| 7408 | stats scope . |
| 7409 | stats uri /admin?stats |
| 7410 | stats realm Haproxy\ Statistics |
| 7411 | stats auth admin1:AdMiN123 |
| 7412 | stats auth admin2:AdMiN321 |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 7413 | |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 7414 | # internal monitoring access (unlimited) |
| 7415 | backend private_monitoring |
| 7416 | stats enable |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7417 | stats uri /admin?stats |
| 7418 | stats refresh 5s |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 7419 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7420 | See also : "stats auth", "stats enable", "stats realm", "stats uri" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 7421 | |
Willy Tarreau | 983e01e | 2010-01-11 18:42:06 +0100 | [diff] [blame] | 7422 | |
Cyril Bonté | 2be1b3f | 2010-09-30 23:46:30 +0200 | [diff] [blame] | 7423 | stats http-request { allow | deny | auth [realm <realm>] } |
| 7424 | [ { if | unless } <condition> ] |
| 7425 | Access control for statistics |
| 7426 | |
| 7427 | May be used in sections: defaults | frontend | listen | backend |
| 7428 | no | no | yes | yes |
| 7429 | |
| 7430 | As "http-request", these set of options allow to fine control access to |
| 7431 | statistics. Each option may be followed by if/unless and acl. |
| 7432 | First option with matched condition (or option without condition) is final. |
| 7433 | For "deny" a 403 error will be returned, for "allow" normal processing is |
| 7434 | performed, for "auth" a 401/407 error code is returned so the client |
| 7435 | should be asked to enter a username and password. |
| 7436 | |
| 7437 | There is no fixed limit to the number of http-request statements per |
| 7438 | instance. |
| 7439 | |
| 7440 | See also : "http-request", section 3.4 about userlists and section 7 |
| 7441 | about ACL usage. |
| 7442 | |
| 7443 | |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7444 | stats realm <realm> |
| 7445 | Enable statistics and set authentication realm |
| 7446 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7447 | yes | yes | yes | yes |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7448 | Arguments : |
| 7449 | <realm> is the name of the HTTP Basic Authentication realm reported to |
| 7450 | the browser. The browser uses it to display it in the pop-up |
| 7451 | inviting the user to enter a valid username and password. |
| 7452 | |
| 7453 | The realm is read as a single word, so any spaces in it should be escaped |
| 7454 | using a backslash ('\'). |
| 7455 | |
| 7456 | This statement is useful only in conjunction with "stats auth" since it is |
| 7457 | only related to authentication. |
| 7458 | |
| 7459 | Though this statement alone is enough to enable statistics reporting, it is |
| 7460 | recommended to set all other settings in order to avoid relying on default |
| 7461 | unobvious parameters. |
| 7462 | |
| 7463 | Example : |
| 7464 | # public access (limited to this backend only) |
| 7465 | backend public_www |
| 7466 | server srv1 192.168.0.1:80 |
| 7467 | stats enable |
| 7468 | stats hide-version |
| 7469 | stats scope . |
| 7470 | stats uri /admin?stats |
| 7471 | stats realm Haproxy\ Statistics |
| 7472 | stats auth admin1:AdMiN123 |
| 7473 | stats auth admin2:AdMiN321 |
| 7474 | |
| 7475 | # internal monitoring access (unlimited) |
| 7476 | backend private_monitoring |
| 7477 | stats enable |
| 7478 | stats uri /admin?stats |
| 7479 | stats refresh 5s |
| 7480 | |
| 7481 | See also : "stats auth", "stats enable", "stats uri" |
| 7482 | |
| 7483 | |
| 7484 | stats refresh <delay> |
| 7485 | Enable statistics with automatic refresh |
| 7486 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7487 | yes | yes | yes | yes |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7488 | Arguments : |
| 7489 | <delay> is the suggested refresh delay, specified in seconds, which will |
| 7490 | be returned to the browser consulting the report page. While the |
| 7491 | browser is free to apply any delay, it will generally respect it |
| 7492 | and refresh the page this every seconds. The refresh interval may |
| 7493 | be specified in any other non-default time unit, by suffixing the |
| 7494 | unit after the value, as explained at the top of this document. |
| 7495 | |
| 7496 | This statement is useful on monitoring displays with a permanent page |
| 7497 | reporting the load balancer's activity. When set, the HTML report page will |
| 7498 | include a link "refresh"/"stop refresh" so that the user can select whether |
| 7499 | he wants automatic refresh of the page or not. |
| 7500 | |
| 7501 | Though this statement alone is enough to enable statistics reporting, it is |
| 7502 | recommended to set all other settings in order to avoid relying on default |
| 7503 | unobvious parameters. |
| 7504 | |
| 7505 | Example : |
| 7506 | # public access (limited to this backend only) |
| 7507 | backend public_www |
| 7508 | server srv1 192.168.0.1:80 |
| 7509 | stats enable |
| 7510 | stats hide-version |
| 7511 | stats scope . |
| 7512 | stats uri /admin?stats |
| 7513 | stats realm Haproxy\ Statistics |
| 7514 | stats auth admin1:AdMiN123 |
| 7515 | stats auth admin2:AdMiN321 |
| 7516 | |
| 7517 | # internal monitoring access (unlimited) |
| 7518 | backend private_monitoring |
| 7519 | stats enable |
| 7520 | stats uri /admin?stats |
| 7521 | stats refresh 5s |
| 7522 | |
| 7523 | See also : "stats auth", "stats enable", "stats realm", "stats uri" |
| 7524 | |
| 7525 | |
| 7526 | stats scope { <name> | "." } |
| 7527 | Enable statistics and limit access scope |
| 7528 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7529 | yes | yes | yes | yes |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7530 | Arguments : |
| 7531 | <name> is the name of a listen, frontend or backend section to be |
| 7532 | reported. The special name "." (a single dot) designates the |
| 7533 | section in which the statement appears. |
| 7534 | |
| 7535 | When this statement is specified, only the sections enumerated with this |
| 7536 | statement will appear in the report. All other ones will be hidden. This |
| 7537 | statement may appear as many times as needed if multiple sections need to be |
| 7538 | reported. Please note that the name checking is performed as simple string |
| 7539 | comparisons, and that it is never checked that a give section name really |
| 7540 | exists. |
| 7541 | |
| 7542 | Though this statement alone is enough to enable statistics reporting, it is |
| 7543 | recommended to set all other settings in order to avoid relying on default |
| 7544 | unobvious parameters. |
| 7545 | |
| 7546 | Example : |
| 7547 | # public access (limited to this backend only) |
| 7548 | backend public_www |
| 7549 | server srv1 192.168.0.1:80 |
| 7550 | stats enable |
| 7551 | stats hide-version |
| 7552 | stats scope . |
| 7553 | stats uri /admin?stats |
| 7554 | stats realm Haproxy\ Statistics |
| 7555 | stats auth admin1:AdMiN123 |
| 7556 | stats auth admin2:AdMiN321 |
| 7557 | |
| 7558 | # internal monitoring access (unlimited) |
| 7559 | backend private_monitoring |
| 7560 | stats enable |
| 7561 | stats uri /admin?stats |
| 7562 | stats refresh 5s |
| 7563 | |
| 7564 | See also : "stats auth", "stats enable", "stats realm", "stats uri" |
| 7565 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7566 | |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 7567 | stats show-desc [ <desc> ] |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7568 | Enable reporting of a description on the statistics page. |
| 7569 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7570 | yes | yes | yes | yes |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7571 | |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 7572 | <desc> is an optional description to be reported. If unspecified, the |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7573 | description from global section is automatically used instead. |
| 7574 | |
| 7575 | This statement is useful for users that offer shared services to their |
| 7576 | customers, where node or description should be different for each customer. |
| 7577 | |
| 7578 | Though this statement alone is enough to enable statistics reporting, it is |
| 7579 | recommended to set all other settings in order to avoid relying on default |
Dmitry Sivachenko | 7823de3 | 2012-05-16 14:00:26 +0400 | [diff] [blame] | 7580 | unobvious parameters. By default description is not shown. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7581 | |
| 7582 | Example : |
| 7583 | # internal monitoring access (unlimited) |
| 7584 | backend private_monitoring |
| 7585 | stats enable |
| 7586 | stats show-desc Master node for Europe, Asia, Africa |
| 7587 | stats uri /admin?stats |
| 7588 | stats refresh 5s |
| 7589 | |
| 7590 | See also: "show-node", "stats enable", "stats uri" and "description" in |
| 7591 | global section. |
| 7592 | |
| 7593 | |
| 7594 | stats show-legends |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7595 | Enable reporting additional information on the statistics page |
| 7596 | May be used in sections : defaults | frontend | listen | backend |
| 7597 | yes | yes | yes | yes |
| 7598 | Arguments : none |
| 7599 | |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 7600 | Enable reporting additional information on the statistics page : |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7601 | - cap: capabilities (proxy) |
| 7602 | - mode: one of tcp, http or health (proxy) |
| 7603 | - id: SNMP ID (proxy, socket, server) |
| 7604 | - IP (socket, server) |
| 7605 | - cookie (backend, server) |
| 7606 | |
| 7607 | Though this statement alone is enough to enable statistics reporting, it is |
| 7608 | recommended to set all other settings in order to avoid relying on default |
Dmitry Sivachenko | 7823de3 | 2012-05-16 14:00:26 +0400 | [diff] [blame] | 7609 | unobvious parameters. Default behaviour is not to show this information. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7610 | |
| 7611 | See also: "stats enable", "stats uri". |
| 7612 | |
| 7613 | |
| 7614 | stats show-node [ <name> ] |
| 7615 | Enable reporting of a host name on the statistics page. |
| 7616 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7617 | yes | yes | yes | yes |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7618 | Arguments: |
| 7619 | <name> is an optional name to be reported. If unspecified, the |
| 7620 | node name from global section is automatically used instead. |
| 7621 | |
| 7622 | This statement is useful for users that offer shared services to their |
| 7623 | customers, where node or description might be different on a stats page |
Dmitry Sivachenko | 7823de3 | 2012-05-16 14:00:26 +0400 | [diff] [blame] | 7624 | provided for each customer. Default behaviour is not to show host name. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7625 | |
| 7626 | Though this statement alone is enough to enable statistics reporting, it is |
| 7627 | recommended to set all other settings in order to avoid relying on default |
| 7628 | unobvious parameters. |
| 7629 | |
| 7630 | Example: |
| 7631 | # internal monitoring access (unlimited) |
| 7632 | backend private_monitoring |
| 7633 | stats enable |
| 7634 | stats show-node Europe-1 |
| 7635 | stats uri /admin?stats |
| 7636 | stats refresh 5s |
| 7637 | |
| 7638 | See also: "show-desc", "stats enable", "stats uri", and "node" in global |
| 7639 | section. |
| 7640 | |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7641 | |
| 7642 | stats uri <prefix> |
| 7643 | Enable statistics and define the URI prefix to access them |
| 7644 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 7645 | yes | yes | yes | yes |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7646 | Arguments : |
| 7647 | <prefix> is the prefix of any URI which will be redirected to stats. This |
| 7648 | prefix may contain a question mark ('?') to indicate part of a |
| 7649 | query string. |
| 7650 | |
| 7651 | The statistics URI is intercepted on the relayed traffic, so it appears as a |
| 7652 | page within the normal application. It is strongly advised to ensure that the |
| 7653 | selected URI will never appear in the application, otherwise it will never be |
| 7654 | possible to reach it in the application. |
| 7655 | |
| 7656 | The default URI compiled in haproxy is "/haproxy?stats", but this may be |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 7657 | changed at build time, so it's better to always explicitly specify it here. |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7658 | It is generally a good idea to include a question mark in the URI so that |
| 7659 | intermediate proxies refrain from caching the results. Also, since any string |
| 7660 | beginning with the prefix will be accepted as a stats request, the question |
| 7661 | mark helps ensuring that no valid URI will begin with the same words. |
| 7662 | |
| 7663 | It is sometimes very convenient to use "/" as the URI prefix, and put that |
| 7664 | statement in a "listen" instance of its own. That makes it easy to dedicate |
| 7665 | an address or a port to statistics only. |
| 7666 | |
| 7667 | Though this statement alone is enough to enable statistics reporting, it is |
| 7668 | recommended to set all other settings in order to avoid relying on default |
| 7669 | unobvious parameters. |
| 7670 | |
| 7671 | Example : |
| 7672 | # public access (limited to this backend only) |
| 7673 | backend public_www |
| 7674 | server srv1 192.168.0.1:80 |
| 7675 | stats enable |
| 7676 | stats hide-version |
| 7677 | stats scope . |
| 7678 | stats uri /admin?stats |
| 7679 | stats realm Haproxy\ Statistics |
| 7680 | stats auth admin1:AdMiN123 |
| 7681 | stats auth admin2:AdMiN321 |
| 7682 | |
| 7683 | # internal monitoring access (unlimited) |
| 7684 | backend private_monitoring |
| 7685 | stats enable |
| 7686 | stats uri /admin?stats |
| 7687 | stats refresh 5s |
| 7688 | |
| 7689 | See also : "stats auth", "stats enable", "stats realm" |
| 7690 | |
| 7691 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7692 | stick match <pattern> [table <table>] [{if | unless} <cond>] |
| 7693 | Define a request pattern matching condition to stick a user to a server |
Willy Tarreau | eabeafa | 2008-01-16 16:17:06 +0100 | [diff] [blame] | 7694 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 7695 | no | no | yes | yes |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7696 | |
| 7697 | Arguments : |
Willy Tarreau | be722a2 | 2014-06-13 16:31:59 +0200 | [diff] [blame] | 7698 | <pattern> is a sample expression rule as described in section 7.3. It |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7699 | describes what elements of the incoming request or connection |
| 7700 | will be analysed in the hope to find a matching entry in a |
| 7701 | stickiness table. This rule is mandatory. |
| 7702 | |
| 7703 | <table> is an optional stickiness table name. If unspecified, the same |
| 7704 | backend's table is used. A stickiness table is declared using |
| 7705 | the "stick-table" statement. |
| 7706 | |
| 7707 | <cond> is an optional matching condition. It makes it possible to match |
| 7708 | on a certain criterion only when other conditions are met (or |
| 7709 | not met). For instance, it could be used to match on a source IP |
| 7710 | address except when a request passes through a known proxy, in |
| 7711 | which case we'd match on a header containing that IP address. |
| 7712 | |
| 7713 | Some protocols or applications require complex stickiness rules and cannot |
| 7714 | always simply rely on cookies nor hashing. The "stick match" statement |
| 7715 | describes a rule to extract the stickiness criterion from an incoming request |
| 7716 | or connection. See section 7 for a complete list of possible patterns and |
| 7717 | transformation rules. |
| 7718 | |
| 7719 | The table has to be declared using the "stick-table" statement. It must be of |
| 7720 | a type compatible with the pattern. By default it is the one which is present |
| 7721 | in the same backend. It is possible to share a table with other backends by |
| 7722 | referencing it using the "table" keyword. If another table is referenced, |
| 7723 | the server's ID inside the backends are used. By default, all server IDs |
| 7724 | start at 1 in each backend, so the server ordering is enough. But in case of |
| 7725 | doubt, it is highly recommended to force server IDs using their "id" setting. |
| 7726 | |
| 7727 | It is possible to restrict the conditions where a "stick match" statement |
| 7728 | will apply, using "if" or "unless" followed by a condition. See section 7 for |
| 7729 | ACL based conditions. |
| 7730 | |
| 7731 | There is no limit on the number of "stick match" statements. The first that |
| 7732 | applies and matches will cause the request to be directed to the same server |
| 7733 | as was used for the request which created the entry. That way, multiple |
| 7734 | matches can be used as fallbacks. |
| 7735 | |
| 7736 | The stick rules are checked after the persistence cookies, so they will not |
| 7737 | affect stickiness if a cookie has already been used to select a server. That |
| 7738 | way, it becomes very easy to insert cookies and match on IP addresses in |
| 7739 | order to maintain stickiness between HTTP and HTTPS. |
| 7740 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7741 | Note : Consider not using this feature in multi-process mode (nbproc > 1) |
| 7742 | unless you know what you do : memory is not shared between the |
| 7743 | processes, which can result in random behaviours. |
| 7744 | |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7745 | Example : |
| 7746 | # forward SMTP users to the same server they just used for POP in the |
| 7747 | # last 30 minutes |
| 7748 | backend pop |
| 7749 | mode tcp |
| 7750 | balance roundrobin |
| 7751 | stick store-request src |
| 7752 | stick-table type ip size 200k expire 30m |
| 7753 | server s1 192.168.1.1:110 |
| 7754 | server s2 192.168.1.1:110 |
| 7755 | |
| 7756 | backend smtp |
| 7757 | mode tcp |
| 7758 | balance roundrobin |
| 7759 | stick match src table pop |
| 7760 | server s1 192.168.1.1:25 |
| 7761 | server s2 192.168.1.1:25 |
| 7762 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7763 | See also : "stick-table", "stick on", "nbproc", "bind-process" and section 7 |
Willy Tarreau | be722a2 | 2014-06-13 16:31:59 +0200 | [diff] [blame] | 7764 | about ACLs and samples fetching. |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7765 | |
| 7766 | |
| 7767 | stick on <pattern> [table <table>] [{if | unless} <condition>] |
| 7768 | Define a request pattern to associate a user to a server |
| 7769 | May be used in sections : defaults | frontend | listen | backend |
| 7770 | no | no | yes | yes |
| 7771 | |
| 7772 | Note : This form is exactly equivalent to "stick match" followed by |
| 7773 | "stick store-request", all with the same arguments. Please refer |
| 7774 | to both keywords for details. It is only provided as a convenience |
| 7775 | for writing more maintainable configurations. |
| 7776 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7777 | Note : Consider not using this feature in multi-process mode (nbproc > 1) |
| 7778 | unless you know what you do : memory is not shared between the |
| 7779 | processes, which can result in random behaviours. |
| 7780 | |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7781 | Examples : |
| 7782 | # The following form ... |
Willy Tarreau | ec579d8 | 2010-02-26 19:15:04 +0100 | [diff] [blame] | 7783 | stick on src table pop if !localhost |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7784 | |
| 7785 | # ...is strictly equivalent to this one : |
| 7786 | stick match src table pop if !localhost |
| 7787 | stick store-request src table pop if !localhost |
| 7788 | |
| 7789 | |
| 7790 | # Use cookie persistence for HTTP, and stick on source address for HTTPS as |
| 7791 | # well as HTTP without cookie. Share the same table between both accesses. |
| 7792 | backend http |
| 7793 | mode http |
| 7794 | balance roundrobin |
| 7795 | stick on src table https |
| 7796 | cookie SRV insert indirect nocache |
| 7797 | server s1 192.168.1.1:80 cookie s1 |
| 7798 | server s2 192.168.1.1:80 cookie s2 |
| 7799 | |
| 7800 | backend https |
| 7801 | mode tcp |
| 7802 | balance roundrobin |
| 7803 | stick-table type ip size 200k expire 30m |
| 7804 | stick on src |
| 7805 | server s1 192.168.1.1:443 |
| 7806 | server s2 192.168.1.1:443 |
| 7807 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7808 | See also : "stick match", "stick store-request", "nbproc" and "bind-process". |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7809 | |
| 7810 | |
| 7811 | stick store-request <pattern> [table <table>] [{if | unless} <condition>] |
| 7812 | Define a request pattern used to create an entry in a stickiness table |
| 7813 | May be used in sections : defaults | frontend | listen | backend |
| 7814 | no | no | yes | yes |
| 7815 | |
| 7816 | Arguments : |
Willy Tarreau | be722a2 | 2014-06-13 16:31:59 +0200 | [diff] [blame] | 7817 | <pattern> is a sample expression rule as described in section 7.3. It |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7818 | describes what elements of the incoming request or connection |
| 7819 | will be analysed, extracted and stored in the table once a |
| 7820 | server is selected. |
| 7821 | |
| 7822 | <table> is an optional stickiness table name. If unspecified, the same |
| 7823 | backend's table is used. A stickiness table is declared using |
| 7824 | the "stick-table" statement. |
| 7825 | |
| 7826 | <cond> is an optional storage condition. It makes it possible to store |
| 7827 | certain criteria only when some conditions are met (or not met). |
| 7828 | For instance, it could be used to store the source IP address |
| 7829 | except when the request passes through a known proxy, in which |
| 7830 | case we'd store a converted form of a header containing that IP |
| 7831 | address. |
| 7832 | |
| 7833 | Some protocols or applications require complex stickiness rules and cannot |
| 7834 | always simply rely on cookies nor hashing. The "stick store-request" statement |
| 7835 | describes a rule to decide what to extract from the request and when to do |
| 7836 | it, in order to store it into a stickiness table for further requests to |
| 7837 | match it using the "stick match" statement. Obviously the extracted part must |
| 7838 | make sense and have a chance to be matched in a further request. Storing a |
| 7839 | client's IP address for instance often makes sense. Storing an ID found in a |
| 7840 | URL parameter also makes sense. Storing a source port will almost never make |
| 7841 | any sense because it will be randomly matched. See section 7 for a complete |
| 7842 | list of possible patterns and transformation rules. |
| 7843 | |
| 7844 | The table has to be declared using the "stick-table" statement. It must be of |
| 7845 | a type compatible with the pattern. By default it is the one which is present |
| 7846 | in the same backend. It is possible to share a table with other backends by |
| 7847 | referencing it using the "table" keyword. If another table is referenced, |
| 7848 | the server's ID inside the backends are used. By default, all server IDs |
| 7849 | start at 1 in each backend, so the server ordering is enough. But in case of |
| 7850 | doubt, it is highly recommended to force server IDs using their "id" setting. |
| 7851 | |
| 7852 | It is possible to restrict the conditions where a "stick store-request" |
| 7853 | statement will apply, using "if" or "unless" followed by a condition. This |
| 7854 | condition will be evaluated while parsing the request, so any criteria can be |
| 7855 | used. See section 7 for ACL based conditions. |
| 7856 | |
| 7857 | There is no limit on the number of "stick store-request" statements, but |
| 7858 | there is a limit of 8 simultaneous stores per request or response. This |
| 7859 | makes it possible to store up to 8 criteria, all extracted from either the |
| 7860 | request or the response, regardless of the number of rules. Only the 8 first |
| 7861 | ones which match will be kept. Using this, it is possible to feed multiple |
| 7862 | tables at once in the hope to increase the chance to recognize a user on |
Willy Tarreau | 9667a80 | 2013-12-09 12:52:13 +0100 | [diff] [blame] | 7863 | another protocol or access method. Using multiple store-request rules with |
| 7864 | the same table is possible and may be used to find the best criterion to rely |
| 7865 | on, by arranging the rules by decreasing preference order. Only the first |
| 7866 | extracted criterion for a given table will be stored. All subsequent store- |
| 7867 | request rules referencing the same table will be skipped and their ACLs will |
| 7868 | not be evaluated. |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7869 | |
| 7870 | The "store-request" rules are evaluated once the server connection has been |
| 7871 | established, so that the table will contain the real server that processed |
| 7872 | the request. |
| 7873 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7874 | Note : Consider not using this feature in multi-process mode (nbproc > 1) |
| 7875 | unless you know what you do : memory is not shared between the |
| 7876 | processes, which can result in random behaviours. |
| 7877 | |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7878 | Example : |
| 7879 | # forward SMTP users to the same server they just used for POP in the |
| 7880 | # last 30 minutes |
| 7881 | backend pop |
| 7882 | mode tcp |
| 7883 | balance roundrobin |
| 7884 | stick store-request src |
| 7885 | stick-table type ip size 200k expire 30m |
| 7886 | server s1 192.168.1.1:110 |
| 7887 | server s2 192.168.1.1:110 |
| 7888 | |
| 7889 | backend smtp |
| 7890 | mode tcp |
| 7891 | balance roundrobin |
| 7892 | stick match src table pop |
| 7893 | server s1 192.168.1.1:25 |
| 7894 | server s2 192.168.1.1:25 |
| 7895 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7896 | See also : "stick-table", "stick on", "nbproc", "bind-process" and section 7 |
Willy Tarreau | be722a2 | 2014-06-13 16:31:59 +0200 | [diff] [blame] | 7897 | about ACLs and sample fetching. |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7898 | |
| 7899 | |
Emeric Brun | 7c6b82e | 2010-09-24 16:34:28 +0200 | [diff] [blame] | 7900 | stick-table type {ip | integer | string [len <length>] | binary [len <length>]} |
Emeric Brun | f099e79 | 2010-09-27 12:05:28 +0200 | [diff] [blame] | 7901 | size <size> [expire <expire>] [nopurge] [peers <peersect>] |
| 7902 | [store <data_type>]* |
Godbach | 64cef79 | 2013-12-04 16:08:22 +0800 | [diff] [blame] | 7903 | Configure the stickiness table for the current section |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7904 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 7905 | no | yes | yes | yes |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7906 | |
| 7907 | Arguments : |
| 7908 | ip a table declared with "type ip" will only store IPv4 addresses. |
| 7909 | This form is very compact (about 50 bytes per entry) and allows |
| 7910 | very fast entry lookup and stores with almost no overhead. This |
| 7911 | is mainly used to store client source IP addresses. |
| 7912 | |
David du Colombier | 9a6d3c9 | 2011-03-17 10:40:24 +0100 | [diff] [blame] | 7913 | ipv6 a table declared with "type ipv6" will only store IPv6 addresses. |
| 7914 | This form is very compact (about 60 bytes per entry) and allows |
| 7915 | very fast entry lookup and stores with almost no overhead. This |
| 7916 | is mainly used to store client source IP addresses. |
| 7917 | |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7918 | integer a table declared with "type integer" will store 32bit integers |
| 7919 | which can represent a client identifier found in a request for |
| 7920 | instance. |
| 7921 | |
| 7922 | string a table declared with "type string" will store substrings of up |
| 7923 | to <len> characters. If the string provided by the pattern |
| 7924 | extractor is larger than <len>, it will be truncated before |
| 7925 | being stored. During matching, at most <len> characters will be |
| 7926 | compared between the string in the table and the extracted |
| 7927 | pattern. When not specified, the string is automatically limited |
Emeric Brun | 7c6b82e | 2010-09-24 16:34:28 +0200 | [diff] [blame] | 7928 | to 32 characters. |
| 7929 | |
| 7930 | binary a table declared with "type binary" will store binary blocks |
| 7931 | of <len> bytes. If the block provided by the pattern |
| 7932 | extractor is larger than <len>, it will be truncated before |
Willy Tarreau | be722a2 | 2014-06-13 16:31:59 +0200 | [diff] [blame] | 7933 | being stored. If the block provided by the sample expression |
Emeric Brun | 7c6b82e | 2010-09-24 16:34:28 +0200 | [diff] [blame] | 7934 | is shorter than <len>, it will be padded by 0. When not |
| 7935 | specified, the block is automatically limited to 32 bytes. |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7936 | |
| 7937 | <length> is the maximum number of characters that will be stored in a |
Emeric Brun | 7c6b82e | 2010-09-24 16:34:28 +0200 | [diff] [blame] | 7938 | "string" type table (See type "string" above). Or the number |
| 7939 | of bytes of the block in "binary" type table. Be careful when |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7940 | changing this parameter as memory usage will proportionally |
| 7941 | increase. |
| 7942 | |
| 7943 | <size> is the maximum number of entries that can fit in the table. This |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 7944 | value directly impacts memory usage. Count approximately |
| 7945 | 50 bytes per entry, plus the size of a string if any. The size |
| 7946 | supports suffixes "k", "m", "g" for 2^10, 2^20 and 2^30 factors. |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7947 | |
| 7948 | [nopurge] indicates that we refuse to purge older entries when the table |
| 7949 | is full. When not specified and the table is full when haproxy |
| 7950 | wants to store an entry in it, it will flush a few of the oldest |
| 7951 | entries in order to release some space for the new ones. This is |
| 7952 | most often the desired behaviour. In some specific cases, it |
| 7953 | be desirable to refuse new entries instead of purging the older |
| 7954 | ones. That may be the case when the amount of data to store is |
| 7955 | far above the hardware limits and we prefer not to offer access |
| 7956 | to new clients than to reject the ones already connected. When |
| 7957 | using this parameter, be sure to properly set the "expire" |
| 7958 | parameter (see below). |
| 7959 | |
Emeric Brun | f099e79 | 2010-09-27 12:05:28 +0200 | [diff] [blame] | 7960 | <peersect> is the name of the peers section to use for replication. Entries |
| 7961 | which associate keys to server IDs are kept synchronized with |
| 7962 | the remote peers declared in this section. All entries are also |
| 7963 | automatically learned from the local peer (old process) during a |
| 7964 | soft restart. |
| 7965 | |
Willy Tarreau | 1abc673 | 2015-05-01 19:21:02 +0200 | [diff] [blame] | 7966 | NOTE : each peers section may be referenced only by tables |
| 7967 | belonging to the same unique process. |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7968 | |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7969 | <expire> defines the maximum duration of an entry in the table since it |
| 7970 | was last created, refreshed or matched. The expiration delay is |
| 7971 | defined using the standard time format, similarly as the various |
| 7972 | timeouts. The maximum duration is slightly above 24 days. See |
| 7973 | section 2.2 for more information. If this delay is not specified, |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 7974 | the session won't automatically expire, but older entries will |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 7975 | be removed once full. Be sure not to use the "nopurge" parameter |
| 7976 | if not expiration delay is specified. |
| 7977 | |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 7978 | <data_type> is used to store additional information in the stick-table. This |
| 7979 | may be used by ACLs in order to control various criteria related |
| 7980 | to the activity of the client matching the stick-table. For each |
| 7981 | item specified here, the size of each entry will be inflated so |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 7982 | that the additional data can fit. Several data types may be |
| 7983 | stored with an entry. Multiple data types may be specified after |
| 7984 | the "store" keyword, as a comma-separated list. Alternatively, |
| 7985 | it is possible to repeat the "store" keyword followed by one or |
| 7986 | several data types. Except for the "server_id" type which is |
| 7987 | automatically detected and enabled, all data types must be |
| 7988 | explicitly declared to be stored. If an ACL references a data |
| 7989 | type which is not stored, the ACL will simply not match. Some |
| 7990 | data types require an argument which must be passed just after |
| 7991 | the type between parenthesis. See below for the supported data |
| 7992 | types and their arguments. |
| 7993 | |
| 7994 | The data types that can be stored with an entry are the following : |
| 7995 | - server_id : this is an integer which holds the numeric ID of the server a |
| 7996 | request was assigned to. It is used by the "stick match", "stick store", |
| 7997 | and "stick on" rules. It is automatically enabled when referenced. |
| 7998 | |
| 7999 | - gpc0 : first General Purpose Counter. It is a positive 32-bit integer |
| 8000 | integer which may be used for anything. Most of the time it will be used |
| 8001 | to put a special tag on some entries, for instance to note that a |
| 8002 | specific behaviour was detected and must be known for future matches. |
| 8003 | |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 8004 | - gpc0_rate(<period>) : increment rate of the first General Purpose Counter |
| 8005 | over a period. It is a positive 32-bit integer integer which may be used |
| 8006 | for anything. Just like <gpc0>, it counts events, but instead of keeping |
| 8007 | a cumulative count, it maintains the rate at which the counter is |
| 8008 | incremented. Most of the time it will be used to measure the frequency of |
| 8009 | occurrence of certain events (eg: requests to a specific URL). |
| 8010 | |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 8011 | - conn_cnt : Connection Count. It is a positive 32-bit integer which counts |
| 8012 | the absolute number of connections received from clients which matched |
| 8013 | this entry. It does not mean the connections were accepted, just that |
| 8014 | they were received. |
| 8015 | |
| 8016 | - conn_cur : Current Connections. It is a positive 32-bit integer which |
| 8017 | stores the concurrent connection counts for the entry. It is incremented |
| 8018 | once an incoming connection matches the entry, and decremented once the |
| 8019 | connection leaves. That way it is possible to know at any time the exact |
| 8020 | number of concurrent connections for an entry. |
| 8021 | |
| 8022 | - conn_rate(<period>) : frequency counter (takes 12 bytes). It takes an |
| 8023 | integer parameter <period> which indicates in milliseconds the length |
| 8024 | of the period over which the average is measured. It reports the average |
| 8025 | incoming connection rate over that period, in connections per period. The |
| 8026 | result is an integer which can be matched using ACLs. |
| 8027 | |
| 8028 | - sess_cnt : Session Count. It is a positive 32-bit integer which counts |
| 8029 | the absolute number of sessions received from clients which matched this |
| 8030 | entry. A session is a connection that was accepted by the layer 4 rules. |
| 8031 | |
| 8032 | - sess_rate(<period>) : frequency counter (takes 12 bytes). It takes an |
| 8033 | integer parameter <period> which indicates in milliseconds the length |
| 8034 | of the period over which the average is measured. It reports the average |
| 8035 | incoming session rate over that period, in sessions per period. The |
| 8036 | result is an integer which can be matched using ACLs. |
| 8037 | |
| 8038 | - http_req_cnt : HTTP request Count. It is a positive 32-bit integer which |
| 8039 | counts the absolute number of HTTP requests received from clients which |
| 8040 | matched this entry. It does not matter whether they are valid requests or |
| 8041 | not. Note that this is different from sessions when keep-alive is used on |
| 8042 | the client side. |
| 8043 | |
| 8044 | - http_req_rate(<period>) : frequency counter (takes 12 bytes). It takes an |
| 8045 | integer parameter <period> which indicates in milliseconds the length |
| 8046 | of the period over which the average is measured. It reports the average |
| 8047 | HTTP request rate over that period, in requests per period. The result is |
| 8048 | an integer which can be matched using ACLs. It does not matter whether |
| 8049 | they are valid requests or not. Note that this is different from sessions |
| 8050 | when keep-alive is used on the client side. |
| 8051 | |
| 8052 | - http_err_cnt : HTTP Error Count. It is a positive 32-bit integer which |
| 8053 | counts the absolute number of HTTP requests errors induced by clients |
| 8054 | which matched this entry. Errors are counted on invalid and truncated |
| 8055 | requests, as well as on denied or tarpitted requests, and on failed |
| 8056 | authentications. If the server responds with 4xx, then the request is |
| 8057 | also counted as an error since it's an error triggered by the client |
| 8058 | (eg: vulnerability scan). |
| 8059 | |
| 8060 | - http_err_rate(<period>) : frequency counter (takes 12 bytes). It takes an |
| 8061 | integer parameter <period> which indicates in milliseconds the length |
| 8062 | of the period over which the average is measured. It reports the average |
| 8063 | HTTP request error rate over that period, in requests per period (see |
| 8064 | http_err_cnt above for what is accounted as an error). The result is an |
| 8065 | integer which can be matched using ACLs. |
| 8066 | |
| 8067 | - bytes_in_cnt : client to server byte count. It is a positive 64-bit |
| 8068 | integer which counts the cumulated amount of bytes received from clients |
| 8069 | which matched this entry. Headers are included in the count. This may be |
| 8070 | used to limit abuse of upload features on photo or video servers. |
| 8071 | |
| 8072 | - bytes_in_rate(<period>) : frequency counter (takes 12 bytes). It takes an |
| 8073 | integer parameter <period> which indicates in milliseconds the length |
| 8074 | of the period over which the average is measured. It reports the average |
| 8075 | incoming bytes rate over that period, in bytes per period. It may be used |
| 8076 | to detect users which upload too much and too fast. Warning: with large |
| 8077 | uploads, it is possible that the amount of uploaded data will be counted |
| 8078 | once upon termination, thus causing spikes in the average transfer speed |
| 8079 | instead of having a smooth one. This may partially be smoothed with |
| 8080 | "option contstats" though this is not perfect yet. Use of byte_in_cnt is |
| 8081 | recommended for better fairness. |
| 8082 | |
| 8083 | - bytes_out_cnt : server to client byte count. It is a positive 64-bit |
| 8084 | integer which counts the cumulated amount of bytes sent to clients which |
| 8085 | matched this entry. Headers are included in the count. This may be used |
| 8086 | to limit abuse of bots sucking the whole site. |
| 8087 | |
| 8088 | - bytes_out_rate(<period>) : frequency counter (takes 12 bytes). It takes |
| 8089 | an integer parameter <period> which indicates in milliseconds the length |
| 8090 | of the period over which the average is measured. It reports the average |
| 8091 | outgoing bytes rate over that period, in bytes per period. It may be used |
| 8092 | to detect users which download too much and too fast. Warning: with large |
| 8093 | transfers, it is possible that the amount of transferred data will be |
| 8094 | counted once upon termination, thus causing spikes in the average |
| 8095 | transfer speed instead of having a smooth one. This may partially be |
| 8096 | smoothed with "option contstats" though this is not perfect yet. Use of |
| 8097 | byte_out_cnt is recommended for better fairness. |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 8098 | |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 8099 | There is only one stick-table per proxy. At the moment of writing this doc, |
| 8100 | it does not seem useful to have multiple tables per proxy. If this happens |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 8101 | to be required, simply create a dummy backend with a stick-table in it and |
| 8102 | reference it. |
| 8103 | |
| 8104 | It is important to understand that stickiness based on learning information |
| 8105 | has some limitations, including the fact that all learned associations are |
| 8106 | lost upon restart. In general it can be good as a complement but not always |
| 8107 | as an exclusive stickiness. |
| 8108 | |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 8109 | Last, memory requirements may be important when storing many data types. |
| 8110 | Indeed, storing all indicators above at once in each entry requires 116 bytes |
| 8111 | per entry, or 116 MB for a 1-million entries table. This is definitely not |
| 8112 | something that can be ignored. |
| 8113 | |
| 8114 | Example: |
| 8115 | # Keep track of counters of up to 1 million IP addresses over 5 minutes |
| 8116 | # and store a general purpose counter and the average connection rate |
| 8117 | # computed over a sliding window of 30 seconds. |
| 8118 | stick-table type ip size 1m expire 5m store gpc0,conn_rate(30s) |
| 8119 | |
| 8120 | See also : "stick match", "stick on", "stick store-request", section 2.2 |
David du Colombier | a13d1b9 | 2011-03-17 10:40:22 +0100 | [diff] [blame] | 8121 | about time format and section 7 about ACLs. |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 8122 | |
| 8123 | |
Emeric Brun | 6a1cefa | 2010-09-24 18:15:17 +0200 | [diff] [blame] | 8124 | stick store-response <pattern> [table <table>] [{if | unless} <condition>] |
| 8125 | Define a request pattern used to create an entry in a stickiness table |
| 8126 | May be used in sections : defaults | frontend | listen | backend |
| 8127 | no | no | yes | yes |
| 8128 | |
| 8129 | Arguments : |
Willy Tarreau | be722a2 | 2014-06-13 16:31:59 +0200 | [diff] [blame] | 8130 | <pattern> is a sample expression rule as described in section 7.3. It |
Emeric Brun | 6a1cefa | 2010-09-24 18:15:17 +0200 | [diff] [blame] | 8131 | describes what elements of the response or connection will |
| 8132 | be analysed, extracted and stored in the table once a |
| 8133 | server is selected. |
| 8134 | |
| 8135 | <table> is an optional stickiness table name. If unspecified, the same |
| 8136 | backend's table is used. A stickiness table is declared using |
| 8137 | the "stick-table" statement. |
| 8138 | |
| 8139 | <cond> is an optional storage condition. It makes it possible to store |
| 8140 | certain criteria only when some conditions are met (or not met). |
| 8141 | For instance, it could be used to store the SSL session ID only |
| 8142 | when the response is a SSL server hello. |
| 8143 | |
| 8144 | Some protocols or applications require complex stickiness rules and cannot |
| 8145 | always simply rely on cookies nor hashing. The "stick store-response" |
| 8146 | statement describes a rule to decide what to extract from the response and |
| 8147 | when to do it, in order to store it into a stickiness table for further |
| 8148 | requests to match it using the "stick match" statement. Obviously the |
| 8149 | extracted part must make sense and have a chance to be matched in a further |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 8150 | request. Storing an ID found in a header of a response makes sense. |
Emeric Brun | 6a1cefa | 2010-09-24 18:15:17 +0200 | [diff] [blame] | 8151 | See section 7 for a complete list of possible patterns and transformation |
| 8152 | rules. |
| 8153 | |
| 8154 | The table has to be declared using the "stick-table" statement. It must be of |
| 8155 | a type compatible with the pattern. By default it is the one which is present |
| 8156 | in the same backend. It is possible to share a table with other backends by |
| 8157 | referencing it using the "table" keyword. If another table is referenced, |
| 8158 | the server's ID inside the backends are used. By default, all server IDs |
| 8159 | start at 1 in each backend, so the server ordering is enough. But in case of |
| 8160 | doubt, it is highly recommended to force server IDs using their "id" setting. |
| 8161 | |
| 8162 | It is possible to restrict the conditions where a "stick store-response" |
| 8163 | statement will apply, using "if" or "unless" followed by a condition. This |
| 8164 | condition will be evaluated while parsing the response, so any criteria can |
| 8165 | be used. See section 7 for ACL based conditions. |
| 8166 | |
| 8167 | There is no limit on the number of "stick store-response" statements, but |
| 8168 | there is a limit of 8 simultaneous stores per request or response. This |
| 8169 | makes it possible to store up to 8 criteria, all extracted from either the |
| 8170 | request or the response, regardless of the number of rules. Only the 8 first |
| 8171 | ones which match will be kept. Using this, it is possible to feed multiple |
| 8172 | tables at once in the hope to increase the chance to recognize a user on |
Willy Tarreau | 9667a80 | 2013-12-09 12:52:13 +0100 | [diff] [blame] | 8173 | another protocol or access method. Using multiple store-response rules with |
| 8174 | the same table is possible and may be used to find the best criterion to rely |
| 8175 | on, by arranging the rules by decreasing preference order. Only the first |
| 8176 | extracted criterion for a given table will be stored. All subsequent store- |
| 8177 | response rules referencing the same table will be skipped and their ACLs will |
| 8178 | not be evaluated. However, even if a store-request rule references a table, a |
| 8179 | store-response rule may also use the same table. This means that each table |
| 8180 | may learn exactly one element from the request and one element from the |
| 8181 | response at once. |
Emeric Brun | 6a1cefa | 2010-09-24 18:15:17 +0200 | [diff] [blame] | 8182 | |
| 8183 | The table will contain the real server that processed the request. |
| 8184 | |
| 8185 | Example : |
| 8186 | # Learn SSL session ID from both request and response and create affinity. |
| 8187 | backend https |
| 8188 | mode tcp |
| 8189 | balance roundrobin |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 8190 | # maximum SSL session ID length is 32 bytes. |
Emeric Brun | 6a1cefa | 2010-09-24 18:15:17 +0200 | [diff] [blame] | 8191 | stick-table type binary len 32 size 30k expire 30m |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 8192 | |
Emeric Brun | 6a1cefa | 2010-09-24 18:15:17 +0200 | [diff] [blame] | 8193 | acl clienthello req_ssl_hello_type 1 |
| 8194 | acl serverhello rep_ssl_hello_type 2 |
| 8195 | |
| 8196 | # use tcp content accepts to detects ssl client and server hello. |
| 8197 | tcp-request inspect-delay 5s |
| 8198 | tcp-request content accept if clienthello |
| 8199 | |
| 8200 | # no timeout on response inspect delay by default. |
| 8201 | tcp-response content accept if serverhello |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 8202 | |
Emeric Brun | 6a1cefa | 2010-09-24 18:15:17 +0200 | [diff] [blame] | 8203 | # SSL session ID (SSLID) may be present on a client or server hello. |
| 8204 | # Its length is coded on 1 byte at offset 43 and its value starts |
| 8205 | # at offset 44. |
| 8206 | |
| 8207 | # Match and learn on request if client hello. |
| 8208 | stick on payload_lv(43,1) if clienthello |
| 8209 | |
| 8210 | # Learn on response if server hello. |
| 8211 | stick store-response payload_lv(43,1) if serverhello |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 8212 | |
Emeric Brun | 6a1cefa | 2010-09-24 18:15:17 +0200 | [diff] [blame] | 8213 | server s1 192.168.1.1:443 |
| 8214 | server s2 192.168.1.1:443 |
| 8215 | |
| 8216 | See also : "stick-table", "stick on", and section 7 about ACLs and pattern |
| 8217 | extraction. |
| 8218 | |
| 8219 | |
Willy Tarreau | 938c7fe | 2014-04-25 14:21:39 +0200 | [diff] [blame] | 8220 | tcp-check connect [params*] |
| 8221 | Opens a new connection |
| 8222 | May be used in sections: defaults | frontend | listen | backend |
| 8223 | no | no | yes | yes |
| 8224 | |
| 8225 | When an application lies on more than a single TCP port or when HAProxy |
| 8226 | load-balance many services in a single backend, it makes sense to probe all |
| 8227 | the services individually before considering a server as operational. |
| 8228 | |
| 8229 | When there are no TCP port configured on the server line neither server port |
| 8230 | directive, then the 'tcp-check connect port <port>' must be the first step |
| 8231 | of the sequence. |
| 8232 | |
| 8233 | In a tcp-check ruleset a 'connect' is required, it is also mandatory to start |
| 8234 | the ruleset with a 'connect' rule. Purpose is to ensure admin know what they |
| 8235 | do. |
| 8236 | |
| 8237 | Parameters : |
| 8238 | They are optional and can be used to describe how HAProxy should open and |
| 8239 | use the TCP connection. |
| 8240 | |
| 8241 | port if not set, check port or server port is used. |
| 8242 | It tells HAProxy where to open the connection to. |
| 8243 | <port> must be a valid TCP port source integer, from 1 to 65535. |
| 8244 | |
| 8245 | send-proxy send a PROXY protocol string |
| 8246 | |
| 8247 | ssl opens a ciphered connection |
| 8248 | |
| 8249 | Examples: |
| 8250 | # check HTTP and HTTPs services on a server. |
| 8251 | # first open port 80 thanks to server line port directive, then |
| 8252 | # tcp-check opens port 443, ciphered and run a request on it: |
| 8253 | option tcp-check |
| 8254 | tcp-check connect |
| 8255 | tcp-check send GET\ /\ HTTP/1.0\r\n |
| 8256 | tcp-check send Host:\ haproxy.1wt.eu\r\n |
| 8257 | tcp-check send \r\n |
| 8258 | tcp-check expect rstring (2..|3..) |
| 8259 | tcp-check connect port 443 ssl |
| 8260 | tcp-check send GET\ /\ HTTP/1.0\r\n |
| 8261 | tcp-check send Host:\ haproxy.1wt.eu\r\n |
| 8262 | tcp-check send \r\n |
| 8263 | tcp-check expect rstring (2..|3..) |
| 8264 | server www 10.0.0.1 check port 80 |
| 8265 | |
| 8266 | # check both POP and IMAP from a single server: |
| 8267 | option tcp-check |
| 8268 | tcp-check connect port 110 |
| 8269 | tcp-check expect string +OK\ POP3\ ready |
| 8270 | tcp-check connect port 143 |
| 8271 | tcp-check expect string *\ OK\ IMAP4\ ready |
| 8272 | server mail 10.0.0.1 check |
| 8273 | |
| 8274 | See also : "option tcp-check", "tcp-check send", "tcp-check expect" |
| 8275 | |
| 8276 | |
| 8277 | tcp-check expect [!] <match> <pattern> |
| 8278 | Specify data to be collected and analysed during a generic health check |
| 8279 | May be used in sections: defaults | frontend | listen | backend |
| 8280 | no | no | yes | yes |
| 8281 | |
| 8282 | Arguments : |
| 8283 | <match> is a keyword indicating how to look for a specific pattern in the |
| 8284 | response. The keyword may be one of "string", "rstring" or |
| 8285 | binary. |
| 8286 | The keyword may be preceded by an exclamation mark ("!") to negate |
| 8287 | the match. Spaces are allowed between the exclamation mark and the |
| 8288 | keyword. See below for more details on the supported keywords. |
| 8289 | |
| 8290 | <pattern> is the pattern to look for. It may be a string or a regular |
| 8291 | expression. If the pattern contains spaces, they must be escaped |
| 8292 | with the usual backslash ('\'). |
| 8293 | If the match is set to binary, then the pattern must be passed as |
| 8294 | a serie of hexadecimal digits in an even number. Each sequence of |
| 8295 | two digits will represent a byte. The hexadecimal digits may be |
| 8296 | used upper or lower case. |
| 8297 | |
| 8298 | |
| 8299 | The available matches are intentionally similar to their http-check cousins : |
| 8300 | |
| 8301 | string <string> : test the exact string matches in the response buffer. |
| 8302 | A health check response will be considered valid if the |
| 8303 | response's buffer contains this exact string. If the |
| 8304 | "string" keyword is prefixed with "!", then the response |
| 8305 | will be considered invalid if the body contains this |
| 8306 | string. This can be used to look for a mandatory pattern |
| 8307 | in a protocol response, or to detect a failure when a |
| 8308 | specific error appears in a protocol banner. |
| 8309 | |
| 8310 | rstring <regex> : test a regular expression on the response buffer. |
| 8311 | A health check response will be considered valid if the |
| 8312 | response's buffer matches this expression. If the |
| 8313 | "rstring" keyword is prefixed with "!", then the response |
| 8314 | will be considered invalid if the body matches the |
| 8315 | expression. |
| 8316 | |
| 8317 | binary <hexstring> : test the exact string in its hexadecimal form matches |
| 8318 | in the response buffer. A health check response will |
| 8319 | be considered valid if the response's buffer contains |
| 8320 | this exact hexadecimal string. |
| 8321 | Purpose is to match data on binary protocols. |
| 8322 | |
| 8323 | It is important to note that the responses will be limited to a certain size |
| 8324 | defined by the global "tune.chksize" option, which defaults to 16384 bytes. |
| 8325 | Thus, too large responses may not contain the mandatory pattern when using |
| 8326 | "string", "rstring" or binary. If a large response is absolutely required, it |
| 8327 | is possible to change the default max size by setting the global variable. |
| 8328 | However, it is worth keeping in mind that parsing very large responses can |
| 8329 | waste some CPU cycles, especially when regular expressions are used, and that |
| 8330 | it is always better to focus the checks on smaller resources. Also, in its |
| 8331 | current state, the check will not find any string nor regex past a null |
| 8332 | character in the response. Similarly it is not possible to request matching |
| 8333 | the null character. |
| 8334 | |
| 8335 | Examples : |
| 8336 | # perform a POP check |
| 8337 | option tcp-check |
| 8338 | tcp-check expect string +OK\ POP3\ ready |
| 8339 | |
| 8340 | # perform an IMAP check |
| 8341 | option tcp-check |
| 8342 | tcp-check expect string *\ OK\ IMAP4\ ready |
| 8343 | |
| 8344 | # look for the redis master server |
| 8345 | option tcp-check |
| 8346 | tcp-check send PING\r\n |
Baptiste Assmann | a332299 | 2015-08-04 10:12:18 +0200 | [diff] [blame] | 8347 | tcp-check expect string +PONG |
Willy Tarreau | 938c7fe | 2014-04-25 14:21:39 +0200 | [diff] [blame] | 8348 | tcp-check send info\ replication\r\n |
| 8349 | tcp-check expect string role:master |
| 8350 | tcp-check send QUIT\r\n |
| 8351 | tcp-check expect string +OK |
| 8352 | |
| 8353 | |
| 8354 | See also : "option tcp-check", "tcp-check connect", "tcp-check send", |
| 8355 | "tcp-check send-binary", "http-check expect", tune.chksize |
| 8356 | |
| 8357 | |
| 8358 | tcp-check send <data> |
| 8359 | Specify a string to be sent as a question during a generic health check |
| 8360 | May be used in sections: defaults | frontend | listen | backend |
| 8361 | no | no | yes | yes |
| 8362 | |
| 8363 | <data> : the data to be sent as a question during a generic health check |
| 8364 | session. For now, <data> must be a string. |
| 8365 | |
| 8366 | Examples : |
| 8367 | # look for the redis master server |
| 8368 | option tcp-check |
| 8369 | tcp-check send info\ replication\r\n |
| 8370 | tcp-check expect string role:master |
| 8371 | |
| 8372 | See also : "option tcp-check", "tcp-check connect", "tcp-check expect", |
| 8373 | "tcp-check send-binary", tune.chksize |
| 8374 | |
| 8375 | |
| 8376 | tcp-check send-binary <hexastring> |
| 8377 | Specify an hexa digits string to be sent as a binary question during a raw |
| 8378 | tcp health check |
| 8379 | May be used in sections: defaults | frontend | listen | backend |
| 8380 | no | no | yes | yes |
| 8381 | |
| 8382 | <data> : the data to be sent as a question during a generic health check |
| 8383 | session. For now, <data> must be a string. |
| 8384 | <hexastring> : test the exact string in its hexadecimal form matches in the |
| 8385 | response buffer. A health check response will be considered |
| 8386 | valid if the response's buffer contains this exact |
| 8387 | hexadecimal string. |
| 8388 | Purpose is to send binary data to ask on binary protocols. |
| 8389 | |
| 8390 | Examples : |
| 8391 | # redis check in binary |
| 8392 | option tcp-check |
| 8393 | tcp-check send-binary 50494e470d0a # PING\r\n |
| 8394 | tcp-check expect binary 2b504F4e47 # +PONG |
| 8395 | |
| 8396 | |
| 8397 | See also : "option tcp-check", "tcp-check connect", "tcp-check expect", |
| 8398 | "tcp-check send", tune.chksize |
| 8399 | |
| 8400 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8401 | tcp-request connection <action> [{if | unless} <condition>] |
| 8402 | Perform an action on an incoming connection depending on a layer 4 condition |
Willy Tarreau | 1a68794 | 2010-05-23 22:40:30 +0200 | [diff] [blame] | 8403 | May be used in sections : defaults | frontend | listen | backend |
| 8404 | no | yes | yes | no |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8405 | Arguments : |
| 8406 | <action> defines the action to perform if the condition applies. Valid |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8407 | actions include : "accept", "reject", "track-sc0", "track-sc1", |
| 8408 | "track-sc2", and "expect-proxy". See below for more details. |
Willy Tarreau | 1a68794 | 2010-05-23 22:40:30 +0200 | [diff] [blame] | 8409 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8410 | <condition> is a standard layer4-only ACL-based condition (see section 7). |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8411 | |
| 8412 | Immediately after acceptance of a new incoming connection, it is possible to |
| 8413 | evaluate some conditions to decide whether this connection must be accepted |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8414 | or dropped or have its counters tracked. Those conditions cannot make use of |
| 8415 | any data contents because the connection has not been read from yet, and the |
| 8416 | buffers are not yet allocated. This is used to selectively and very quickly |
| 8417 | accept or drop connections from various sources with a very low overhead. If |
| 8418 | some contents need to be inspected in order to take the decision, the |
| 8419 | "tcp-request content" statements must be used instead. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8420 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8421 | The "tcp-request connection" rules are evaluated in their exact declaration |
| 8422 | order. If no rule matches or if there is no rule, the default action is to |
| 8423 | accept the incoming connection. There is no specific limit to the number of |
| 8424 | rules which may be inserted. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8425 | |
Willy Tarreau | a9083d0 | 2015-05-08 15:27:59 +0200 | [diff] [blame] | 8426 | Four types of actions are supported : |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8427 | - accept : |
| 8428 | accepts the connection if the condition is true (when used with "if") |
| 8429 | or false (when used with "unless"). The first such rule executed ends |
| 8430 | the rules evaluation. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8431 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8432 | - reject : |
| 8433 | rejects the connection if the condition is true (when used with "if") |
| 8434 | or false (when used with "unless"). The first such rule executed ends |
| 8435 | the rules evaluation. Rejected connections do not even become a |
| 8436 | session, which is why they are accounted separately for in the stats, |
| 8437 | as "denied connections". They are not considered for the session |
| 8438 | rate-limit and are not logged either. The reason is that these rules |
| 8439 | should only be used to filter extremely high connection rates such as |
| 8440 | the ones encountered during a massive DDoS attack. Under these extreme |
| 8441 | conditions, the simple action of logging each event would make the |
| 8442 | system collapse and would considerably lower the filtering capacity. If |
| 8443 | logging is absolutely desired, then "tcp-request content" rules should |
| 8444 | be used instead. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8445 | |
Willy Tarreau | 4f0d919 | 2013-06-11 20:40:55 +0200 | [diff] [blame] | 8446 | - expect-proxy layer4 : |
| 8447 | configures the client-facing connection to receive a PROXY protocol |
| 8448 | header before any byte is read from the socket. This is equivalent to |
| 8449 | having the "accept-proxy" keyword on the "bind" line, except that using |
| 8450 | the TCP rule allows the PROXY protocol to be accepted only for certain |
| 8451 | IP address ranges using an ACL. This is convenient when multiple layers |
| 8452 | of load balancers are passed through by traffic coming from public |
| 8453 | hosts. |
| 8454 | |
Willy Tarreau | 18bf01e | 2014-06-13 16:18:52 +0200 | [diff] [blame] | 8455 | - capture <sample> len <length> : |
| 8456 | This only applies to "tcp-request content" rules. It captures sample |
| 8457 | expression <sample> from the request buffer, and converts it to a |
| 8458 | string of at most <len> characters. The resulting string is stored into |
| 8459 | the next request "capture" slot, so it will possibly appear next to |
| 8460 | some captured HTTP headers. It will then automatically appear in the |
| 8461 | logs, and it will be possible to extract it using sample fetch rules to |
| 8462 | feed it into headers or anything. The length should be limited given |
| 8463 | that this size will be allocated for each capture during the whole |
Willy Tarreau | a9083d0 | 2015-05-08 15:27:59 +0200 | [diff] [blame] | 8464 | session life. Please check section 7.3 (Fetching samples) and "capture |
| 8465 | request header" for more information. |
Willy Tarreau | 18bf01e | 2014-06-13 16:18:52 +0200 | [diff] [blame] | 8466 | |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8467 | - { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] : |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8468 | enables tracking of sticky counters from current connection. These |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8469 | rules do not stop evaluation and do not change default action. 3 sets |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8470 | of counters may be simultaneously tracked by the same connection. The |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8471 | first "track-sc0" rule executed enables tracking of the counters of the |
| 8472 | specified table as the first set. The first "track-sc1" rule executed |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8473 | enables tracking of the counters of the specified table as the second |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8474 | set. The first "track-sc2" rule executed enables tracking of the |
| 8475 | counters of the specified table as the third set. It is a recommended |
| 8476 | practice to use the first set of counters for the per-frontend counters |
| 8477 | and the second set for the per-backend ones. But this is just a |
| 8478 | guideline, all may be used everywhere. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8479 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8480 | These actions take one or two arguments : |
Willy Tarreau | be722a2 | 2014-06-13 16:31:59 +0200 | [diff] [blame] | 8481 | <key> is mandatory, and is a sample expression rule as described |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 8482 | in section 7.3. It describes what elements of the incoming |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 8483 | request or connection will be analysed, extracted, combined, |
| 8484 | and used to select which table entry to update the counters. |
| 8485 | Note that "tcp-request connection" cannot use content-based |
| 8486 | fetches. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8487 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8488 | <table> is an optional table to be used instead of the default one, |
| 8489 | which is the stick-table declared in the current proxy. All |
| 8490 | the counters for the matches and updates for the key will |
| 8491 | then be performed in that table until the session ends. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8492 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8493 | Once a "track-sc*" rule is executed, the key is looked up in the table |
| 8494 | and if it is not found, an entry is allocated for it. Then a pointer to |
| 8495 | that entry is kept during all the session's life, and this entry's |
| 8496 | counters are updated as often as possible, every time the session's |
| 8497 | counters are updated, and also systematically when the session ends. |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 8498 | Counters are only updated for events that happen after the tracking has |
| 8499 | been started. For example, connection counters will not be updated when |
| 8500 | tracking layer 7 information, since the connection event happens before |
| 8501 | layer7 information is extracted. |
| 8502 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8503 | If the entry tracks concurrent connection counters, one connection is |
| 8504 | counted for as long as the entry is tracked, and the entry will not |
| 8505 | expire during that time. Tracking counters also provides a performance |
| 8506 | advantage over just checking the keys, because only one table lookup is |
| 8507 | performed for all ACL checks that make use of it. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8508 | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 8509 | - sc-inc-gpc0(<sc-id>): |
| 8510 | The "sc-inc-gpc0" increments the GPC0 counter according to the sticky |
| 8511 | counter designated by <sc-id>. If an error occurs, this action silently |
| 8512 | fails and the actions evaluation continues. |
| 8513 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 8514 | - sc-set-gpt0(<sc-id>) <int>: |
| 8515 | This action sets the GPT0 tag according to the sticky counter designated |
| 8516 | by <sc-id> and the value of <int>. The expected result is a boolean. If |
| 8517 | an error occurs, this action silently fails and the actions evaluation |
| 8518 | continues. |
| 8519 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8520 | Note that the "if/unless" condition is optional. If no condition is set on |
| 8521 | the action, it is simply performed unconditionally. That can be useful for |
| 8522 | "track-sc*" actions as well as for changing the default action to a reject. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8523 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8524 | Example: accept all connections from white-listed hosts, reject too fast |
| 8525 | connection without counting them, and track accepted connections. |
| 8526 | This results in connection rate being capped from abusive sources. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8527 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8528 | tcp-request connection accept if { src -f /etc/haproxy/whitelist.lst } |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8529 | tcp-request connection reject if { src_conn_rate gt 10 } |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8530 | tcp-request connection track-sc0 src |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8531 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8532 | Example: accept all connections from white-listed hosts, count all other |
| 8533 | connections and reject too fast ones. This results in abusive ones |
| 8534 | being blocked as long as they don't slow down. |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8535 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8536 | tcp-request connection accept if { src -f /etc/haproxy/whitelist.lst } |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8537 | tcp-request connection track-sc0 src |
| 8538 | tcp-request connection reject if { sc0_conn_rate gt 10 } |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8539 | |
Willy Tarreau | 4f0d919 | 2013-06-11 20:40:55 +0200 | [diff] [blame] | 8540 | Example: enable the PROXY protocol for traffic coming from all known proxies. |
| 8541 | |
| 8542 | tcp-request connection expect-proxy layer4 if { src -f proxies.lst } |
| 8543 | |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8544 | See section 7 about ACL usage. |
| 8545 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8546 | See also : "tcp-request content", "stick-table" |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8547 | |
| 8548 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8549 | tcp-request content <action> [{if | unless} <condition>] |
| 8550 | Perform an action on a new session depending on a layer 4-7 condition |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8551 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8552 | no | yes | yes | yes |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8553 | Arguments : |
| 8554 | <action> defines the action to perform if the condition applies. Valid |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8555 | actions include : "accept", "reject", "track-sc0", "track-sc1", |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 8556 | "track-sc2", "sc-inc-gpc0", "sc-set-gpt0", "capture" and "lua". |
| 8557 | See "tcp-request connection" above for their signification. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8558 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8559 | <condition> is a standard layer 4-7 ACL-based condition (see section 7). |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8560 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8561 | A request's contents can be analysed at an early stage of request processing |
| 8562 | called "TCP content inspection". During this stage, ACL-based rules are |
| 8563 | evaluated every time the request contents are updated, until either an |
| 8564 | "accept" or a "reject" rule matches, or the TCP request inspection delay |
| 8565 | expires with no matching rule. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8566 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8567 | The first difference between these rules and "tcp-request connection" rules |
| 8568 | is that "tcp-request content" rules can make use of contents to take a |
| 8569 | decision. Most often, these decisions will consider a protocol recognition or |
| 8570 | validity. The second difference is that content-based rules can be used in |
Willy Tarreau | f333834 | 2014-01-28 21:40:28 +0100 | [diff] [blame] | 8571 | both frontends and backends. In case of HTTP keep-alive with the client, all |
| 8572 | tcp-request content rules are evaluated again, so haproxy keeps a record of |
| 8573 | what sticky counters were assigned by a "tcp-request connection" versus a |
| 8574 | "tcp-request content" rule, and flushes all the content-related ones after |
| 8575 | processing an HTTP request, so that they may be evaluated again by the rules |
| 8576 | being evaluated again for the next request. This is of particular importance |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 8577 | when the rule tracks some L7 information or when it is conditioned by an |
Willy Tarreau | f333834 | 2014-01-28 21:40:28 +0100 | [diff] [blame] | 8578 | L7-based ACL, since tracking may change between requests. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8579 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8580 | Content-based rules are evaluated in their exact declaration order. If no |
| 8581 | rule matches or if there is no rule, the default action is to accept the |
| 8582 | contents. There is no specific limit to the number of rules which may be |
| 8583 | inserted. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8584 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 8585 | Several types of actions are supported : |
Willy Tarreau | 18bf01e | 2014-06-13 16:18:52 +0200 | [diff] [blame] | 8586 | - accept : the request is accepted |
| 8587 | - reject : the request is rejected and the connection is closed |
| 8588 | - capture : the specified sample expression is captured |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8589 | - { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 8590 | - sc-inc-gpc0(<sc-id>) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 8591 | - set-gpt0(<sc-id>) <int> |
Thierry FOURNIER | 69717b4 | 2015-06-04 12:23:41 +0200 | [diff] [blame] | 8592 | - lua <function> |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 8593 | - set-var(<var-name>) <expr> |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8594 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8595 | They have the same meaning as their counter-parts in "tcp-request connection" |
| 8596 | so please refer to that section for a complete description. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8597 | |
Willy Tarreau | f333834 | 2014-01-28 21:40:28 +0100 | [diff] [blame] | 8598 | While there is nothing mandatory about it, it is recommended to use the |
| 8599 | track-sc0 in "tcp-request connection" rules, track-sc1 for "tcp-request |
| 8600 | content" rules in the frontend, and track-sc2 for "tcp-request content" |
| 8601 | rules in the backend, because that makes the configuration more readable |
| 8602 | and easier to troubleshoot, but this is just a guideline and all counters |
| 8603 | may be used everywhere. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8604 | |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 8605 | Note that the "if/unless" condition is optional. If no condition is set on |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8606 | the action, it is simply performed unconditionally. That can be useful for |
| 8607 | "track-sc*" actions as well as for changing the default action to a reject. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8608 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8609 | It is perfectly possible to match layer 7 contents with "tcp-request content" |
Willy Tarreau | c0239e0 | 2012-04-16 14:42:55 +0200 | [diff] [blame] | 8610 | rules, since HTTP-specific ACL matches are able to preliminarily parse the |
| 8611 | contents of a buffer before extracting the required data. If the buffered |
| 8612 | contents do not parse as a valid HTTP message, then the ACL does not match. |
| 8613 | The parser which is involved there is exactly the same as for all other HTTP |
Willy Tarreau | f333834 | 2014-01-28 21:40:28 +0100 | [diff] [blame] | 8614 | processing, so there is no risk of parsing something differently. In an HTTP |
| 8615 | backend connected to from an HTTP frontend, it is guaranteed that HTTP |
| 8616 | contents will always be immediately present when the rule is evaluated first. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8617 | |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 8618 | Tracking layer7 information is also possible provided that the information |
Willy Tarreau | 4d54c7c | 2014-09-16 15:48:15 +0200 | [diff] [blame] | 8619 | are present when the rule is processed. The rule processing engine is able to |
| 8620 | wait until the inspect delay expires when the data to be tracked is not yet |
| 8621 | available. |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 8622 | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 8623 | The "lua" keyword is followed by a Lua function name. It is used to run a Lua |
| 8624 | function if the action is executed. The single parameter is the name of the |
| 8625 | function to run. The prototype of the function is documented in the API |
| 8626 | documentation. |
| 8627 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 8628 | The "set-var" is used to set the content of a variable. The variable is |
| 8629 | declared inline. |
| 8630 | |
| 8631 | <var-name> The name of the variable starts by an indication about its scope. |
| 8632 | The allowed scopes are: |
| 8633 | "sess" : the variable is shared with all the session, |
| 8634 | "txn" : the variable is shared with all the transaction |
| 8635 | (request and response) |
| 8636 | "req" : the variable is shared only during the request |
| 8637 | processing |
| 8638 | "res" : the variable is shared only during the response |
| 8639 | processing. |
| 8640 | This prefix is followed by a name. The separator is a '.'. |
| 8641 | The name may only contain characters 'a-z', 'A-Z', '0-9' and '_'. |
| 8642 | |
| 8643 | <expr> Is a standard HAProxy expression formed by a sample-fetch |
| 8644 | followed by some converters. |
| 8645 | |
| 8646 | Example: |
| 8647 | |
| 8648 | tcp-request content set-var(sess.my_var) src |
| 8649 | |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8650 | Example: |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8651 | # Accept HTTP requests containing a Host header saying "example.com" |
| 8652 | # and reject everything else. |
| 8653 | acl is_host_com hdr(Host) -i example.com |
| 8654 | tcp-request inspect-delay 30s |
Willy Tarreau | c0239e0 | 2012-04-16 14:42:55 +0200 | [diff] [blame] | 8655 | tcp-request content accept if is_host_com |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8656 | tcp-request content reject |
| 8657 | |
| 8658 | Example: |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8659 | # reject SMTP connection if client speaks first |
| 8660 | tcp-request inspect-delay 30s |
| 8661 | acl content_present req_len gt 0 |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8662 | tcp-request content reject if content_present |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8663 | |
| 8664 | # Forward HTTPS connection only if client speaks |
| 8665 | tcp-request inspect-delay 30s |
| 8666 | acl content_present req_len gt 0 |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 8667 | tcp-request content accept if content_present |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8668 | tcp-request content reject |
| 8669 | |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 8670 | Example: |
| 8671 | # Track the last IP from X-Forwarded-For |
| 8672 | tcp-request inspect-delay 10s |
Willy Tarreau | 4d54c7c | 2014-09-16 15:48:15 +0200 | [diff] [blame] | 8673 | tcp-request content track-sc0 hdr(x-forwarded-for,-1) |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 8674 | |
| 8675 | Example: |
| 8676 | # track request counts per "base" (concatenation of Host+URL) |
| 8677 | tcp-request inspect-delay 10s |
Willy Tarreau | 4d54c7c | 2014-09-16 15:48:15 +0200 | [diff] [blame] | 8678 | tcp-request content track-sc0 base table req-rate |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 8679 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8680 | Example: track per-frontend and per-backend counters, block abusers at the |
| 8681 | frontend when the backend detects abuse. |
| 8682 | |
| 8683 | frontend http |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8684 | # Use General Purpose Couter 0 in SC0 as a global abuse counter |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8685 | # protecting all our sites |
| 8686 | stick-table type ip size 1m expire 5m store gpc0 |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8687 | tcp-request connection track-sc0 src |
| 8688 | tcp-request connection reject if { sc0_get_gpc0 gt 0 } |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8689 | ... |
| 8690 | use_backend http_dynamic if { path_end .php } |
| 8691 | |
| 8692 | backend http_dynamic |
| 8693 | # if a source makes too fast requests to this dynamic site (tracked |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8694 | # by SC1), block it globally in the frontend. |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8695 | stick-table type ip size 1m expire 5m store http_req_rate(10s) |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 8696 | acl click_too_fast sc1_http_req_rate gt 10 |
| 8697 | acl mark_as_abuser sc0_inc_gpc0 gt 0 |
| 8698 | tcp-request content track-sc1 src |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8699 | tcp-request content reject if click_too_fast mark_as_abuser |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8700 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 8701 | See section 7 about ACL usage. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8702 | |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 8703 | See also : "tcp-request connection", "tcp-request inspect-delay" |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8704 | |
| 8705 | |
| 8706 | tcp-request inspect-delay <timeout> |
| 8707 | Set the maximum allowed time to wait for data during content inspection |
| 8708 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8709 | no | yes | yes | yes |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8710 | Arguments : |
| 8711 | <timeout> is the timeout value specified in milliseconds by default, but |
| 8712 | can be in any other unit if the number is suffixed by the unit, |
| 8713 | as explained at the top of this document. |
| 8714 | |
| 8715 | People using haproxy primarily as a TCP relay are often worried about the |
| 8716 | risk of passing any type of protocol to a server without any analysis. In |
| 8717 | order to be able to analyze the request contents, we must first withhold |
| 8718 | the data then analyze them. This statement simply enables withholding of |
| 8719 | data for at most the specified amount of time. |
| 8720 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8721 | TCP content inspection applies very early when a connection reaches a |
| 8722 | frontend, then very early when the connection is forwarded to a backend. This |
| 8723 | means that a connection may experience a first delay in the frontend and a |
| 8724 | second delay in the backend if both have tcp-request rules. |
| 8725 | |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8726 | Note that when performing content inspection, haproxy will evaluate the whole |
| 8727 | rules for every new chunk which gets in, taking into account the fact that |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 8728 | those data are partial. If no rule matches before the aforementioned delay, |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8729 | a last check is performed upon expiration, this time considering that the |
Willy Tarreau | d869b24 | 2009-03-15 14:43:58 +0100 | [diff] [blame] | 8730 | contents are definitive. If no delay is set, haproxy will not wait at all |
| 8731 | and will immediately apply a verdict based on the available information. |
| 8732 | Obviously this is unlikely to be very useful and might even be racy, so such |
| 8733 | setups are not recommended. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8734 | |
| 8735 | As soon as a rule matches, the request is released and continues as usual. If |
| 8736 | the timeout is reached and no rule matches, the default policy will be to let |
| 8737 | it pass through unaffected. |
| 8738 | |
| 8739 | For most protocols, it is enough to set it to a few seconds, as most clients |
| 8740 | send the full request immediately upon connection. Add 3 or more seconds to |
| 8741 | cover TCP retransmits but that's all. For some protocols, it may make sense |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 8742 | to use large values, for instance to ensure that the client never talks |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8743 | before the server (eg: SMTP), or to wait for a client to talk before passing |
| 8744 | data to the server (eg: SSL). Note that the client timeout must cover at |
Willy Tarreau | b824b00 | 2010-09-29 16:36:16 +0200 | [diff] [blame] | 8745 | least the inspection delay, otherwise it will expire first. If the client |
| 8746 | closes the connection or if the buffer is full, the delay immediately expires |
| 8747 | since the contents will not be able to change anymore. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8748 | |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 8749 | See also : "tcp-request content accept", "tcp-request content reject", |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 8750 | "timeout client". |
| 8751 | |
| 8752 | |
Emeric Brun | 0a3b67f | 2010-09-24 15:34:53 +0200 | [diff] [blame] | 8753 | tcp-response content <action> [{if | unless} <condition>] |
| 8754 | Perform an action on a session response depending on a layer 4-7 condition |
| 8755 | May be used in sections : defaults | frontend | listen | backend |
| 8756 | no | no | yes | yes |
| 8757 | Arguments : |
| 8758 | <action> defines the action to perform if the condition applies. Valid |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 8759 | actions include : "accept", "close", "reject", "lua", |
| 8760 | "sc-inc-gpc0" and "sc-set-gpt0". |
Emeric Brun | 0a3b67f | 2010-09-24 15:34:53 +0200 | [diff] [blame] | 8761 | |
| 8762 | <condition> is a standard layer 4-7 ACL-based condition (see section 7). |
| 8763 | |
| 8764 | Response contents can be analysed at an early stage of response processing |
| 8765 | called "TCP content inspection". During this stage, ACL-based rules are |
| 8766 | evaluated every time the response contents are updated, until either an |
Willy Tarreau | cc1e04b | 2013-09-11 23:20:29 +0200 | [diff] [blame] | 8767 | "accept", "close" or a "reject" rule matches, or a TCP response inspection |
| 8768 | delay is set and expires with no matching rule. |
Emeric Brun | 0a3b67f | 2010-09-24 15:34:53 +0200 | [diff] [blame] | 8769 | |
| 8770 | Most often, these decisions will consider a protocol recognition or validity. |
| 8771 | |
| 8772 | Content-based rules are evaluated in their exact declaration order. If no |
| 8773 | rule matches or if there is no rule, the default action is to accept the |
| 8774 | contents. There is no specific limit to the number of rules which may be |
| 8775 | inserted. |
| 8776 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 8777 | Several types of actions are supported : |
Emeric Brun | 0a3b67f | 2010-09-24 15:34:53 +0200 | [diff] [blame] | 8778 | - accept : |
| 8779 | accepts the response if the condition is true (when used with "if") |
| 8780 | or false (when used with "unless"). The first such rule executed ends |
| 8781 | the rules evaluation. |
| 8782 | |
Willy Tarreau | cc1e04b | 2013-09-11 23:20:29 +0200 | [diff] [blame] | 8783 | - close : |
| 8784 | immediately closes the connection with the server if the condition is |
| 8785 | true (when used with "if"), or false (when used with "unless"). The |
| 8786 | first such rule executed ends the rules evaluation. The main purpose of |
| 8787 | this action is to force a connection to be finished between a client |
| 8788 | and a server after an exchange when the application protocol expects |
| 8789 | some long time outs to elapse first. The goal is to eliminate idle |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 8790 | connections which take significant resources on servers with certain |
Willy Tarreau | cc1e04b | 2013-09-11 23:20:29 +0200 | [diff] [blame] | 8791 | protocols. |
| 8792 | |
Emeric Brun | 0a3b67f | 2010-09-24 15:34:53 +0200 | [diff] [blame] | 8793 | - reject : |
| 8794 | rejects the response if the condition is true (when used with "if") |
| 8795 | or false (when used with "unless"). The first such rule executed ends |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 8796 | the rules evaluation. Rejected session are immediately closed. |
Emeric Brun | 0a3b67f | 2010-09-24 15:34:53 +0200 | [diff] [blame] | 8797 | |
Thierry FOURNIER | 69717b4 | 2015-06-04 12:23:41 +0200 | [diff] [blame] | 8798 | - lua <function> |
| 8799 | Executes Lua. |
| 8800 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 8801 | - set-var(<var-name>) <expr> |
| 8802 | Sets a variable. |
| 8803 | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 8804 | - sc-inc-gpc0(<sc-id>): |
| 8805 | This action increments the GPC0 counter according to the sticky |
| 8806 | counter designated by <sc-id>. If an error occurs, this action fails |
| 8807 | silently and the actions evaluation continues. |
| 8808 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 8809 | - sc-set-gpt0(<sc-id>) <int> : |
| 8810 | This action sets the GPT0 tag according to the sticky counter designated |
| 8811 | by <sc-id> and the value of <int>. The expected result is a boolean. If |
| 8812 | an error occurs, this action silently fails and the actions evaluation |
| 8813 | continues. |
| 8814 | |
Emeric Brun | 0a3b67f | 2010-09-24 15:34:53 +0200 | [diff] [blame] | 8815 | Note that the "if/unless" condition is optional. If no condition is set on |
| 8816 | the action, it is simply performed unconditionally. That can be useful for |
| 8817 | for changing the default action to a reject. |
| 8818 | |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 8819 | It is perfectly possible to match layer 7 contents with "tcp-response |
| 8820 | content" rules, but then it is important to ensure that a full response has |
| 8821 | been buffered, otherwise no contents will match. In order to achieve this, |
| 8822 | the best solution involves detecting the HTTP protocol during the inspection |
Emeric Brun | 0a3b67f | 2010-09-24 15:34:53 +0200 | [diff] [blame] | 8823 | period. |
| 8824 | |
Thierry FOURNIER | 90da191 | 2015-03-05 11:17:06 +0100 | [diff] [blame] | 8825 | The "lua" keyword is followed by a Lua function name. It is used to run a Lua |
| 8826 | function if the action is executed. The single parameter is the name of the |
| 8827 | function to run. The prototype of the function is documented in the API |
| 8828 | documentation. |
| 8829 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 8830 | The "set-var" is used to set the content of a variable. The variable is |
| 8831 | declared inline. |
| 8832 | |
| 8833 | <var-name> The name of the variable starts by an indication about its scope. |
| 8834 | The allowed scopes are: |
| 8835 | "sess" : the variable is shared with all the session, |
| 8836 | "txn" : the variable is shared with all the transaction |
| 8837 | (request and response) |
| 8838 | "req" : the variable is shared only during the request |
| 8839 | processing |
| 8840 | "res" : the variable is shared only during the response |
| 8841 | processing. |
| 8842 | This prefix is followed by a name. The separator is a '.'. |
| 8843 | The name may only contain characters 'a-z', 'A-Z', '0-9' and '_'. |
| 8844 | |
| 8845 | <expr> Is a standard HAProxy expression formed by a sample-fetch |
| 8846 | followed by some converters. |
| 8847 | |
| 8848 | Example: |
| 8849 | |
| 8850 | tcp-request content set-var(sess.my_var) src |
| 8851 | |
Emeric Brun | 0a3b67f | 2010-09-24 15:34:53 +0200 | [diff] [blame] | 8852 | See section 7 about ACL usage. |
| 8853 | |
| 8854 | See also : "tcp-request content", "tcp-response inspect-delay" |
| 8855 | |
| 8856 | |
| 8857 | tcp-response inspect-delay <timeout> |
| 8858 | Set the maximum allowed time to wait for a response during content inspection |
| 8859 | May be used in sections : defaults | frontend | listen | backend |
| 8860 | no | no | yes | yes |
| 8861 | Arguments : |
| 8862 | <timeout> is the timeout value specified in milliseconds by default, but |
| 8863 | can be in any other unit if the number is suffixed by the unit, |
| 8864 | as explained at the top of this document. |
| 8865 | |
| 8866 | See also : "tcp-response content", "tcp-request inspect-delay". |
| 8867 | |
| 8868 | |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 8869 | timeout check <timeout> |
| 8870 | Set additional check timeout, but only after a connection has been already |
| 8871 | established. |
| 8872 | |
| 8873 | May be used in sections: defaults | frontend | listen | backend |
| 8874 | yes | no | yes | yes |
| 8875 | Arguments: |
| 8876 | <timeout> is the timeout value specified in milliseconds by default, but |
| 8877 | can be in any other unit if the number is suffixed by the unit, |
| 8878 | as explained at the top of this document. |
| 8879 | |
| 8880 | If set, haproxy uses min("timeout connect", "inter") as a connect timeout |
| 8881 | for check and "timeout check" as an additional read timeout. The "min" is |
| 8882 | used so that people running with *very* long "timeout connect" (eg. those |
| 8883 | who needed this due to the queue or tarpit) do not slow down their checks. |
Willy Tarreau | d7550a2 | 2010-02-10 05:10:19 +0100 | [diff] [blame] | 8884 | (Please also note that there is no valid reason to have such long connect |
| 8885 | timeouts, because "timeout queue" and "timeout tarpit" can always be used to |
| 8886 | avoid that). |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 8887 | |
| 8888 | If "timeout check" is not set haproxy uses "inter" for complete check |
| 8889 | timeout (connect + read) exactly like all <1.3.15 version. |
| 8890 | |
| 8891 | In most cases check request is much simpler and faster to handle than normal |
| 8892 | requests and people may want to kick out laggy servers so this timeout should |
Willy Tarreau | 41a340d | 2008-01-22 12:25:31 +0100 | [diff] [blame] | 8893 | be smaller than "timeout server". |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 8894 | |
| 8895 | This parameter is specific to backends, but can be specified once for all in |
| 8896 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 8897 | forget about it. |
| 8898 | |
Willy Tarreau | 41a340d | 2008-01-22 12:25:31 +0100 | [diff] [blame] | 8899 | See also: "timeout connect", "timeout queue", "timeout server", |
| 8900 | "timeout tarpit". |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 8901 | |
| 8902 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 8903 | timeout client <timeout> |
| 8904 | timeout clitimeout <timeout> (deprecated) |
| 8905 | Set the maximum inactivity time on the client side. |
| 8906 | May be used in sections : defaults | frontend | listen | backend |
| 8907 | yes | yes | yes | no |
| 8908 | Arguments : |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 8909 | <timeout> is the timeout value specified in milliseconds by default, but |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 8910 | can be in any other unit if the number is suffixed by the unit, |
| 8911 | as explained at the top of this document. |
| 8912 | |
| 8913 | The inactivity timeout applies when the client is expected to acknowledge or |
| 8914 | send data. In HTTP mode, this timeout is particularly important to consider |
| 8915 | during the first phase, when the client sends the request, and during the |
| 8916 | response while it is reading data sent by the server. The value is specified |
| 8917 | in milliseconds by default, but can be in any other unit if the number is |
| 8918 | suffixed by the unit, as specified at the top of this document. In TCP mode |
| 8919 | (and to a lesser extent, in HTTP mode), it is highly recommended that the |
| 8920 | client timeout remains equal to the server timeout in order to avoid complex |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 8921 | situations to debug. It is a good practice to cover one or several TCP packet |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 8922 | losses by specifying timeouts that are slightly above multiples of 3 seconds |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8923 | (eg: 4 or 5 seconds). If some long-lived sessions are mixed with short-lived |
| 8924 | sessions (eg: WebSocket and HTTP), it's worth considering "timeout tunnel", |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 8925 | which overrides "timeout client" and "timeout server" for tunnels, as well as |
| 8926 | "timeout client-fin" for half-closed connections. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 8927 | |
| 8928 | This parameter is specific to frontends, but can be specified once for all in |
| 8929 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 8930 | forget about it. An unspecified timeout results in an infinite timeout, which |
| 8931 | is not recommended. Such a usage is accepted and works but reports a warning |
| 8932 | during startup because it may results in accumulation of expired sessions in |
| 8933 | the system if the system's timeouts are not configured either. |
| 8934 | |
| 8935 | This parameter replaces the old, deprecated "clitimeout". It is recommended |
| 8936 | to use it to write new configurations. The form "timeout clitimeout" is |
| 8937 | provided only by backwards compatibility but its use is strongly discouraged. |
| 8938 | |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8939 | See also : "clitimeout", "timeout server", "timeout tunnel". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 8940 | |
| 8941 | |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 8942 | timeout client-fin <timeout> |
| 8943 | Set the inactivity timeout on the client side for half-closed connections. |
| 8944 | May be used in sections : defaults | frontend | listen | backend |
| 8945 | yes | yes | yes | no |
| 8946 | Arguments : |
| 8947 | <timeout> is the timeout value specified in milliseconds by default, but |
| 8948 | can be in any other unit if the number is suffixed by the unit, |
| 8949 | as explained at the top of this document. |
| 8950 | |
| 8951 | The inactivity timeout applies when the client is expected to acknowledge or |
| 8952 | send data while one direction is already shut down. This timeout is different |
| 8953 | from "timeout client" in that it only applies to connections which are closed |
| 8954 | in one direction. This is particularly useful to avoid keeping connections in |
| 8955 | FIN_WAIT state for too long when clients do not disconnect cleanly. This |
| 8956 | problem is particularly common long connections such as RDP or WebSocket. |
| 8957 | Note that this timeout can override "timeout tunnel" when a connection shuts |
| 8958 | down in one direction. |
| 8959 | |
| 8960 | This parameter is specific to frontends, but can be specified once for all in |
| 8961 | "defaults" sections. By default it is not set, so half-closed connections |
| 8962 | will use the other timeouts (timeout.client or timeout.tunnel). |
| 8963 | |
| 8964 | See also : "timeout client", "timeout server-fin", and "timeout tunnel". |
| 8965 | |
| 8966 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 8967 | timeout connect <timeout> |
| 8968 | timeout contimeout <timeout> (deprecated) |
| 8969 | Set the maximum time to wait for a connection attempt to a server to succeed. |
| 8970 | May be used in sections : defaults | frontend | listen | backend |
| 8971 | yes | no | yes | yes |
| 8972 | Arguments : |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 8973 | <timeout> is the timeout value specified in milliseconds by default, but |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 8974 | can be in any other unit if the number is suffixed by the unit, |
| 8975 | as explained at the top of this document. |
| 8976 | |
| 8977 | If the server is located on the same LAN as haproxy, the connection should be |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 8978 | immediate (less than a few milliseconds). Anyway, it is a good practice to |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 8979 | cover one or several TCP packet losses by specifying timeouts that are |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 8980 | slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 8981 | connect timeout also presets both queue and tarpit timeouts to the same value |
| 8982 | if these have not been specified. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 8983 | |
| 8984 | This parameter is specific to backends, but can be specified once for all in |
| 8985 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 8986 | forget about it. An unspecified timeout results in an infinite timeout, which |
| 8987 | is not recommended. Such a usage is accepted and works but reports a warning |
| 8988 | during startup because it may results in accumulation of failed sessions in |
| 8989 | the system if the system's timeouts are not configured either. |
| 8990 | |
| 8991 | This parameter replaces the old, deprecated "contimeout". It is recommended |
| 8992 | to use it to write new configurations. The form "timeout contimeout" is |
| 8993 | provided only by backwards compatibility but its use is strongly discouraged. |
| 8994 | |
Willy Tarreau | 41a340d | 2008-01-22 12:25:31 +0100 | [diff] [blame] | 8995 | See also: "timeout check", "timeout queue", "timeout server", "contimeout", |
| 8996 | "timeout tarpit". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 8997 | |
| 8998 | |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 8999 | timeout http-keep-alive <timeout> |
| 9000 | Set the maximum allowed time to wait for a new HTTP request to appear |
| 9001 | May be used in sections : defaults | frontend | listen | backend |
| 9002 | yes | yes | yes | yes |
| 9003 | Arguments : |
| 9004 | <timeout> is the timeout value specified in milliseconds by default, but |
| 9005 | can be in any other unit if the number is suffixed by the unit, |
| 9006 | as explained at the top of this document. |
| 9007 | |
| 9008 | By default, the time to wait for a new request in case of keep-alive is set |
| 9009 | by "timeout http-request". However this is not always convenient because some |
| 9010 | people want very short keep-alive timeouts in order to release connections |
| 9011 | faster, and others prefer to have larger ones but still have short timeouts |
| 9012 | once the request has started to present itself. |
| 9013 | |
| 9014 | The "http-keep-alive" timeout covers these needs. It will define how long to |
| 9015 | wait for a new HTTP request to start coming after a response was sent. Once |
| 9016 | the first byte of request has been seen, the "http-request" timeout is used |
| 9017 | to wait for the complete request to come. Note that empty lines prior to a |
| 9018 | new request do not refresh the timeout and are not counted as a new request. |
| 9019 | |
| 9020 | There is also another difference between the two timeouts : when a connection |
| 9021 | expires during timeout http-keep-alive, no error is returned, the connection |
| 9022 | just closes. If the connection expires in "http-request" while waiting for a |
| 9023 | connection to complete, a HTTP 408 error is returned. |
| 9024 | |
| 9025 | In general it is optimal to set this value to a few tens to hundreds of |
| 9026 | milliseconds, to allow users to fetch all objects of a page at once but |
| 9027 | without waiting for further clicks. Also, if set to a very small value (eg: |
| 9028 | 1 millisecond) it will probably only accept pipelined requests but not the |
| 9029 | non-pipelined ones. It may be a nice trade-off for very large sites running |
Patrick Mézard | 2382ad6 | 2010-05-09 10:43:32 +0200 | [diff] [blame] | 9030 | with tens to hundreds of thousands of clients. |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 9031 | |
| 9032 | If this parameter is not set, the "http-request" timeout applies, and if both |
| 9033 | are not set, "timeout client" still applies at the lower level. It should be |
| 9034 | set in the frontend to take effect, unless the frontend is in TCP mode, in |
| 9035 | which case the HTTP backend's timeout will be used. |
| 9036 | |
| 9037 | See also : "timeout http-request", "timeout client". |
| 9038 | |
| 9039 | |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 9040 | timeout http-request <timeout> |
| 9041 | Set the maximum allowed time to wait for a complete HTTP request |
| 9042 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 9043 | yes | yes | yes | yes |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 9044 | Arguments : |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9045 | <timeout> is the timeout value specified in milliseconds by default, but |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 9046 | can be in any other unit if the number is suffixed by the unit, |
| 9047 | as explained at the top of this document. |
| 9048 | |
| 9049 | In order to offer DoS protection, it may be required to lower the maximum |
| 9050 | accepted time to receive a complete HTTP request without affecting the client |
| 9051 | timeout. This helps protecting against established connections on which |
| 9052 | nothing is sent. The client timeout cannot offer a good protection against |
| 9053 | this abuse because it is an inactivity timeout, which means that if the |
| 9054 | attacker sends one character every now and then, the timeout will not |
| 9055 | trigger. With the HTTP request timeout, no matter what speed the client |
Willy Tarreau | 2705a61 | 2014-05-23 17:38:34 +0200 | [diff] [blame] | 9056 | types, the request will be aborted if it does not complete in time. When the |
| 9057 | timeout expires, an HTTP 408 response is sent to the client to inform it |
| 9058 | about the problem, and the connection is closed. The logs will report |
| 9059 | termination codes "cR". Some recent browsers are having problems with this |
| 9060 | standard, well-documented behaviour, so it might be needed to hide the 408 |
Willy Tarreau | 0f228a0 | 2015-05-01 15:37:53 +0200 | [diff] [blame] | 9061 | code using "option http-ignore-probes" or "errorfile 408 /dev/null". See |
| 9062 | more details in the explanations of the "cR" termination code in section 8.5. |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 9063 | |
| 9064 | Note that this timeout only applies to the header part of the request, and |
| 9065 | not to any data. As soon as the empty line is received, this timeout is not |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 9066 | used anymore. It is used again on keep-alive connections to wait for a second |
| 9067 | request if "timeout http-keep-alive" is not set. |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 9068 | |
| 9069 | Generally it is enough to set it to a few seconds, as most clients send the |
| 9070 | full request immediately upon connection. Add 3 or more seconds to cover TCP |
| 9071 | retransmits but that's all. Setting it to very low values (eg: 50 ms) will |
| 9072 | generally work on local networks as long as there are no packet losses. This |
| 9073 | will prevent people from sending bare HTTP requests using telnet. |
| 9074 | |
| 9075 | If this parameter is not set, the client timeout still applies between each |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 9076 | chunk of the incoming request. It should be set in the frontend to take |
| 9077 | effect, unless the frontend is in TCP mode, in which case the HTTP backend's |
| 9078 | timeout will be used. |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 9079 | |
Willy Tarreau | 0f228a0 | 2015-05-01 15:37:53 +0200 | [diff] [blame] | 9080 | See also : "errorfile", "http-ignore-probes", "timeout http-keep-alive", and |
| 9081 | "timeout client". |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 9082 | |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9083 | |
| 9084 | timeout queue <timeout> |
| 9085 | Set the maximum time to wait in the queue for a connection slot to be free |
| 9086 | May be used in sections : defaults | frontend | listen | backend |
| 9087 | yes | no | yes | yes |
| 9088 | Arguments : |
| 9089 | <timeout> is the timeout value specified in milliseconds by default, but |
| 9090 | can be in any other unit if the number is suffixed by the unit, |
| 9091 | as explained at the top of this document. |
| 9092 | |
| 9093 | When a server's maxconn is reached, connections are left pending in a queue |
| 9094 | which may be server-specific or global to the backend. In order not to wait |
| 9095 | indefinitely, a timeout is applied to requests pending in the queue. If the |
| 9096 | timeout is reached, it is considered that the request will almost never be |
| 9097 | served, so it is dropped and a 503 error is returned to the client. |
| 9098 | |
| 9099 | The "timeout queue" statement allows to fix the maximum time for a request to |
| 9100 | be left pending in a queue. If unspecified, the same value as the backend's |
| 9101 | connection timeout ("timeout connect") is used, for backwards compatibility |
| 9102 | with older versions with no "timeout queue" parameter. |
| 9103 | |
| 9104 | See also : "timeout connect", "contimeout". |
| 9105 | |
| 9106 | |
| 9107 | timeout server <timeout> |
| 9108 | timeout srvtimeout <timeout> (deprecated) |
| 9109 | Set the maximum inactivity time on the server side. |
| 9110 | May be used in sections : defaults | frontend | listen | backend |
| 9111 | yes | no | yes | yes |
| 9112 | Arguments : |
| 9113 | <timeout> is the timeout value specified in milliseconds by default, but |
| 9114 | can be in any other unit if the number is suffixed by the unit, |
| 9115 | as explained at the top of this document. |
| 9116 | |
| 9117 | The inactivity timeout applies when the server is expected to acknowledge or |
| 9118 | send data. In HTTP mode, this timeout is particularly important to consider |
| 9119 | during the first phase of the server's response, when it has to send the |
| 9120 | headers, as it directly represents the server's processing time for the |
| 9121 | request. To find out what value to put there, it's often good to start with |
| 9122 | what would be considered as unacceptable response times, then check the logs |
| 9123 | to observe the response time distribution, and adjust the value accordingly. |
| 9124 | |
| 9125 | The value is specified in milliseconds by default, but can be in any other |
| 9126 | unit if the number is suffixed by the unit, as specified at the top of this |
| 9127 | document. In TCP mode (and to a lesser extent, in HTTP mode), it is highly |
| 9128 | recommended that the client timeout remains equal to the server timeout in |
| 9129 | order to avoid complex situations to debug. Whatever the expected server |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 9130 | response times, it is a good practice to cover at least one or several TCP |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9131 | packet losses by specifying timeouts that are slightly above multiples of 3 |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 9132 | seconds (eg: 4 or 5 seconds minimum). If some long-lived sessions are mixed |
| 9133 | with short-lived sessions (eg: WebSocket and HTTP), it's worth considering |
| 9134 | "timeout tunnel", which overrides "timeout client" and "timeout server" for |
| 9135 | tunnels. |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9136 | |
| 9137 | This parameter is specific to backends, but can be specified once for all in |
| 9138 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 9139 | forget about it. An unspecified timeout results in an infinite timeout, which |
| 9140 | is not recommended. Such a usage is accepted and works but reports a warning |
| 9141 | during startup because it may results in accumulation of expired sessions in |
| 9142 | the system if the system's timeouts are not configured either. |
| 9143 | |
| 9144 | This parameter replaces the old, deprecated "srvtimeout". It is recommended |
| 9145 | to use it to write new configurations. The form "timeout srvtimeout" is |
| 9146 | provided only by backwards compatibility but its use is strongly discouraged. |
| 9147 | |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 9148 | See also : "srvtimeout", "timeout client" and "timeout tunnel". |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9149 | |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 9150 | |
| 9151 | timeout server-fin <timeout> |
| 9152 | Set the inactivity timeout on the server side for half-closed connections. |
| 9153 | May be used in sections : defaults | frontend | listen | backend |
| 9154 | yes | no | yes | yes |
| 9155 | Arguments : |
| 9156 | <timeout> is the timeout value specified in milliseconds by default, but |
| 9157 | can be in any other unit if the number is suffixed by the unit, |
| 9158 | as explained at the top of this document. |
| 9159 | |
| 9160 | The inactivity timeout applies when the server is expected to acknowledge or |
| 9161 | send data while one direction is already shut down. This timeout is different |
| 9162 | from "timeout server" in that it only applies to connections which are closed |
| 9163 | in one direction. This is particularly useful to avoid keeping connections in |
| 9164 | FIN_WAIT state for too long when a remote server does not disconnect cleanly. |
| 9165 | This problem is particularly common long connections such as RDP or WebSocket. |
| 9166 | Note that this timeout can override "timeout tunnel" when a connection shuts |
| 9167 | down in one direction. This setting was provided for completeness, but in most |
| 9168 | situations, it should not be needed. |
| 9169 | |
| 9170 | This parameter is specific to backends, but can be specified once for all in |
| 9171 | "defaults" sections. By default it is not set, so half-closed connections |
| 9172 | will use the other timeouts (timeout.server or timeout.tunnel). |
| 9173 | |
| 9174 | See also : "timeout client-fin", "timeout server", and "timeout tunnel". |
| 9175 | |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9176 | |
| 9177 | timeout tarpit <timeout> |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 9178 | Set the duration for which tarpitted connections will be maintained |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9179 | May be used in sections : defaults | frontend | listen | backend |
| 9180 | yes | yes | yes | yes |
| 9181 | Arguments : |
| 9182 | <timeout> is the tarpit duration specified in milliseconds by default, but |
| 9183 | can be in any other unit if the number is suffixed by the unit, |
| 9184 | as explained at the top of this document. |
| 9185 | |
| 9186 | When a connection is tarpitted using "reqtarpit", it is maintained open with |
| 9187 | no activity for a certain amount of time, then closed. "timeout tarpit" |
| 9188 | defines how long it will be maintained open. |
| 9189 | |
| 9190 | The value is specified in milliseconds by default, but can be in any other |
| 9191 | unit if the number is suffixed by the unit, as specified at the top of this |
| 9192 | document. If unspecified, the same value as the backend's connection timeout |
| 9193 | ("timeout connect") is used, for backwards compatibility with older versions |
Cyril Bonté | 78caf84 | 2010-03-10 22:41:43 +0100 | [diff] [blame] | 9194 | with no "timeout tarpit" parameter. |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9195 | |
| 9196 | See also : "timeout connect", "contimeout". |
| 9197 | |
| 9198 | |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 9199 | timeout tunnel <timeout> |
| 9200 | Set the maximum inactivity time on the client and server side for tunnels. |
| 9201 | May be used in sections : defaults | frontend | listen | backend |
| 9202 | yes | no | yes | yes |
| 9203 | Arguments : |
| 9204 | <timeout> is the timeout value specified in milliseconds by default, but |
| 9205 | can be in any other unit if the number is suffixed by the unit, |
| 9206 | as explained at the top of this document. |
| 9207 | |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 9208 | The tunnel timeout applies when a bidirectional connection is established |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 9209 | between a client and a server, and the connection remains inactive in both |
| 9210 | directions. This timeout supersedes both the client and server timeouts once |
| 9211 | the connection becomes a tunnel. In TCP, this timeout is used as soon as no |
| 9212 | analyser remains attached to either connection (eg: tcp content rules are |
| 9213 | accepted). In HTTP, this timeout is used when a connection is upgraded (eg: |
| 9214 | when switching to the WebSocket protocol, or forwarding a CONNECT request |
| 9215 | to a proxy), or after the first response when no keepalive/close option is |
| 9216 | specified. |
| 9217 | |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 9218 | Since this timeout is usually used in conjunction with long-lived connections, |
| 9219 | it usually is a good idea to also set "timeout client-fin" to handle the |
| 9220 | situation where a client suddenly disappears from the net and does not |
| 9221 | acknowledge a close, or sends a shutdown and does not acknowledge pending |
| 9222 | data anymore. This can happen in lossy networks where firewalls are present, |
| 9223 | and is detected by the presence of large amounts of sessions in a FIN_WAIT |
| 9224 | state. |
| 9225 | |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 9226 | The value is specified in milliseconds by default, but can be in any other |
| 9227 | unit if the number is suffixed by the unit, as specified at the top of this |
| 9228 | document. Whatever the expected normal idle time, it is a good practice to |
| 9229 | cover at least one or several TCP packet losses by specifying timeouts that |
| 9230 | are slightly above multiples of 3 seconds (eg: 4 or 5 seconds minimum). |
| 9231 | |
| 9232 | This parameter is specific to backends, but can be specified once for all in |
| 9233 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 9234 | forget about it. |
| 9235 | |
| 9236 | Example : |
| 9237 | defaults http |
| 9238 | option http-server-close |
| 9239 | timeout connect 5s |
| 9240 | timeout client 30s |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 9241 | timeout client-fin 30s |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 9242 | timeout server 30s |
| 9243 | timeout tunnel 1h # timeout to use with WebSocket and CONNECT |
| 9244 | |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 9245 | See also : "timeout client", "timeout client-fin", "timeout server". |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 9246 | |
| 9247 | |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9248 | transparent (deprecated) |
| 9249 | Enable client-side transparent proxying |
| 9250 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | 4b1f859 | 2008-12-23 23:13:55 +0100 | [diff] [blame] | 9251 | yes | no | yes | yes |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9252 | Arguments : none |
| 9253 | |
| 9254 | This keyword was introduced in order to provide layer 7 persistence to layer |
| 9255 | 3 load balancers. The idea is to use the OS's ability to redirect an incoming |
| 9256 | connection for a remote address to a local process (here HAProxy), and let |
| 9257 | this process know what address was initially requested. When this option is |
| 9258 | used, sessions without cookies will be forwarded to the original destination |
| 9259 | IP address of the incoming request (which should match that of another |
| 9260 | equipment), while requests with cookies will still be forwarded to the |
| 9261 | appropriate server. |
| 9262 | |
| 9263 | The "transparent" keyword is deprecated, use "option transparent" instead. |
| 9264 | |
| 9265 | Note that contrary to a common belief, this option does NOT make HAProxy |
| 9266 | present the client's IP to the server when establishing the connection. |
| 9267 | |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9268 | See also: "option transparent" |
| 9269 | |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 9270 | unique-id-format <string> |
| 9271 | Generate a unique ID for each request. |
| 9272 | May be used in sections : defaults | frontend | listen | backend |
| 9273 | yes | yes | yes | no |
| 9274 | Arguments : |
| 9275 | <string> is a log-format string. |
| 9276 | |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 9277 | This keyword creates a ID for each request using the custom log format. A |
| 9278 | unique ID is useful to trace a request passing through many components of |
| 9279 | a complex infrastructure. The newly created ID may also be logged using the |
| 9280 | %ID tag the log-format string. |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 9281 | |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 9282 | The format should be composed from elements that are guaranteed to be |
| 9283 | unique when combined together. For instance, if multiple haproxy instances |
| 9284 | are involved, it might be important to include the node name. It is often |
| 9285 | needed to log the incoming connection's source and destination addresses |
| 9286 | and ports. Note that since multiple requests may be performed over the same |
| 9287 | connection, including a request counter may help differentiate them. |
| 9288 | Similarly, a timestamp may protect against a rollover of the counter. |
| 9289 | Logging the process ID will avoid collisions after a service restart. |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 9290 | |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 9291 | It is recommended to use hexadecimal notation for many fields since it |
| 9292 | makes them more compact and saves space in logs. |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 9293 | |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 9294 | Example: |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 9295 | |
Julien Vehent | f21be32 | 2014-03-07 08:27:34 -0500 | [diff] [blame] | 9296 | unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 9297 | |
| 9298 | will generate: |
| 9299 | |
| 9300 | 7F000001:8296_7F00001E:1F90_4F7B0A69_0003:790A |
| 9301 | |
| 9302 | See also: "unique-id-header" |
| 9303 | |
| 9304 | unique-id-header <name> |
| 9305 | Add a unique ID header in the HTTP request. |
| 9306 | May be used in sections : defaults | frontend | listen | backend |
| 9307 | yes | yes | yes | no |
| 9308 | Arguments : |
| 9309 | <name> is the name of the header. |
| 9310 | |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 9311 | Add a unique-id header in the HTTP request sent to the server, using the |
| 9312 | unique-id-format. It can't work if the unique-id-format doesn't exist. |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 9313 | |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 9314 | Example: |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 9315 | |
Julien Vehent | f21be32 | 2014-03-07 08:27:34 -0500 | [diff] [blame] | 9316 | unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 9317 | unique-id-header X-Unique-ID |
| 9318 | |
| 9319 | will generate: |
| 9320 | |
| 9321 | X-Unique-ID: 7F000001:8296_7F00001E:1F90_4F7B0A69_0003:790A |
| 9322 | |
| 9323 | See also: "unique-id-format" |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9324 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 9325 | use_backend <backend> [{if | unless} <condition>] |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 9326 | Switch to a specific backend if/unless an ACL-based condition is matched. |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9327 | May be used in sections : defaults | frontend | listen | backend |
| 9328 | no | yes | yes | no |
| 9329 | Arguments : |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 9330 | <backend> is the name of a valid backend or "listen" section, or a |
| 9331 | "log-format" string resolving to a backend name. |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9332 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 9333 | <condition> is a condition composed of ACLs, as described in section 7. If |
| 9334 | it is omitted, the rule is unconditionally applied. |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9335 | |
| 9336 | When doing content-switching, connections arrive on a frontend and are then |
| 9337 | dispatched to various backends depending on a number of conditions. The |
| 9338 | relation between the conditions and the backends is described with the |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 9339 | "use_backend" keyword. While it is normally used with HTTP processing, it can |
| 9340 | also be used in pure TCP, either without content using stateless ACLs (eg: |
| 9341 | source address validation) or combined with a "tcp-request" rule to wait for |
| 9342 | some payload. |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 9343 | |
| 9344 | There may be as many "use_backend" rules as desired. All of these rules are |
| 9345 | evaluated in their declaration order, and the first one which matches will |
| 9346 | assign the backend. |
| 9347 | |
| 9348 | In the first form, the backend will be used if the condition is met. In the |
| 9349 | second form, the backend will be used if the condition is not met. If no |
| 9350 | condition is valid, the backend defined with "default_backend" will be used. |
| 9351 | If no default backend is defined, either the servers in the same section are |
| 9352 | used (in case of a "listen" section) or, in case of a frontend, no server is |
| 9353 | used and a 503 service unavailable response is returned. |
| 9354 | |
Willy Tarreau | 51aecc7 | 2009-07-12 09:47:04 +0200 | [diff] [blame] | 9355 | Note that it is possible to switch from a TCP frontend to an HTTP backend. In |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 9356 | this case, either the frontend has already checked that the protocol is HTTP, |
Willy Tarreau | 51aecc7 | 2009-07-12 09:47:04 +0200 | [diff] [blame] | 9357 | and backend processing will immediately follow, or the backend will wait for |
| 9358 | a complete HTTP request to get in. This feature is useful when a frontend |
| 9359 | must decode several protocols on a unique port, one of them being HTTP. |
| 9360 | |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 9361 | When <backend> is a simple name, it is resolved at configuration time, and an |
| 9362 | error is reported if the specified backend does not exist. If <backend> is |
| 9363 | a log-format string instead, no check may be done at configuration time, so |
| 9364 | the backend name is resolved dynamically at run time. If the resulting |
| 9365 | backend name does not correspond to any valid backend, no other rule is |
| 9366 | evaluated, and the default_backend directive is applied instead. Note that |
| 9367 | when using dynamic backend names, it is highly recommended to use a prefix |
| 9368 | that no other backend uses in order to ensure that an unauthorized backend |
| 9369 | cannot be forced from the request. |
| 9370 | |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9371 | It is worth mentioning that "use_backend" rules with an explicit name are |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 9372 | used to detect the association between frontends and backends to compute the |
| 9373 | backend's "fullconn" setting. This cannot be done for dynamic names. |
| 9374 | |
| 9375 | See also: "default_backend", "tcp-request", "fullconn", "log-format", and |
| 9376 | section 7 about ACLs. |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 9377 | |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 9378 | |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 9379 | use-server <server> if <condition> |
| 9380 | use-server <server> unless <condition> |
| 9381 | Only use a specific server if/unless an ACL-based condition is matched. |
| 9382 | May be used in sections : defaults | frontend | listen | backend |
| 9383 | no | no | yes | yes |
| 9384 | Arguments : |
Cyril Bonté | 108cf6e | 2012-04-21 23:30:29 +0200 | [diff] [blame] | 9385 | <server> is the name of a valid server in the same backend section. |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 9386 | |
| 9387 | <condition> is a condition composed of ACLs, as described in section 7. |
| 9388 | |
| 9389 | By default, connections which arrive to a backend are load-balanced across |
| 9390 | the available servers according to the configured algorithm, unless a |
| 9391 | persistence mechanism such as a cookie is used and found in the request. |
| 9392 | |
| 9393 | Sometimes it is desirable to forward a particular request to a specific |
| 9394 | server without having to declare a dedicated backend for this server. This |
| 9395 | can be achieved using the "use-server" rules. These rules are evaluated after |
| 9396 | the "redirect" rules and before evaluating cookies, and they have precedence |
| 9397 | on them. There may be as many "use-server" rules as desired. All of these |
| 9398 | rules are evaluated in their declaration order, and the first one which |
| 9399 | matches will assign the server. |
| 9400 | |
| 9401 | If a rule designates a server which is down, and "option persist" is not used |
| 9402 | and no force-persist rule was validated, it is ignored and evaluation goes on |
| 9403 | with the next rules until one matches. |
| 9404 | |
| 9405 | In the first form, the server will be used if the condition is met. In the |
| 9406 | second form, the server will be used if the condition is not met. If no |
| 9407 | condition is valid, the processing continues and the server will be assigned |
| 9408 | according to other persistence mechanisms. |
| 9409 | |
| 9410 | Note that even if a rule is matched, cookie processing is still performed but |
| 9411 | does not assign the server. This allows prefixed cookies to have their prefix |
| 9412 | stripped. |
| 9413 | |
| 9414 | The "use-server" statement works both in HTTP and TCP mode. This makes it |
| 9415 | suitable for use with content-based inspection. For instance, a server could |
| 9416 | be selected in a farm according to the TLS SNI field. And if these servers |
| 9417 | have their weight set to zero, they will not be used for other traffic. |
| 9418 | |
| 9419 | Example : |
| 9420 | # intercept incoming TLS requests based on the SNI field |
| 9421 | use-server www if { req_ssl_sni -i www.example.com } |
| 9422 | server www 192.168.0.1:443 weight 0 |
| 9423 | use-server mail if { req_ssl_sni -i mail.example.com } |
| 9424 | server mail 192.168.0.1:587 weight 0 |
| 9425 | use-server imap if { req_ssl_sni -i imap.example.com } |
| 9426 | server mail 192.168.0.1:993 weight 0 |
| 9427 | # all the rest is forwarded to this server |
| 9428 | server default 192.168.0.2:443 check |
| 9429 | |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9430 | See also: "use_backend", section 5 about server and section 7 about ACLs. |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 9431 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9432 | |
| 9433 | 5. Bind and Server options |
| 9434 | -------------------------- |
| 9435 | |
| 9436 | The "bind", "server" and "default-server" keywords support a number of settings |
| 9437 | depending on some build options and on the system HAProxy was built on. These |
| 9438 | settings generally each consist in one word sometimes followed by a value, |
| 9439 | written on the same line as the "bind" or "server" line. All these options are |
| 9440 | described in this section. |
| 9441 | |
| 9442 | |
| 9443 | 5.1. Bind options |
| 9444 | ----------------- |
| 9445 | |
| 9446 | The "bind" keyword supports a certain number of settings which are all passed |
| 9447 | as arguments on the same line. The order in which those arguments appear makes |
| 9448 | no importance, provided that they appear after the bind address. All of these |
| 9449 | parameters are optional. Some of them consist in a single words (booleans), |
| 9450 | while other ones expect a value after them. In this case, the value must be |
| 9451 | provided immediately after the setting name. |
| 9452 | |
| 9453 | The currently supported settings are the following ones. |
| 9454 | |
| 9455 | accept-proxy |
| 9456 | Enforces the use of the PROXY protocol over any connection accepted by any of |
Willy Tarreau | 7799267 | 2014-06-14 11:06:17 +0200 | [diff] [blame] | 9457 | the sockets declared on the same line. Versions 1 and 2 of the PROXY protocol |
| 9458 | are supported and correctly detected. The PROXY protocol dictates the layer |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9459 | 3/4 addresses of the incoming connection to be used everywhere an address is |
| 9460 | used, with the only exception of "tcp-request connection" rules which will |
| 9461 | only see the real connection address. Logs will reflect the addresses |
| 9462 | indicated in the protocol, unless it is violated, in which case the real |
| 9463 | address will still be used. This keyword combined with support from external |
| 9464 | components can be used as an efficient and reliable alternative to the |
| 9465 | X-Forwarded-For mechanism which is not always reliable and not even always |
Willy Tarreau | 4f0d919 | 2013-06-11 20:40:55 +0200 | [diff] [blame] | 9466 | usable. See also "tcp-request connection expect-proxy" for a finer-grained |
| 9467 | setting of which client is allowed to use the protocol. |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9468 | |
Willy Tarreau | ab861d3 | 2013-04-02 02:30:41 +0200 | [diff] [blame] | 9469 | alpn <protocols> |
| 9470 | This enables the TLS ALPN extension and advertises the specified protocol |
| 9471 | list as supported on top of ALPN. The protocol list consists in a comma- |
| 9472 | delimited list of protocol names, for instance: "http/1.1,http/1.0" (without |
| 9473 | quotes). This requires that the SSL library is build with support for TLS |
| 9474 | extensions enabled (check with haproxy -vv). The ALPN extension replaces the |
| 9475 | initial NPN extension. |
| 9476 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9477 | backlog <backlog> |
| 9478 | Sets the socket's backlog to this value. If unspecified, the frontend's |
| 9479 | backlog is used instead, which generally defaults to the maxconn value. |
| 9480 | |
Emeric Brun | 7fb3442 | 2012-09-28 15:26:15 +0200 | [diff] [blame] | 9481 | ecdhe <named curve> |
| 9482 | This setting is only available when support for OpenSSL was built in. It sets |
Emeric Brun | 6924ef8 | 2013-03-06 14:08:53 +0100 | [diff] [blame] | 9483 | the named curve (RFC 4492) used to generate ECDH ephemeral keys. By default, |
| 9484 | used named curve is prime256v1. |
Emeric Brun | 7fb3442 | 2012-09-28 15:26:15 +0200 | [diff] [blame] | 9485 | |
Emeric Brun | fd33a26 | 2012-10-11 16:28:27 +0200 | [diff] [blame] | 9486 | ca-file <cafile> |
Emeric Brun | 1a073b4 | 2012-09-28 17:07:34 +0200 | [diff] [blame] | 9487 | This setting is only available when support for OpenSSL was built in. It |
| 9488 | designates a PEM file from which to load CA certificates used to verify |
| 9489 | client's certificate. |
| 9490 | |
Emeric Brun | b6dc934 | 2012-09-28 17:55:37 +0200 | [diff] [blame] | 9491 | ca-ignore-err [all|<errorID>,...] |
| 9492 | This setting is only available when support for OpenSSL was built in. |
| 9493 | Sets a comma separated list of errorIDs to ignore during verify at depth > 0. |
| 9494 | If set to 'all', all errors are ignored. SSL handshake is not aborted if an |
| 9495 | error is ignored. |
| 9496 | |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 9497 | ca-sign-file <cafile> |
| 9498 | This setting is only available when support for OpenSSL was built in. It |
| 9499 | designates a PEM file containing both the CA certificate and the CA private |
| 9500 | key used to create and sign server's certificates. This is a mandatory |
| 9501 | setting when the dynamic generation of certificates is enabled. See |
| 9502 | 'generate-certificates' for details. |
| 9503 | |
| 9504 | ca-sign-passphrase <passphrase> |
| 9505 | This setting is only available when support for OpenSSL was built in. It is |
| 9506 | the CA private key passphrase. This setting is optional and used only when |
| 9507 | the dynamic generation of certificates is enabled. See |
| 9508 | 'generate-certificates' for details. |
| 9509 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9510 | ciphers <ciphers> |
| 9511 | This setting is only available when support for OpenSSL was built in. It sets |
| 9512 | the string describing the list of cipher algorithms ("cipher suite") that are |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9513 | negotiated during the SSL/TLS handshake. The format of the string is defined |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9514 | in "man 1 ciphers" from OpenSSL man pages, and can be for instance a string |
| 9515 | such as "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" (without quotes). |
| 9516 | |
Emeric Brun | fd33a26 | 2012-10-11 16:28:27 +0200 | [diff] [blame] | 9517 | crl-file <crlfile> |
Emeric Brun | 1a073b4 | 2012-09-28 17:07:34 +0200 | [diff] [blame] | 9518 | This setting is only available when support for OpenSSL was built in. It |
| 9519 | designates a PEM file from which to load certificate revocation list used |
| 9520 | to verify client's certificate. |
| 9521 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9522 | crt <cert> |
Alex Davies | 0fbf016 | 2013-03-02 16:04:50 +0000 | [diff] [blame] | 9523 | This setting is only available when support for OpenSSL was built in. It |
| 9524 | designates a PEM file containing both the required certificates and any |
| 9525 | associated private keys. This file can be built by concatenating multiple |
| 9526 | PEM files into one (e.g. cat cert.pem key.pem > combined.pem). If your CA |
| 9527 | requires an intermediate certificate, this can also be concatenated into this |
| 9528 | file. |
| 9529 | |
| 9530 | If the OpenSSL used supports Diffie-Hellman, parameters present in this file |
| 9531 | are loaded. |
| 9532 | |
| 9533 | If a directory name is used instead of a PEM file, then all files found in |
Cyril Bonté | 3180f7b | 2015-01-25 00:16:08 +0100 | [diff] [blame] | 9534 | that directory will be loaded in alphabetic order unless their name ends with |
Janusz Dziemidowicz | 2c701b5 | 2015-03-07 23:03:59 +0100 | [diff] [blame] | 9535 | '.issuer', '.ocsp' or '.sctl' (reserved extensions). This directive may be |
| 9536 | specified multiple times in order to load certificates from multiple files or |
| 9537 | directories. The certificates will be presented to clients who provide a |
| 9538 | valid TLS Server Name Indication field matching one of their CN or alt |
| 9539 | subjects. Wildcards are supported, where a wildcard character '*' is used |
| 9540 | instead of the first hostname component (eg: *.example.org matches |
| 9541 | www.example.org but not www.sub.example.org). |
Alex Davies | 0fbf016 | 2013-03-02 16:04:50 +0000 | [diff] [blame] | 9542 | |
| 9543 | If no SNI is provided by the client or if the SSL library does not support |
| 9544 | TLS extensions, or if the client provides an SNI hostname which does not |
| 9545 | match any certificate, then the first loaded certificate will be presented. |
| 9546 | This means that when loading certificates from a directory, it is highly |
Cyril Bonté | 3180f7b | 2015-01-25 00:16:08 +0100 | [diff] [blame] | 9547 | recommended to load the default one first as a file or to ensure that it will |
| 9548 | always be the first one in the directory. |
Alex Davies | 0fbf016 | 2013-03-02 16:04:50 +0000 | [diff] [blame] | 9549 | |
Emeric Brun | e032bfa | 2012-09-28 13:01:45 +0200 | [diff] [blame] | 9550 | Note that the same cert may be loaded multiple times without side effects. |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9551 | |
Alex Davies | 0fbf016 | 2013-03-02 16:04:50 +0000 | [diff] [blame] | 9552 | Some CAs (such as Godaddy) offer a drop down list of server types that do not |
| 9553 | include HAProxy when obtaining a certificate. If this happens be sure to |
Godbach | 8bf60a1 | 2014-04-21 21:42:41 +0800 | [diff] [blame] | 9554 | choose a webserver that the CA believes requires an intermediate CA (for |
Alex Davies | 0fbf016 | 2013-03-02 16:04:50 +0000 | [diff] [blame] | 9555 | Godaddy, selection Apache Tomcat will get the correct bundle, but many |
| 9556 | others, e.g. nginx, result in a wrong bundle that will not work for some |
| 9557 | clients). |
| 9558 | |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 9559 | For each PEM file, haproxy checks for the presence of file at the same path |
| 9560 | suffixed by ".ocsp". If such file is found, support for the TLS Certificate |
| 9561 | Status Request extension (also known as "OCSP stapling") is automatically |
| 9562 | enabled. The content of this file is optional. If not empty, it must contain |
| 9563 | a valid OCSP Response in DER format. In order to be valid an OCSP Response |
| 9564 | must comply with the following rules: it has to indicate a good status, |
| 9565 | it has to be a single response for the certificate of the PEM file, and it |
| 9566 | has to be valid at the moment of addition. If these rules are not respected |
| 9567 | the OCSP Response is ignored and a warning is emitted. In order to identify |
| 9568 | which certificate an OCSP Response applies to, the issuer's certificate is |
| 9569 | necessary. If the issuer's certificate is not found in the PEM file, it will |
| 9570 | be loaded from a file at the same path as the PEM file suffixed by ".issuer" |
| 9571 | if it exists otherwise it will fail with an error. |
| 9572 | |
Janusz Dziemidowicz | 2c701b5 | 2015-03-07 23:03:59 +0100 | [diff] [blame] | 9573 | For each PEM file, haproxy also checks for the presence of file at the same |
| 9574 | path suffixed by ".sctl". If such file is found, support for Certificate |
| 9575 | Transparency (RFC6962) TLS extension is enabled. The file must contain a |
| 9576 | valid Signed Certificate Timestamp List, as described in RFC. File is parsed |
| 9577 | to check basic syntax, but no signatures are verified. |
| 9578 | |
Emeric Brun | b6dc934 | 2012-09-28 17:55:37 +0200 | [diff] [blame] | 9579 | crt-ignore-err <errors> |
Alex Davies | 0fbf016 | 2013-03-02 16:04:50 +0000 | [diff] [blame] | 9580 | This setting is only available when support for OpenSSL was built in. Sets a |
| 9581 | comma separated list of errorIDs to ignore during verify at depth == 0. If |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9582 | set to 'all', all errors are ignored. SSL handshake is not aborted if an error |
Alex Davies | 0fbf016 | 2013-03-02 16:04:50 +0000 | [diff] [blame] | 9583 | is ignored. |
Emeric Brun | b6dc934 | 2012-09-28 17:55:37 +0200 | [diff] [blame] | 9584 | |
Emmanuel Hocdet | fe61656 | 2013-01-22 15:31:15 +0100 | [diff] [blame] | 9585 | crt-list <file> |
| 9586 | This setting is only available when support for OpenSSL was built in. It |
Emmanuel Hocdet | 7c41a1b | 2013-05-07 20:20:06 +0200 | [diff] [blame] | 9587 | designates a list of PEM file with an optional list of SNI filter per |
| 9588 | certificate, with the following format for each line : |
Emmanuel Hocdet | fe61656 | 2013-01-22 15:31:15 +0100 | [diff] [blame] | 9589 | |
Emmanuel Hocdet | 7c41a1b | 2013-05-07 20:20:06 +0200 | [diff] [blame] | 9590 | <crtfile> [[!]<snifilter> ...] |
Emmanuel Hocdet | fe61656 | 2013-01-22 15:31:15 +0100 | [diff] [blame] | 9591 | |
Emmanuel Hocdet | 7c41a1b | 2013-05-07 20:20:06 +0200 | [diff] [blame] | 9592 | Wildcards are supported in the SNI filter. Negative filter are also supported, |
| 9593 | only useful in combination with a wildcard filter to exclude a particular SNI. |
| 9594 | The certificates will be presented to clients who provide a valid TLS Server |
| 9595 | Name Indication field matching one of the SNI filters. If no SNI filter is |
| 9596 | specified, the CN and alt subjects are used. This directive may be specified |
| 9597 | multiple times. See the "crt" option for more information. The default |
| 9598 | certificate is still needed to meet OpenSSL expectations. If it is not used, |
| 9599 | the 'strict-sni' option may be used. |
Emmanuel Hocdet | fe61656 | 2013-01-22 15:31:15 +0100 | [diff] [blame] | 9600 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9601 | defer-accept |
| 9602 | Is an optional keyword which is supported only on certain Linux kernels. It |
| 9603 | states that a connection will only be accepted once some data arrive on it, |
| 9604 | or at worst after the first retransmit. This should be used only on protocols |
| 9605 | for which the client talks first (eg: HTTP). It can slightly improve |
| 9606 | performance by ensuring that most of the request is already available when |
| 9607 | the connection is accepted. On the other hand, it will not be able to detect |
| 9608 | connections which don't talk. It is important to note that this option is |
| 9609 | broken in all kernels up to 2.6.31, as the connection is never accepted until |
| 9610 | the client talks. This can cause issues with front firewalls which would see |
| 9611 | an established connection while the proxy will only see it in SYN_RECV. This |
| 9612 | option is only supported on TCPv4/TCPv6 sockets and ignored by other ones. |
| 9613 | |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 9614 | force-sslv3 |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9615 | This option enforces use of SSLv3 only on SSL connections instantiated from |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 9616 | this listener. SSLv3 is generally less expensive than the TLS counterparts |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 9617 | for high connection rates. This option is also available on global statement |
| 9618 | "ssl-default-bind-options". See also "no-tlsv*" and "no-sslv3". |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 9619 | |
| 9620 | force-tlsv10 |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9621 | This option enforces use of TLSv1.0 only on SSL connections instantiated from |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 9622 | this listener. This option is also available on global statement |
| 9623 | "ssl-default-bind-options". See also "no-tlsv*" and "no-sslv3". |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 9624 | |
| 9625 | force-tlsv11 |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9626 | This option enforces use of TLSv1.1 only on SSL connections instantiated from |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 9627 | this listener. This option is also available on global statement |
| 9628 | "ssl-default-bind-options". See also "no-tlsv*", and "no-sslv3". |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 9629 | |
| 9630 | force-tlsv12 |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9631 | This option enforces use of TLSv1.2 only on SSL connections instantiated from |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 9632 | this listener. This option is also available on global statement |
| 9633 | "ssl-default-bind-options". See also "no-tlsv*", and "no-sslv3". |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 9634 | |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 9635 | generate-certificates |
| 9636 | This setting is only available when support for OpenSSL was built in. It |
| 9637 | enables the dynamic SSL certificates generation. A CA certificate and its |
| 9638 | private key are necessary (see 'ca-sign-file'). When HAProxy is configured as |
| 9639 | a transparent forward proxy, SSL requests generate errors because of a common |
| 9640 | name mismatch on the certificate presented to the client. With this option |
| 9641 | enabled, HAProxy will try to forge a certificate using the SNI hostname |
| 9642 | indicated by the client. This is done only if no certificate matches the SNI |
| 9643 | hostname (see 'crt-list'). If an error occurs, the default certificate is |
| 9644 | used, else the 'strict-sni' option is set. |
| 9645 | It can also be used when HAProxy is configured as a reverse proxy to ease the |
| 9646 | deployment of an architecture with many backends. |
| 9647 | |
| 9648 | Creating a SSL certificate is an expensive operation, so a LRU cache is used |
| 9649 | to store forged certificates (see 'tune.ssl.ssl-ctx-cache-size'). It |
| 9650 | increases the HAProxy's memroy footprint to reduce latency when the same |
| 9651 | certificate is used many times. |
| 9652 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9653 | gid <gid> |
| 9654 | Sets the group of the UNIX sockets to the designated system gid. It can also |
| 9655 | be set by default in the global section's "unix-bind" statement. Note that |
| 9656 | some platforms simply ignore this. This setting is equivalent to the "group" |
| 9657 | setting except that the group ID is used instead of its name. This setting is |
| 9658 | ignored by non UNIX sockets. |
| 9659 | |
| 9660 | group <group> |
| 9661 | Sets the group of the UNIX sockets to the designated system group. It can |
| 9662 | also be set by default in the global section's "unix-bind" statement. Note |
| 9663 | that some platforms simply ignore this. This setting is equivalent to the |
| 9664 | "gid" setting except that the group name is used instead of its gid. This |
| 9665 | setting is ignored by non UNIX sockets. |
| 9666 | |
| 9667 | id <id> |
| 9668 | Fixes the socket ID. By default, socket IDs are automatically assigned, but |
| 9669 | sometimes it is more convenient to fix them to ease monitoring. This value |
| 9670 | must be strictly positive and unique within the listener/frontend. This |
| 9671 | option can only be used when defining only a single socket. |
| 9672 | |
| 9673 | interface <interface> |
Lukas Tribus | fce2e96 | 2013-02-12 22:13:19 +0100 | [diff] [blame] | 9674 | Restricts the socket to a specific interface. When specified, only packets |
| 9675 | received from that particular interface are processed by the socket. This is |
| 9676 | currently only supported on Linux. The interface must be a primary system |
| 9677 | interface, not an aliased interface. It is also possible to bind multiple |
| 9678 | frontends to the same address if they are bound to different interfaces. Note |
| 9679 | that binding to a network interface requires root privileges. This parameter |
| 9680 | is only compatible with TCPv4/TCPv6 sockets. |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9681 | |
Willy Tarreau | abb175f | 2012-09-24 12:43:26 +0200 | [diff] [blame] | 9682 | level <level> |
| 9683 | This setting is used with the stats sockets only to restrict the nature of |
| 9684 | the commands that can be issued on the socket. It is ignored by other |
| 9685 | sockets. <level> can be one of : |
| 9686 | - "user" is the least privileged level ; only non-sensitive stats can be |
| 9687 | read, and no change is allowed. It would make sense on systems where it |
| 9688 | is not easy to restrict access to the socket. |
| 9689 | - "operator" is the default level and fits most common uses. All data can |
| 9690 | be read, and only non-sensitive changes are permitted (eg: clear max |
| 9691 | counters). |
| 9692 | - "admin" should be used with care, as everything is permitted (eg: clear |
| 9693 | all counters). |
| 9694 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9695 | maxconn <maxconn> |
| 9696 | Limits the sockets to this number of concurrent connections. Extraneous |
| 9697 | connections will remain in the system's backlog until a connection is |
| 9698 | released. If unspecified, the limit will be the same as the frontend's |
| 9699 | maxconn. Note that in case of port ranges or multiple addresses, the same |
| 9700 | value will be applied to each socket. This setting enables different |
| 9701 | limitations on expensive sockets, for instance SSL entries which may easily |
| 9702 | eat all memory. |
| 9703 | |
| 9704 | mode <mode> |
| 9705 | Sets the octal mode used to define access permissions on the UNIX socket. It |
| 9706 | can also be set by default in the global section's "unix-bind" statement. |
| 9707 | Note that some platforms simply ignore this. This setting is ignored by non |
| 9708 | UNIX sockets. |
| 9709 | |
| 9710 | mss <maxseg> |
| 9711 | Sets the TCP Maximum Segment Size (MSS) value to be advertised on incoming |
| 9712 | connections. This can be used to force a lower MSS for certain specific |
| 9713 | ports, for instance for connections passing through a VPN. Note that this |
| 9714 | relies on a kernel feature which is theoretically supported under Linux but |
| 9715 | was buggy in all versions prior to 2.6.28. It may or may not work on other |
| 9716 | operating systems. It may also not change the advertised value but change the |
| 9717 | effective size of outgoing segments. The commonly advertised value for TCPv4 |
| 9718 | over Ethernet networks is 1460 = 1500(MTU) - 40(IP+TCP). If this value is |
| 9719 | positive, it will be used as the advertised MSS. If it is negative, it will |
| 9720 | indicate by how much to reduce the incoming connection's advertised MSS for |
| 9721 | outgoing segments. This parameter is only compatible with TCP v4/v6 sockets. |
| 9722 | |
| 9723 | name <name> |
| 9724 | Sets an optional name for these sockets, which will be reported on the stats |
| 9725 | page. |
| 9726 | |
| 9727 | nice <nice> |
| 9728 | Sets the 'niceness' of connections initiated from the socket. Value must be |
| 9729 | in the range -1024..1024 inclusive, and defaults to zero. Positive values |
| 9730 | means that such connections are more friendly to others and easily offer |
| 9731 | their place in the scheduler. On the opposite, negative values mean that |
| 9732 | connections want to run with a higher priority than others. The difference |
| 9733 | only happens under high loads when the system is close to saturation. |
| 9734 | Negative values are appropriate for low-latency or administration services, |
| 9735 | and high values are generally recommended for CPU intensive tasks such as SSL |
| 9736 | processing or bulk transfers which are less sensible to latency. For example, |
| 9737 | it may make sense to use a positive value for an SMTP socket and a negative |
| 9738 | one for an RDP socket. |
| 9739 | |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 9740 | no-sslv3 |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9741 | This setting is only available when support for OpenSSL was built in. It |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9742 | disables support for SSLv3 on any sockets instantiated from the listener when |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9743 | SSL is supported. Note that SSLv2 is forced disabled in the code and cannot |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 9744 | be enabled using any configuration option. This option is also available on |
| 9745 | global statement "ssl-default-bind-options". See also "force-tls*", |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 9746 | and "force-sslv3". |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9747 | |
Emeric Brun | 90ad872 | 2012-10-02 14:00:59 +0200 | [diff] [blame] | 9748 | no-tls-tickets |
| 9749 | This setting is only available when support for OpenSSL was built in. It |
| 9750 | disables the stateless session resumption (RFC 5077 TLS Ticket |
| 9751 | extension) and force to use stateful session resumption. Stateless |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 9752 | session resumption is more expensive in CPU usage. This option is also |
| 9753 | available on global statement "ssl-default-bind-options". |
Emeric Brun | 90ad872 | 2012-10-02 14:00:59 +0200 | [diff] [blame] | 9754 | |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 9755 | no-tlsv10 |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9756 | This setting is only available when support for OpenSSL was built in. It |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9757 | disables support for TLSv1.0 on any sockets instantiated from the listener |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 9758 | when SSL is supported. Note that SSLv2 is forced disabled in the code and |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 9759 | cannot be enabled using any configuration option. This option is also |
| 9760 | available on global statement "ssl-default-bind-options". See also |
| 9761 | "force-tlsv*", and "force-sslv3". |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9762 | |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 9763 | no-tlsv11 |
Emeric Brun | f5da493 | 2012-09-28 19:42:54 +0200 | [diff] [blame] | 9764 | This setting is only available when support for OpenSSL was built in. It |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9765 | disables support for TLSv1.1 on any sockets instantiated from the listener |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 9766 | when SSL is supported. Note that SSLv2 is forced disabled in the code and |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 9767 | cannot be enabled using any configuration option. This option is also |
| 9768 | available on global statement "ssl-default-bind-options". See also |
| 9769 | "force-tlsv*", and "force-sslv3". |
Emeric Brun | f5da493 | 2012-09-28 19:42:54 +0200 | [diff] [blame] | 9770 | |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 9771 | no-tlsv12 |
Emeric Brun | f5da493 | 2012-09-28 19:42:54 +0200 | [diff] [blame] | 9772 | This setting is only available when support for OpenSSL was built in. It |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9773 | disables support for TLSv1.2 on any sockets instantiated from the listener |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 9774 | when SSL is supported. Note that SSLv2 is forced disabled in the code and |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 9775 | cannot be enabled using any configuration option. This option is also |
| 9776 | available on global statement "ssl-default-bind-options". See also |
| 9777 | "force-tlsv*", and "force-sslv3". |
Emeric Brun | f5da493 | 2012-09-28 19:42:54 +0200 | [diff] [blame] | 9778 | |
Willy Tarreau | 6c9a3d5 | 2012-10-18 18:57:14 +0200 | [diff] [blame] | 9779 | npn <protocols> |
| 9780 | This enables the NPN TLS extension and advertises the specified protocol list |
| 9781 | as supported on top of NPN. The protocol list consists in a comma-delimited |
| 9782 | list of protocol names, for instance: "http/1.1,http/1.0" (without quotes). |
| 9783 | This requires that the SSL library is build with support for TLS extensions |
Willy Tarreau | ab861d3 | 2013-04-02 02:30:41 +0200 | [diff] [blame] | 9784 | enabled (check with haproxy -vv). Note that the NPN extension has been |
| 9785 | replaced with the ALPN extension (see the "alpn" keyword). |
Willy Tarreau | 6c9a3d5 | 2012-10-18 18:57:14 +0200 | [diff] [blame] | 9786 | |
Willy Tarreau | 6ae1ba6 | 2014-05-07 19:01:58 +0200 | [diff] [blame] | 9787 | process [ all | odd | even | <number 1-64>[-<number 1-64>] ] |
| 9788 | This restricts the list of processes on which this listener is allowed to |
| 9789 | run. It does not enforce any process but eliminates those which do not match. |
| 9790 | If the frontend uses a "bind-process" setting, the intersection between the |
| 9791 | two is applied. If in the end the listener is not allowed to run on any |
| 9792 | remaining process, a warning is emitted, and the listener will either run on |
| 9793 | the first process of the listener if a single process was specified, or on |
| 9794 | all of its processes if multiple processes were specified. For the unlikely |
Willy Tarreau | ae30253 | 2014-05-07 19:22:24 +0200 | [diff] [blame] | 9795 | case where several ranges are needed, this directive may be repeated. The |
| 9796 | main purpose of this directive is to be used with the stats sockets and have |
| 9797 | one different socket per process. The second purpose is to have multiple bind |
| 9798 | lines sharing the same IP:port but not the same process in a listener, so |
| 9799 | that the system can distribute the incoming connections into multiple queues |
| 9800 | and allow a smoother inter-process load balancing. Currently Linux 3.9 and |
| 9801 | above is known for supporting this. See also "bind-process" and "nbproc". |
Willy Tarreau | 6ae1ba6 | 2014-05-07 19:01:58 +0200 | [diff] [blame] | 9802 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9803 | ssl |
| 9804 | This setting is only available when support for OpenSSL was built in. It |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9805 | enables SSL deciphering on connections instantiated from this listener. A |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9806 | certificate is necessary (see "crt" above). All contents in the buffers will |
| 9807 | appear in clear text, so that ACLs and HTTP processing will only have access |
| 9808 | to deciphered contents. |
| 9809 | |
Emmanuel Hocdet | 6562337 | 2013-01-24 17:17:15 +0100 | [diff] [blame] | 9810 | strict-sni |
| 9811 | This setting is only available when support for OpenSSL was built in. The |
| 9812 | SSL/TLS negotiation is allow only if the client provided an SNI which match |
| 9813 | a certificate. The default certificate is not used. |
| 9814 | See the "crt" option for more information. |
| 9815 | |
Willy Tarreau | 2af207a | 2015-02-04 00:45:58 +0100 | [diff] [blame] | 9816 | tcp-ut <delay> |
| 9817 | Sets the TCP User Timeout for all incoming connections instanciated from this |
| 9818 | listening socket. This option is available on Linux since version 2.6.37. It |
| 9819 | allows haproxy to configure a timeout for sockets which contain data not |
| 9820 | receiving an acknoledgement for the configured delay. This is especially |
| 9821 | useful on long-lived connections experiencing long idle periods such as |
| 9822 | remote terminals or database connection pools, where the client and server |
| 9823 | timeouts must remain high to allow a long period of idle, but where it is |
| 9824 | important to detect that the client has disappeared in order to release all |
| 9825 | resources associated with its connection (and the server's session). The |
| 9826 | argument is a delay expressed in milliseconds by default. This only works |
| 9827 | for regular TCP connections, and is ignored for other protocols. |
| 9828 | |
Willy Tarreau | 1c862c5 | 2012-10-05 16:21:00 +0200 | [diff] [blame] | 9829 | tfo |
Lukas Tribus | 0defb90 | 2013-02-13 23:35:39 +0100 | [diff] [blame] | 9830 | Is an optional keyword which is supported only on Linux kernels >= 3.7. It |
Willy Tarreau | 1c862c5 | 2012-10-05 16:21:00 +0200 | [diff] [blame] | 9831 | enables TCP Fast Open on the listening socket, which means that clients which |
| 9832 | support this feature will be able to send a request and receive a response |
| 9833 | during the 3-way handshake starting from second connection, thus saving one |
| 9834 | round-trip after the first connection. This only makes sense with protocols |
| 9835 | that use high connection rates and where each round trip matters. This can |
| 9836 | possibly cause issues with many firewalls which do not accept data on SYN |
| 9837 | packets, so this option should only be enabled once well tested. This option |
Lukas Tribus | 0999f76 | 2013-04-02 16:43:24 +0200 | [diff] [blame] | 9838 | is only supported on TCPv4/TCPv6 sockets and ignored by other ones. You may |
| 9839 | need to build HAProxy with USE_TFO=1 if your libc doesn't define |
| 9840 | TCP_FASTOPEN. |
Willy Tarreau | 1c862c5 | 2012-10-05 16:21:00 +0200 | [diff] [blame] | 9841 | |
Nenad Merdanovic | 188ad3e | 2015-02-27 19:56:50 +0100 | [diff] [blame] | 9842 | tls-ticket-keys <keyfile> |
| 9843 | Sets the TLS ticket keys file to load the keys from. The keys need to be 48 |
| 9844 | bytes long, encoded with base64 (ex. openssl rand -base64 48). Number of keys |
| 9845 | is specified by the TLS_TICKETS_NO build option (default 3) and at least as |
| 9846 | many keys need to be present in the file. Last TLS_TICKETS_NO keys will be |
| 9847 | used for decryption and the penultimate one for encryption. This enables easy |
| 9848 | key rotation by just appending new key to the file and reloading the process. |
| 9849 | Keys must be periodically rotated (ex. every 12h) or Perfect Forward Secrecy |
| 9850 | is compromised. It is also a good idea to keep the keys off any permanent |
| 9851 | storage such as hard drives (hint: use tmpfs and don't swap those files). |
| 9852 | Lifetime hint can be changed using tune.ssl.timeout. |
| 9853 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9854 | transparent |
| 9855 | Is an optional keyword which is supported only on certain Linux kernels. It |
| 9856 | indicates that the addresses will be bound even if they do not belong to the |
| 9857 | local machine, and that packets targeting any of these addresses will be |
| 9858 | intercepted just as if the addresses were locally configured. This normally |
| 9859 | requires that IP forwarding is enabled. Caution! do not use this with the |
| 9860 | default address '*', as it would redirect any traffic for the specified port. |
| 9861 | This keyword is available only when HAProxy is built with USE_LINUX_TPROXY=1. |
| 9862 | This parameter is only compatible with TCPv4 and TCPv6 sockets, depending on |
| 9863 | kernel version. Some distribution kernels include backports of the feature, |
| 9864 | so check for support with your vendor. |
| 9865 | |
Willy Tarreau | 77e3af9 | 2012-11-24 15:07:23 +0100 | [diff] [blame] | 9866 | v4v6 |
| 9867 | Is an optional keyword which is supported only on most recent systems |
| 9868 | including Linux kernels >= 2.4.21. It is used to bind a socket to both IPv4 |
| 9869 | and IPv6 when it uses the default address. Doing so is sometimes necessary |
| 9870 | on systems which bind to IPv6 only by default. It has no effect on non-IPv6 |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 9871 | sockets, and is overridden by the "v6only" option. |
Willy Tarreau | 77e3af9 | 2012-11-24 15:07:23 +0100 | [diff] [blame] | 9872 | |
Willy Tarreau | 9b6700f | 2012-11-24 11:55:28 +0100 | [diff] [blame] | 9873 | v6only |
| 9874 | Is an optional keyword which is supported only on most recent systems |
| 9875 | including Linux kernels >= 2.4.21. It is used to bind a socket to IPv6 only |
| 9876 | when it uses the default address. Doing so is sometimes preferred to doing it |
Willy Tarreau | 77e3af9 | 2012-11-24 15:07:23 +0100 | [diff] [blame] | 9877 | system-wide as it is per-listener. It has no effect on non-IPv6 sockets and |
| 9878 | has precedence over the "v4v6" option. |
Willy Tarreau | 9b6700f | 2012-11-24 11:55:28 +0100 | [diff] [blame] | 9879 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9880 | uid <uid> |
| 9881 | Sets the owner of the UNIX sockets to the designated system uid. It can also |
| 9882 | be set by default in the global section's "unix-bind" statement. Note that |
| 9883 | some platforms simply ignore this. This setting is equivalent to the "user" |
| 9884 | setting except that the user numeric ID is used instead of its name. This |
| 9885 | setting is ignored by non UNIX sockets. |
| 9886 | |
| 9887 | user <user> |
| 9888 | Sets the owner of the UNIX sockets to the designated system user. It can also |
| 9889 | be set by default in the global section's "unix-bind" statement. Note that |
| 9890 | some platforms simply ignore this. This setting is equivalent to the "uid" |
| 9891 | setting except that the user name is used instead of its uid. This setting is |
| 9892 | ignored by non UNIX sockets. |
| 9893 | |
Emeric Brun | 1a073b4 | 2012-09-28 17:07:34 +0200 | [diff] [blame] | 9894 | verify [none|optional|required] |
| 9895 | This setting is only available when support for OpenSSL was built in. If set |
| 9896 | to 'none', client certificate is not requested. This is the default. In other |
| 9897 | cases, a client certificate is requested. If the client does not provide a |
| 9898 | certificate after the request and if 'verify' is set to 'required', then the |
| 9899 | handshake is aborted, while it would have succeeded if set to 'optional'. The |
Emeric Brun | fd33a26 | 2012-10-11 16:28:27 +0200 | [diff] [blame] | 9900 | certificate provided by the client is always verified using CAs from |
| 9901 | 'ca-file' and optional CRLs from 'crl-file'. On verify failure the handshake |
| 9902 | is aborted, regardless of the 'verify' option, unless the error code exactly |
| 9903 | matches one of those listed with 'ca-ignore-err' or 'crt-ignore-err'. |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 9904 | |
Willy Tarreau | b6205fd | 2012-09-24 12:27:33 +0200 | [diff] [blame] | 9905 | 5.2. Server and default-server options |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 9906 | ------------------------------------ |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 9907 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 9908 | The "server" and "default-server" keywords support a certain number of settings |
| 9909 | which are all passed as arguments on the server line. The order in which those |
| 9910 | arguments appear does not count, and they are all optional. Some of those |
| 9911 | settings are single words (booleans) while others expect one or several values |
| 9912 | after them. In this case, the values must immediately follow the setting name. |
| 9913 | Except default-server, all those settings must be specified after the server's |
| 9914 | address if they are used: |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 9915 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 9916 | server <name> <address>[:port] [settings ...] |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 9917 | default-server [settings ...] |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 9918 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 9919 | The currently supported settings are the following ones. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 9920 | |
Willy Tarreau | ceb4ac9 | 2012-04-28 00:41:46 +0200 | [diff] [blame] | 9921 | addr <ipv4|ipv6> |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 9922 | Using the "addr" parameter, it becomes possible to use a different IP address |
| 9923 | to send health-checks. On some servers, it may be desirable to dedicate an IP |
| 9924 | address to specific component able to perform complex tests which are more |
| 9925 | suitable to health-checks than the application. This parameter is ignored if |
| 9926 | the "check" parameter is not set. See also the "port" parameter. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 9927 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 9928 | Supported in default-server: No |
| 9929 | |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9930 | agent-check |
| 9931 | Enable an auxiliary agent check which is run independently of a regular |
Willy Tarreau | 81f5d94 | 2013-12-09 20:51:51 +0100 | [diff] [blame] | 9932 | health check. An agent health check is performed by making a TCP connection |
| 9933 | to the port set by the "agent-port" parameter and reading an ASCII string. |
| 9934 | The string is made of a series of words delimited by spaces, tabs or commas |
| 9935 | in any order, optionally terminated by '\r' and/or '\n', each consisting of : |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9936 | |
Willy Tarreau | 81f5d94 | 2013-12-09 20:51:51 +0100 | [diff] [blame] | 9937 | - An ASCII representation of a positive integer percentage, e.g. "75%". |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9938 | Values in this format will set the weight proportional to the initial |
Willy Tarreau | c5af3a6 | 2014-10-07 15:27:33 +0200 | [diff] [blame] | 9939 | weight of a server as configured when haproxy starts. Note that a zero |
| 9940 | weight is reported on the stats page as "DRAIN" since it has the same |
| 9941 | effect on the server (it's removed from the LB farm). |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9942 | |
Willy Tarreau | 81f5d94 | 2013-12-09 20:51:51 +0100 | [diff] [blame] | 9943 | - The word "ready". This will turn the server's administrative state to the |
| 9944 | READY mode, thus cancelling any DRAIN or MAINT state |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9945 | |
Willy Tarreau | 81f5d94 | 2013-12-09 20:51:51 +0100 | [diff] [blame] | 9946 | - The word "drain". This will turn the server's administrative state to the |
| 9947 | DRAIN mode, thus it will not accept any new connections other than those |
| 9948 | that are accepted via persistence. |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9949 | |
Willy Tarreau | 81f5d94 | 2013-12-09 20:51:51 +0100 | [diff] [blame] | 9950 | - The word "maint". This will turn the server's administrative state to the |
| 9951 | MAINT mode, thus it will not accept any new connections at all, and health |
| 9952 | checks will be stopped. |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9953 | |
Willy Tarreau | 81f5d94 | 2013-12-09 20:51:51 +0100 | [diff] [blame] | 9954 | - The words "down", "failed", or "stopped", optionally followed by a |
| 9955 | description string after a sharp ('#'). All of these mark the server's |
| 9956 | operating state as DOWN, but since the word itself is reported on the stats |
| 9957 | page, the difference allows an administrator to know if the situation was |
| 9958 | expected or not : the service may intentionally be stopped, may appear up |
| 9959 | but fail some validity tests, or may be seen as down (eg: missing process, |
| 9960 | or port not responding). |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9961 | |
Willy Tarreau | 81f5d94 | 2013-12-09 20:51:51 +0100 | [diff] [blame] | 9962 | - The word "up" sets back the server's operating state as UP if health checks |
| 9963 | also report that the service is accessible. |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9964 | |
Willy Tarreau | 81f5d94 | 2013-12-09 20:51:51 +0100 | [diff] [blame] | 9965 | Parameters which are not advertised by the agent are not changed. For |
| 9966 | example, an agent might be designed to monitor CPU usage and only report a |
| 9967 | relative weight and never interact with the operating status. Similarly, an |
| 9968 | agent could be designed as an end-user interface with 3 radio buttons |
| 9969 | allowing an administrator to change only the administrative state. However, |
| 9970 | it is important to consider that only the agent may revert its own actions, |
| 9971 | so if a server is set to DRAIN mode or to DOWN state using the agent, the |
| 9972 | agent must implement the other equivalent actions to bring the service into |
| 9973 | operations again. |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9974 | |
Simon Horman | 2f1f955 | 2013-11-25 10:46:37 +0900 | [diff] [blame] | 9975 | Failure to connect to the agent is not considered an error as connectivity |
| 9976 | is tested by the regular health check which is enabled by the "check" |
Willy Tarreau | 81f5d94 | 2013-12-09 20:51:51 +0100 | [diff] [blame] | 9977 | parameter. Warning though, it is not a good idea to stop an agent after it |
| 9978 | reports "down", since only an agent reporting "up" will be able to turn the |
| 9979 | server up again. Note that the CLI on the Unix stats socket is also able to |
| 9980 | force an agent's result in order to workaround a bogus agent if needed. |
Simon Horman | 2f1f955 | 2013-11-25 10:46:37 +0900 | [diff] [blame] | 9981 | |
Willy Tarreau | 81f5d94 | 2013-12-09 20:51:51 +0100 | [diff] [blame] | 9982 | Requires the "agent-port" parameter to be set. See also the "agent-inter" |
| 9983 | parameter. |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 9984 | |
| 9985 | Supported in default-server: No |
| 9986 | |
| 9987 | agent-inter <delay> |
| 9988 | The "agent-inter" parameter sets the interval between two agent checks |
| 9989 | to <delay> milliseconds. If left unspecified, the delay defaults to 2000 ms. |
| 9990 | |
| 9991 | Just as with every other time-based parameter, it may be entered in any |
| 9992 | other explicit unit among { us, ms, s, m, h, d }. The "agent-inter" |
| 9993 | parameter also serves as a timeout for agent checks "timeout check" is |
| 9994 | not set. In order to reduce "resonance" effects when multiple servers are |
| 9995 | hosted on the same hardware, the agent and health checks of all servers |
| 9996 | are started with a small time offset between them. It is also possible to |
| 9997 | add some random noise in the agent and health checks interval using the |
| 9998 | global "spread-checks" keyword. This makes sense for instance when a lot |
| 9999 | of backends use the same servers. |
| 10000 | |
| 10001 | See also the "agent-check" and "agent-port" parameters. |
| 10002 | |
| 10003 | Supported in default-server: Yes |
| 10004 | |
| 10005 | agent-port <port> |
| 10006 | The "agent-port" parameter sets the TCP port used for agent checks. |
| 10007 | |
| 10008 | See also the "agent-check" and "agent-inter" parameters. |
| 10009 | |
| 10010 | Supported in default-server: Yes |
| 10011 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10012 | backup |
| 10013 | When "backup" is present on a server line, the server is only used in load |
| 10014 | balancing when all other non-backup servers are unavailable. Requests coming |
| 10015 | with a persistence cookie referencing the server will always be served |
| 10016 | though. By default, only the first operational backup server is used, unless |
| 10017 | the "allbackups" option is set in the backend. See also the "allbackups" |
| 10018 | option. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 10019 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10020 | Supported in default-server: No |
| 10021 | |
Emeric Brun | ef42d92 | 2012-10-11 16:11:36 +0200 | [diff] [blame] | 10022 | ca-file <cafile> |
| 10023 | This setting is only available when support for OpenSSL was built in. It |
| 10024 | designates a PEM file from which to load CA certificates used to verify |
| 10025 | server's certificate. |
| 10026 | |
| 10027 | Supported in default-server: No |
| 10028 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10029 | check |
| 10030 | This option enables health checks on the server. By default, a server is |
Patrick Mézard | b7aeec6 | 2012-01-22 16:01:22 +0100 | [diff] [blame] | 10031 | always considered available. If "check" is set, the server is available when |
| 10032 | accepting periodic TCP connections, to ensure that it is really able to serve |
| 10033 | requests. The default address and port to send the tests to are those of the |
| 10034 | server, and the default source is the same as the one defined in the |
| 10035 | backend. It is possible to change the address using the "addr" parameter, the |
| 10036 | port using the "port" parameter, the source address using the "source" |
| 10037 | address, and the interval and timers using the "inter", "rise" and "fall" |
Simon Horman | afc47ee | 2013-11-25 10:46:35 +0900 | [diff] [blame] | 10038 | parameters. The request method is define in the backend using the "httpchk", |
| 10039 | "smtpchk", "mysql-check", "pgsql-check" and "ssl-hello-chk" options. Please |
| 10040 | refer to those options and parameters for more information. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10041 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10042 | Supported in default-server: No |
| 10043 | |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 10044 | check-send-proxy |
| 10045 | This option forces emission of a PROXY protocol line with outgoing health |
| 10046 | checks, regardless of whether the server uses send-proxy or not for the |
| 10047 | normal traffic. By default, the PROXY protocol is enabled for health checks |
| 10048 | if it is already enabled for normal traffic and if no "port" nor "addr" |
| 10049 | directive is present. However, if such a directive is present, the |
| 10050 | "check-send-proxy" option needs to be used to force the use of the |
| 10051 | protocol. See also the "send-proxy" option for more information. |
| 10052 | |
| 10053 | Supported in default-server: No |
| 10054 | |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 10055 | check-ssl |
| 10056 | This option forces encryption of all health checks over SSL, regardless of |
| 10057 | whether the server uses SSL or not for the normal traffic. This is generally |
| 10058 | used when an explicit "port" or "addr" directive is specified and SSL health |
| 10059 | checks are not inherited. It is important to understand that this option |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 10060 | inserts an SSL transport layer below the checks, so that a simple TCP connect |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 10061 | check becomes an SSL connect, which replaces the old ssl-hello-chk. The most |
| 10062 | common use is to send HTTPS checks by combining "httpchk" with SSL checks. |
| 10063 | All SSL settings are common to health checks and traffic (eg: ciphers). |
| 10064 | See the "ssl" option for more information. |
| 10065 | |
| 10066 | Supported in default-server: No |
| 10067 | |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 10068 | ciphers <ciphers> |
| 10069 | This option sets the string describing the list of cipher algorithms that is |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 10070 | is negotiated during the SSL/TLS handshake with the server. The format of the |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 10071 | string is defined in "man 1 ciphers". When SSL is used to communicate with |
| 10072 | servers on the local network, it is common to see a weaker set of algorithms |
| 10073 | than what is used over the internet. Doing so reduces CPU usage on both the |
| 10074 | server and haproxy while still keeping it compatible with deployed software. |
| 10075 | Some algorithms such as RC4-SHA1 are reasonably cheap. If no security at all |
| 10076 | is needed and just connectivity, using DES can be appropriate. |
| 10077 | |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 10078 | Supported in default-server: No |
| 10079 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10080 | cookie <value> |
| 10081 | The "cookie" parameter sets the cookie value assigned to the server to |
| 10082 | <value>. This value will be checked in incoming requests, and the first |
| 10083 | operational server possessing the same value will be selected. In return, in |
| 10084 | cookie insertion or rewrite modes, this value will be assigned to the cookie |
| 10085 | sent to the client. There is nothing wrong in having several servers sharing |
| 10086 | the same cookie value, and it is in fact somewhat common between normal and |
| 10087 | backup servers. See also the "cookie" keyword in backend section. |
| 10088 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10089 | Supported in default-server: No |
| 10090 | |
Emeric Brun | ef42d92 | 2012-10-11 16:11:36 +0200 | [diff] [blame] | 10091 | crl-file <crlfile> |
| 10092 | This setting is only available when support for OpenSSL was built in. It |
| 10093 | designates a PEM file from which to load certificate revocation list used |
| 10094 | to verify server's certificate. |
| 10095 | |
| 10096 | Supported in default-server: No |
| 10097 | |
Emeric Brun | a7aa309 | 2012-10-26 12:58:00 +0200 | [diff] [blame] | 10098 | crt <cert> |
| 10099 | This setting is only available when support for OpenSSL was built in. |
| 10100 | It designates a PEM file from which to load both a certificate and the |
| 10101 | associated private key. This file can be built by concatenating both PEM |
| 10102 | files into one. This certificate will be sent if the server send a client |
| 10103 | certificate request. |
| 10104 | |
| 10105 | Supported in default-server: No |
| 10106 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 10107 | disabled |
| 10108 | The "disabled" keyword starts the server in the "disabled" state. That means |
| 10109 | that it is marked down in maintenance mode, and no connection other than the |
| 10110 | ones allowed by persist mode will reach it. It is very well suited to setup |
| 10111 | new servers, because normal traffic will never reach them, while it is still |
| 10112 | possible to test the service by making use of the force-persist mechanism. |
| 10113 | |
| 10114 | Supported in default-server: No |
| 10115 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10116 | error-limit <count> |
Willy Tarreau | 983e01e | 2010-01-11 18:42:06 +0100 | [diff] [blame] | 10117 | If health observing is enabled, the "error-limit" parameter specifies the |
| 10118 | number of consecutive errors that triggers event selected by the "on-error" |
| 10119 | option. By default it is set to 10 consecutive errors. |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 10120 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10121 | Supported in default-server: Yes |
| 10122 | |
| 10123 | See also the "check", "error-limit" and "on-error". |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 10124 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10125 | fall <count> |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10126 | The "fall" parameter states that a server will be considered as dead after |
| 10127 | <count> consecutive unsuccessful health checks. This value defaults to 3 if |
| 10128 | unspecified. See also the "check", "inter" and "rise" parameters. |
| 10129 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10130 | Supported in default-server: Yes |
| 10131 | |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 10132 | force-sslv3 |
| 10133 | This option enforces use of SSLv3 only when SSL is used to communicate with |
| 10134 | the server. SSLv3 is generally less expensive than the TLS counterparts for |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 10135 | high connection rates. This option is also available on global statement |
| 10136 | "ssl-default-server-options". See also "no-tlsv*", "no-sslv3". |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 10137 | |
| 10138 | Supported in default-server: No |
| 10139 | |
| 10140 | force-tlsv10 |
| 10141 | This option enforces use of TLSv1.0 only when SSL is used to communicate with |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 10142 | the server. This option is also available on global statement |
| 10143 | "ssl-default-server-options". See also "no-tlsv*", "no-sslv3". |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 10144 | |
| 10145 | Supported in default-server: No |
| 10146 | |
| 10147 | force-tlsv11 |
| 10148 | This option enforces use of TLSv1.1 only when SSL is used to communicate with |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 10149 | the server. This option is also available on global statement |
| 10150 | "ssl-default-server-options". See also "no-tlsv*", "no-sslv3". |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 10151 | |
| 10152 | Supported in default-server: No |
| 10153 | |
| 10154 | force-tlsv12 |
| 10155 | This option enforces use of TLSv1.2 only when SSL is used to communicate with |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 10156 | the server. This option is also available on global statement |
| 10157 | "ssl-default-server-options". See also "no-tlsv*", "no-sslv3". |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 10158 | |
| 10159 | Supported in default-server: No |
| 10160 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10161 | id <value> |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 10162 | Set a persistent ID for the server. This ID must be positive and unique for |
| 10163 | the proxy. An unused ID will automatically be assigned if unset. The first |
| 10164 | assigned value will be 1. This ID is currently only returned in statistics. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10165 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10166 | Supported in default-server: No |
| 10167 | |
| 10168 | inter <delay> |
| 10169 | fastinter <delay> |
| 10170 | downinter <delay> |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10171 | The "inter" parameter sets the interval between two consecutive health checks |
| 10172 | to <delay> milliseconds. If left unspecified, the delay defaults to 2000 ms. |
| 10173 | It is also possible to use "fastinter" and "downinter" to optimize delays |
| 10174 | between checks depending on the server state : |
| 10175 | |
Pieter Baauw | 44fc9df | 2015-09-17 21:30:46 +0200 | [diff] [blame] | 10176 | Server state | Interval used |
| 10177 | ----------------------------------------+---------------------------------- |
| 10178 | UP 100% (non-transitional) | "inter" |
| 10179 | ----------------------------------------+---------------------------------- |
| 10180 | Transitionally UP (going down "fall"), | "fastinter" if set, |
| 10181 | Transitionally DOWN (going up "rise"), | "inter" otherwise. |
| 10182 | or yet unchecked. | |
| 10183 | ----------------------------------------+---------------------------------- |
| 10184 | DOWN 100% (non-transitional) | "downinter" if set, |
| 10185 | | "inter" otherwise. |
| 10186 | ----------------------------------------+---------------------------------- |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 10187 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10188 | Just as with every other time-based parameter, they can be entered in any |
| 10189 | other explicit unit among { us, ms, s, m, h, d }. The "inter" parameter also |
| 10190 | serves as a timeout for health checks sent to servers if "timeout check" is |
| 10191 | not set. In order to reduce "resonance" effects when multiple servers are |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 10192 | hosted on the same hardware, the agent and health checks of all servers |
| 10193 | are started with a small time offset between them. It is also possible to |
| 10194 | add some random noise in the agent and health checks interval using the |
| 10195 | global "spread-checks" keyword. This makes sense for instance when a lot |
| 10196 | of backends use the same servers. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10197 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10198 | Supported in default-server: Yes |
| 10199 | |
| 10200 | maxconn <maxconn> |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10201 | The "maxconn" parameter specifies the maximal number of concurrent |
| 10202 | connections that will be sent to this server. If the number of incoming |
| 10203 | concurrent requests goes higher than this value, they will be queued, waiting |
| 10204 | for a connection to be released. This parameter is very important as it can |
| 10205 | save fragile servers from going down under extreme loads. If a "minconn" |
| 10206 | parameter is specified, the limit becomes dynamic. The default value is "0" |
| 10207 | which means unlimited. See also the "minconn" and "maxqueue" parameters, and |
| 10208 | the backend's "fullconn" keyword. |
| 10209 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10210 | Supported in default-server: Yes |
| 10211 | |
| 10212 | maxqueue <maxqueue> |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10213 | The "maxqueue" parameter specifies the maximal number of connections which |
| 10214 | will wait in the queue for this server. If this limit is reached, next |
| 10215 | requests will be redispatched to other servers instead of indefinitely |
| 10216 | waiting to be served. This will break persistence but may allow people to |
| 10217 | quickly re-log in when the server they try to connect to is dying. The |
| 10218 | default value is "0" which means the queue is unlimited. See also the |
| 10219 | "maxconn" and "minconn" parameters. |
| 10220 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10221 | Supported in default-server: Yes |
| 10222 | |
| 10223 | minconn <minconn> |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10224 | When the "minconn" parameter is set, the maxconn limit becomes a dynamic |
| 10225 | limit following the backend's load. The server will always accept at least |
| 10226 | <minconn> connections, never more than <maxconn>, and the limit will be on |
| 10227 | the ramp between both values when the backend has less than <fullconn> |
| 10228 | concurrent connections. This makes it possible to limit the load on the |
| 10229 | server during normal loads, but push it further for important loads without |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 10230 | overloading the server during exceptional loads. See also the "maxconn" |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10231 | and "maxqueue" parameters, as well as the "fullconn" backend keyword. |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 10232 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10233 | Supported in default-server: Yes |
| 10234 | |
Willy Tarreau | 2a3fb1c | 2015-02-05 16:47:07 +0100 | [diff] [blame] | 10235 | no-ssl-reuse |
| 10236 | This option disables SSL session reuse when SSL is used to communicate with |
| 10237 | the server. It will force the server to perform a full handshake for every |
| 10238 | new connection. It's probably only useful for benchmarking, troubleshooting, |
| 10239 | and for paranoid users. |
| 10240 | |
| 10241 | Supported in default-server: No |
| 10242 | |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 10243 | no-sslv3 |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 10244 | This option disables support for SSLv3 when SSL is used to communicate with |
| 10245 | the server. Note that SSLv2 is disabled in the code and cannot be enabled |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 10246 | using any configuration option. See also "force-sslv3", "force-tlsv*". |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 10247 | |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 10248 | Supported in default-server: No |
| 10249 | |
Emeric Brun | f9c5c47 | 2012-10-11 15:28:34 +0200 | [diff] [blame] | 10250 | no-tls-tickets |
| 10251 | This setting is only available when support for OpenSSL was built in. It |
| 10252 | disables the stateless session resumption (RFC 5077 TLS Ticket |
| 10253 | extension) and force to use stateful session resumption. Stateless |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 10254 | session resumption is more expensive in CPU usage for servers. This option |
| 10255 | is also available on global statement "ssl-default-server-options". |
Emeric Brun | f9c5c47 | 2012-10-11 15:28:34 +0200 | [diff] [blame] | 10256 | |
| 10257 | Supported in default-server: No |
| 10258 | |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 10259 | no-tlsv10 |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 10260 | This option disables support for TLSv1.0 when SSL is used to communicate with |
Emeric Brun | f5da493 | 2012-09-28 19:42:54 +0200 | [diff] [blame] | 10261 | the server. Note that SSLv2 is disabled in the code and cannot be enabled |
| 10262 | using any configuration option. TLSv1 is more expensive than SSLv3 so it |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 10263 | often makes sense to disable it when communicating with local servers. This |
| 10264 | option is also available on global statement "ssl-default-server-options". |
| 10265 | See also "force-sslv3", "force-tlsv*". |
Emeric Brun | f5da493 | 2012-09-28 19:42:54 +0200 | [diff] [blame] | 10266 | |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 10267 | Supported in default-server: No |
| 10268 | |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 10269 | no-tlsv11 |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 10270 | This option disables support for TLSv1.1 when SSL is used to communicate with |
Emeric Brun | f5da493 | 2012-09-28 19:42:54 +0200 | [diff] [blame] | 10271 | the server. Note that SSLv2 is disabled in the code and cannot be enabled |
| 10272 | using any configuration option. TLSv1 is more expensive than SSLv3 so it |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 10273 | often makes sense to disable it when communicating with local servers. This |
| 10274 | option is also available on global statement "ssl-default-server-options". |
| 10275 | See also "force-sslv3", "force-tlsv*". |
Emeric Brun | f5da493 | 2012-09-28 19:42:54 +0200 | [diff] [blame] | 10276 | |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 10277 | Supported in default-server: No |
| 10278 | |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 10279 | no-tlsv12 |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 10280 | This option disables support for TLSv1.2 when SSL is used to communicate with |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 10281 | the server. Note that SSLv2 is disabled in the code and cannot be enabled |
| 10282 | using any configuration option. TLSv1 is more expensive than SSLv3 so it |
Emeric Brun | 2c86cbf | 2014-10-30 15:56:50 +0100 | [diff] [blame] | 10283 | often makes sense to disable it when communicating with local servers. This |
| 10284 | option is also available on global statement "ssl-default-server-options". |
| 10285 | See also "force-sslv3", "force-tlsv*". |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 10286 | |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 10287 | Supported in default-server: No |
| 10288 | |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 10289 | non-stick |
| 10290 | Never add connections allocated to this sever to a stick-table. |
| 10291 | This may be used in conjunction with backup to ensure that |
| 10292 | stick-table persistence is disabled for backup servers. |
| 10293 | |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 10294 | Supported in default-server: No |
| 10295 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 10296 | observe <mode> |
| 10297 | This option enables health adjusting based on observing communication with |
| 10298 | the server. By default this functionality is disabled and enabling it also |
| 10299 | requires to enable health checks. There are two supported modes: "layer4" and |
| 10300 | "layer7". In layer4 mode, only successful/unsuccessful tcp connections are |
| 10301 | significant. In layer7, which is only allowed for http proxies, responses |
| 10302 | received from server are verified, like valid/wrong http code, unparsable |
Willy Tarreau | 150d146 | 2012-03-10 08:19:02 +0100 | [diff] [blame] | 10303 | headers, a timeout, etc. Valid status codes include 100 to 499, 501 and 505. |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 10304 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10305 | Supported in default-server: No |
| 10306 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 10307 | See also the "check", "on-error" and "error-limit". |
| 10308 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10309 | on-error <mode> |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 10310 | Select what should happen when enough consecutive errors are detected. |
| 10311 | Currently, four modes are available: |
| 10312 | - fastinter: force fastinter |
| 10313 | - fail-check: simulate a failed check, also forces fastinter (default) |
| 10314 | - sudden-death: simulate a pre-fatal failed health check, one more failed |
| 10315 | check will mark a server down, forces fastinter |
| 10316 | - mark-down: mark the server immediately down and force fastinter |
| 10317 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10318 | Supported in default-server: Yes |
| 10319 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 10320 | See also the "check", "observe" and "error-limit". |
| 10321 | |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 10322 | on-marked-down <action> |
| 10323 | Modify what occurs when a server is marked down. |
| 10324 | Currently one action is available: |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 10325 | - shutdown-sessions: Shutdown peer sessions. When this setting is enabled, |
| 10326 | all connections to the server are immediately terminated when the server |
| 10327 | goes down. It might be used if the health check detects more complex cases |
| 10328 | than a simple connection status, and long timeouts would cause the service |
| 10329 | to remain unresponsive for too long a time. For instance, a health check |
| 10330 | might detect that a database is stuck and that there's no chance to reuse |
| 10331 | existing connections anymore. Connections killed this way are logged with |
| 10332 | a 'D' termination code (for "Down"). |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 10333 | |
| 10334 | Actions are disabled by default |
| 10335 | |
| 10336 | Supported in default-server: Yes |
| 10337 | |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 10338 | on-marked-up <action> |
| 10339 | Modify what occurs when a server is marked up. |
| 10340 | Currently one action is available: |
| 10341 | - shutdown-backup-sessions: Shutdown sessions on all backup servers. This is |
| 10342 | done only if the server is not in backup state and if it is not disabled |
| 10343 | (it must have an effective weight > 0). This can be used sometimes to force |
| 10344 | an active server to take all the traffic back after recovery when dealing |
| 10345 | with long sessions (eg: LDAP, SQL, ...). Doing this can cause more trouble |
| 10346 | than it tries to solve (eg: incomplete transactions), so use this feature |
| 10347 | with extreme care. Sessions killed because a server comes up are logged |
| 10348 | with an 'U' termination code (for "Up"). |
| 10349 | |
| 10350 | Actions are disabled by default |
| 10351 | |
| 10352 | Supported in default-server: Yes |
| 10353 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10354 | port <port> |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10355 | Using the "port" parameter, it becomes possible to use a different port to |
| 10356 | send health-checks. On some servers, it may be desirable to dedicate a port |
| 10357 | to a specific component able to perform complex tests which are more suitable |
| 10358 | to health-checks than the application. It is common to run a simple script in |
| 10359 | inetd for instance. This parameter is ignored if the "check" parameter is not |
| 10360 | set. See also the "addr" parameter. |
| 10361 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10362 | Supported in default-server: Yes |
| 10363 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10364 | redir <prefix> |
| 10365 | The "redir" parameter enables the redirection mode for all GET and HEAD |
| 10366 | requests addressing this server. This means that instead of having HAProxy |
| 10367 | forward the request to the server, it will send an "HTTP 302" response with |
| 10368 | the "Location" header composed of this prefix immediately followed by the |
| 10369 | requested URI beginning at the leading '/' of the path component. That means |
| 10370 | that no trailing slash should be used after <prefix>. All invalid requests |
| 10371 | will be rejected, and all non-GET or HEAD requests will be normally served by |
| 10372 | the server. Note that since the response is completely forged, no header |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 10373 | mangling nor cookie insertion is possible in the response. However, cookies in |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10374 | requests are still analysed, making this solution completely usable to direct |
| 10375 | users to a remote location in case of local disaster. Main use consists in |
| 10376 | increasing bandwidth for static servers by having the clients directly |
| 10377 | connect to them. Note: never use a relative location here, it would cause a |
| 10378 | loop between the client and HAProxy! |
| 10379 | |
| 10380 | Example : server srv1 192.168.1.1:80 redir http://image1.mydomain.com check |
| 10381 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10382 | Supported in default-server: No |
| 10383 | |
| 10384 | rise <count> |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10385 | The "rise" parameter states that a server will be considered as operational |
| 10386 | after <count> consecutive successful health checks. This value defaults to 2 |
| 10387 | if unspecified. See also the "check", "inter" and "fall" parameters. |
| 10388 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10389 | Supported in default-server: Yes |
| 10390 | |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10391 | resolve-prefer <family> |
| 10392 | When DNS resolution is enabled for a server and multiple IP addresses from |
| 10393 | different families are returned, HAProxy will prefer using an IP address |
| 10394 | from the family mentioned in the "resolve-prefer" parameter. |
| 10395 | Available families: "ipv4" and "ipv6" |
| 10396 | |
Baptiste Assmann | c4aabae | 2015-08-04 22:43:06 +0200 | [diff] [blame] | 10397 | Default value: ipv6 |
| 10398 | |
| 10399 | Supported in default-server: Yes |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10400 | |
| 10401 | Example: server s1 app1.domain.com:80 resolvers mydns resolve-prefer ipv6 |
| 10402 | |
| 10403 | resolvers <id> |
| 10404 | Points to an existing "resolvers" section to resolve current server's |
| 10405 | hostname. |
Baptiste Assmann | 62b75b4 | 2015-09-09 01:11:36 +0200 | [diff] [blame] | 10406 | In order to be operational, DNS resolution requires that health check is |
| 10407 | enabled on the server. Actually, health checks triggers the DNS resolution. |
| 10408 | You must precise one 'resolvers' parameter on each server line where DNS |
| 10409 | resolution is required. |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10410 | |
Baptiste Assmann | 62b75b4 | 2015-09-09 01:11:36 +0200 | [diff] [blame] | 10411 | Supported in default-server: No |
| 10412 | |
| 10413 | Example: server s1 app1.domain.com:80 check resolvers mydns |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10414 | |
| 10415 | See also chapter 5.3 |
| 10416 | |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 10417 | send-proxy |
| 10418 | The "send-proxy" parameter enforces use of the PROXY protocol over any |
| 10419 | connection established to this server. The PROXY protocol informs the other |
| 10420 | end about the layer 3/4 addresses of the incoming connection, so that it can |
| 10421 | know the client's address or the public address it accessed to, whatever the |
| 10422 | upper layer protocol. For connections accepted by an "accept-proxy" listener, |
| 10423 | the advertised address will be used. Only TCPv4 and TCPv6 address families |
| 10424 | are supported. Other families such as Unix sockets, will report an UNKNOWN |
| 10425 | family. Servers using this option can fully be chained to another instance of |
| 10426 | haproxy listening with an "accept-proxy" setting. This setting must not be |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 10427 | used if the server isn't aware of the protocol. When health checks are sent |
| 10428 | to the server, the PROXY protocol is automatically used when this option is |
| 10429 | set, unless there is an explicit "port" or "addr" directive, in which case an |
| 10430 | explicit "check-send-proxy" directive would also be needed to use the PROXY |
| 10431 | protocol. See also the "accept-proxy" option of the "bind" keyword. |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 10432 | |
| 10433 | Supported in default-server: No |
| 10434 | |
David S | afb7683 | 2014-05-08 23:42:08 -0400 | [diff] [blame] | 10435 | send-proxy-v2 |
| 10436 | The "send-proxy-v2" parameter enforces use of the PROXY protocol version 2 |
| 10437 | over any connection established to this server. The PROXY protocol informs |
| 10438 | the other end about the layer 3/4 addresses of the incoming connection, so |
| 10439 | that it can know the client's address or the public address it accessed to, |
| 10440 | whatever the upper layer protocol. This setting must not be used if the |
| 10441 | server isn't aware of this version of the protocol. See also the "send-proxy" |
| 10442 | option of the "bind" keyword. |
| 10443 | |
| 10444 | Supported in default-server: No |
| 10445 | |
| 10446 | send-proxy-v2-ssl |
| 10447 | The "send-proxy-v2-ssl" parameter enforces use of the PROXY protocol version |
| 10448 | 2 over any connection established to this server. The PROXY protocol informs |
| 10449 | the other end about the layer 3/4 addresses of the incoming connection, so |
| 10450 | that it can know the client's address or the public address it accessed to, |
| 10451 | whatever the upper layer protocol. In addition, the SSL information extension |
| 10452 | of the PROXY protocol is added to the PROXY protocol header. This setting |
| 10453 | must not be used if the server isn't aware of this version of the protocol. |
| 10454 | See also the "send-proxy-v2" option of the "bind" keyword. |
| 10455 | |
| 10456 | Supported in default-server: No |
| 10457 | |
| 10458 | send-proxy-v2-ssl-cn |
| 10459 | The "send-proxy-v2-ssl" parameter enforces use of the PROXY protocol version |
| 10460 | 2 over any connection established to this server. The PROXY protocol informs |
| 10461 | the other end about the layer 3/4 addresses of the incoming connection, so |
| 10462 | that it can know the client's address or the public address it accessed to, |
| 10463 | whatever the upper layer protocol. In addition, the SSL information extension |
| 10464 | of the PROXY protocol, along along with the Common Name from the subject of |
| 10465 | the client certificate (if any), is added to the PROXY protocol header. This |
| 10466 | setting must not be used if the server isn't aware of this version of the |
| 10467 | protocol. See also the "send-proxy-v2" option of the "bind" keyword. |
| 10468 | |
| 10469 | Supported in default-server: No |
| 10470 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10471 | slowstart <start_time_in_ms> |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10472 | The "slowstart" parameter for a server accepts a value in milliseconds which |
| 10473 | indicates after how long a server which has just come back up will run at |
| 10474 | full speed. Just as with every other time-based parameter, it can be entered |
| 10475 | in any other explicit unit among { us, ms, s, m, h, d }. The speed grows |
| 10476 | linearly from 0 to 100% during this time. The limitation applies to two |
| 10477 | parameters : |
| 10478 | |
| 10479 | - maxconn: the number of connections accepted by the server will grow from 1 |
| 10480 | to 100% of the usual dynamic limit defined by (minconn,maxconn,fullconn). |
| 10481 | |
| 10482 | - weight: when the backend uses a dynamic weighted algorithm, the weight |
| 10483 | grows linearly from 1 to 100%. In this case, the weight is updated at every |
| 10484 | health-check. For this reason, it is important that the "inter" parameter |
| 10485 | is smaller than the "slowstart", in order to maximize the number of steps. |
| 10486 | |
| 10487 | The slowstart never applies when haproxy starts, otherwise it would cause |
| 10488 | trouble to running servers. It only applies when a server has been previously |
| 10489 | seen as failed. |
| 10490 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10491 | Supported in default-server: Yes |
| 10492 | |
Willy Tarreau | 732eac4 | 2015-07-09 11:40:25 +0200 | [diff] [blame] | 10493 | sni <expression> |
| 10494 | The "sni" parameter evaluates the sample fetch expression, converts it to a |
| 10495 | string and uses the result as the host name sent in the SNI TLS extension to |
| 10496 | the server. A typical use case is to send the SNI received from the client in |
| 10497 | a bridged HTTPS scenario, using the "ssl_fc_sni" sample fetch for the |
| 10498 | expression, though alternatives such as req.hdr(host) can also make sense. |
| 10499 | |
| 10500 | Supported in default-server: no |
| 10501 | |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 10502 | source <addr>[:<pl>[-<ph>]] [usesrc { <addr2>[:<port2>] | client | clientip } ] |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 10503 | source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | hdr_ip(<hdr>[,<occ>]) } ] |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 10504 | source <addr>[:<pl>[-<ph>]] [interface <name>] ... |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10505 | The "source" parameter sets the source address which will be used when |
| 10506 | connecting to the server. It follows the exact same parameters and principle |
| 10507 | as the backend "source" keyword, except that it only applies to the server |
| 10508 | referencing it. Please consult the "source" keyword for details. |
| 10509 | |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 10510 | Additionally, the "source" statement on a server line allows one to specify a |
| 10511 | source port range by indicating the lower and higher bounds delimited by a |
| 10512 | dash ('-'). Some operating systems might require a valid IP address when a |
| 10513 | source port range is specified. It is permitted to have the same IP/range for |
| 10514 | several servers. Doing so makes it possible to bypass the maximum of 64k |
| 10515 | total concurrent connections. The limit will then reach 64k connections per |
| 10516 | server. |
| 10517 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10518 | Supported in default-server: No |
| 10519 | |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 10520 | ssl |
Willy Tarreau | 44f6539 | 2013-06-25 07:56:20 +0200 | [diff] [blame] | 10521 | This option enables SSL ciphering on outgoing connections to the server. It |
| 10522 | is critical to verify server certificates using "verify" when using SSL to |
| 10523 | connect to servers, otherwise the communication is prone to trivial man in |
| 10524 | the-middle attacks rendering SSL useless. When this option is used, health |
| 10525 | checks are automatically sent in SSL too unless there is a "port" or an |
| 10526 | "addr" directive indicating the check should be sent to a different location. |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 10527 | See the "check-ssl" option to force SSL health checks. |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 10528 | |
| 10529 | Supported in default-server: No |
Willy Tarreau | a0ee1d0 | 2012-09-10 09:01:23 +0200 | [diff] [blame] | 10530 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10531 | track [<proxy>/]<server> |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 10532 | This option enables ability to set the current state of the server by tracking |
| 10533 | another one. It is possible to track a server which itself tracks another |
| 10534 | server, provided that at the end of the chain, a server has health checks |
| 10535 | enabled. If <proxy> is omitted the current one is used. If disable-on-404 is |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10536 | used, it has to be enabled on both proxies. |
| 10537 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10538 | Supported in default-server: No |
| 10539 | |
Emeric Brun | ef42d92 | 2012-10-11 16:11:36 +0200 | [diff] [blame] | 10540 | verify [none|required] |
| 10541 | This setting is only available when support for OpenSSL was built in. If set |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 10542 | to 'none', server certificate is not verified. In the other case, The |
| 10543 | certificate provided by the server is verified using CAs from 'ca-file' |
| 10544 | and optional CRLs from 'crl-file'. If 'ssl_server_verify' is not specified |
| 10545 | in global section, this is the default. On verify failure the handshake |
Willy Tarreau | 44f6539 | 2013-06-25 07:56:20 +0200 | [diff] [blame] | 10546 | is aborted. It is critically important to verify server certificates when |
| 10547 | using SSL to connect to servers, otherwise the communication is prone to |
| 10548 | trivial man-in-the-middle attacks rendering SSL totally useless. |
Emeric Brun | ef42d92 | 2012-10-11 16:11:36 +0200 | [diff] [blame] | 10549 | |
| 10550 | Supported in default-server: No |
| 10551 | |
Evan Broder | be55431 | 2013-06-27 00:05:25 -0700 | [diff] [blame] | 10552 | verifyhost <hostname> |
| 10553 | This setting is only available when support for OpenSSL was built in, and |
| 10554 | only takes effect if 'verify required' is also specified. When set, the |
| 10555 | hostnames in the subject and subjectAlternateNames of the certificate |
| 10556 | provided by the server are checked. If none of the hostnames in the |
| 10557 | certificate match the specified hostname, the handshake is aborted. The |
| 10558 | hostnames in the server-provided certificate may include wildcards. |
| 10559 | |
| 10560 | Supported in default-server: No |
| 10561 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10562 | weight <weight> |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10563 | The "weight" parameter is used to adjust the server's weight relative to |
| 10564 | other servers. All servers will receive a load proportional to their weight |
| 10565 | relative to the sum of all weights, so the higher the weight, the higher the |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 10566 | load. The default weight is 1, and the maximal value is 256. A value of 0 |
| 10567 | means the server will not participate in load-balancing but will still accept |
| 10568 | persistent connections. If this parameter is used to distribute the load |
| 10569 | according to server's capacity, it is recommended to start with values which |
| 10570 | can both grow and shrink, for instance between 10 and 100 to leave enough |
| 10571 | room above and below for later adjustments. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10572 | |
Krzysztof Piotr Oledzki | c53601c | 2010-01-06 10:50:42 +0100 | [diff] [blame] | 10573 | Supported in default-server: Yes |
| 10574 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10575 | |
Cyril Bonté | 46175dd | 2015-07-02 22:45:32 +0200 | [diff] [blame] | 10576 | 5.3. Server IP address resolution using DNS |
| 10577 | ------------------------------------------- |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10578 | |
Baptiste Assmann | 62b75b4 | 2015-09-09 01:11:36 +0200 | [diff] [blame] | 10579 | HAProxy allows using a host name on the server line to retrieve its IP address |
| 10580 | using name servers. By default, HAProxy resolves the name when parsing the |
| 10581 | configuration file, at startup and cache the result for the process' life. |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10582 | This is not sufficient in some cases, such as in Amazon where a server's IP |
| 10583 | can change after a reboot or an ELB Virtual IP can change based on current |
| 10584 | workload. |
| 10585 | This chapter describes how HAProxy can be configured to process server's name |
| 10586 | resolution at run time. |
| 10587 | Whether run time server name resolution has been enable or not, HAProxy will |
| 10588 | carry on doing the first resolution when parsing the configuration. |
| 10589 | |
Baptiste Assmann | 62b75b4 | 2015-09-09 01:11:36 +0200 | [diff] [blame] | 10590 | Bear in mind that DNS resolution is triggered by health checks. This makes |
| 10591 | health checks mandatory to allow DNS resolution. |
| 10592 | |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10593 | |
Cyril Bonté | 46175dd | 2015-07-02 22:45:32 +0200 | [diff] [blame] | 10594 | 5.3.1. Global overview |
| 10595 | ---------------------- |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10596 | |
| 10597 | As we've seen in introduction, name resolution in HAProxy occurs at two |
| 10598 | different steps of the process life: |
| 10599 | |
| 10600 | 1. when starting up, HAProxy parses the server line definition and matches a |
| 10601 | host name. It uses libc functions to get the host name resolved. This |
| 10602 | resolution relies on /etc/resolv.conf file. |
| 10603 | |
| 10604 | 2. at run time, when HAProxy gets prepared to run a health check on a server, |
| 10605 | it verifies if the current name resolution is still considered as valid. |
| 10606 | If not, it processes a new resolution, in parallel of the health check. |
| 10607 | |
| 10608 | A few other events can trigger a name resolution at run time: |
| 10609 | - when a server's health check ends up in a connection timeout: this may be |
| 10610 | because the server has a new IP address. So we need to trigger a name |
| 10611 | resolution to know this new IP. |
| 10612 | |
| 10613 | A few things important to notice: |
| 10614 | - all the name servers are queried in the mean time. HAProxy will process the |
| 10615 | first valid response. |
| 10616 | |
| 10617 | - a resolution is considered as invalid (NX, timeout, refused), when all the |
| 10618 | servers return an error. |
| 10619 | |
| 10620 | |
Cyril Bonté | 46175dd | 2015-07-02 22:45:32 +0200 | [diff] [blame] | 10621 | 5.3.2. The resolvers section |
| 10622 | ---------------------------- |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10623 | |
| 10624 | This section is dedicated to host information related to name resolution in |
| 10625 | HAProxy. |
| 10626 | There can be as many as resolvers section as needed. Each section can contain |
| 10627 | many name servers. |
| 10628 | |
Baptiste Assmann | 62b75b4 | 2015-09-09 01:11:36 +0200 | [diff] [blame] | 10629 | When multiple name servers are configured in a resolvers section, then HAProxy |
| 10630 | uses the first valid response. In case of invalid responses, only the last one |
| 10631 | is treated. Purpose is to give the chance to a slow server to deliver a valid |
| 10632 | answer after a fast faulty or outdated server. |
| 10633 | |
| 10634 | When each server returns a different error type, then only the last error is |
| 10635 | used by HAProxy to decide what type of behavior to apply. |
| 10636 | |
| 10637 | Two types of behavior can be applied: |
| 10638 | 1. stop DNS resolution |
| 10639 | 2. replay the DNS query with a new query type |
| 10640 | In such case, the following types are applied in this exact order: |
| 10641 | 1. ANY query type |
| 10642 | 2. query type corresponding to family pointed by resolve-prefer |
| 10643 | server's parameter |
| 10644 | 3. remaining family type |
| 10645 | |
| 10646 | HAProxy stops DNS resolution when the following errors occur: |
| 10647 | - invalid DNS response packet |
| 10648 | - wrong name in the query section of the response |
| 10649 | - NX domain |
| 10650 | - Query refused by server |
| 10651 | - CNAME not pointing to an IP address |
| 10652 | |
| 10653 | HAProxy tries a new query type when the following errors occur: |
| 10654 | - no Answer records in the response |
| 10655 | - DNS response truncated |
| 10656 | - Error in DNS response |
| 10657 | - No expected DNS records found in the response |
| 10658 | - name server timeout |
| 10659 | |
| 10660 | For example, with 2 name servers configured in a resolvers section: |
| 10661 | - first response is valid and is applied directly, second response is ignored |
| 10662 | - first response is invalid and second one is valid, then second response is |
| 10663 | applied; |
| 10664 | - first response is a NX domain and second one a truncated response, then |
| 10665 | HAProxy replays the query with a new type; |
| 10666 | - first response is truncated and second one is a NX Domain, then HAProxy |
| 10667 | stops resolution. |
| 10668 | |
| 10669 | |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10670 | resolvers <resolvers id> |
| 10671 | Creates a new name server list labelled <resolvers id> |
| 10672 | |
| 10673 | A resolvers section accept the following parameters: |
| 10674 | |
| 10675 | nameserver <id> <ip>:<port> |
| 10676 | DNS server description: |
| 10677 | <id> : label of the server, should be unique |
| 10678 | <ip> : IP address of the server |
| 10679 | <port> : port where the DNS service actually runs |
| 10680 | |
| 10681 | hold <status> <period> |
| 10682 | Defines <period> during which the last name resolution should be kept based |
| 10683 | on last resolution <status> |
| 10684 | <status> : last name resolution status. Only "valid" is accepted for now. |
| 10685 | <period> : interval between two successive name resolution when the last |
| 10686 | answer was in <status>. It follows the HAProxy time format. |
| 10687 | <period> is in milliseconds by default. |
| 10688 | |
| 10689 | Default value is 10s for "valid". |
| 10690 | |
| 10691 | Note: since the name resolution is triggered by the health checks, a new |
| 10692 | resolution is triggered after <period> modulo the <inter> parameter of |
| 10693 | the healch check. |
| 10694 | |
| 10695 | resolve_retries <nb> |
| 10696 | Defines the number <nb> of queries to send to resolve a server name before |
| 10697 | giving up. |
| 10698 | Default value: 3 |
| 10699 | |
Baptiste Assmann | 62b75b4 | 2015-09-09 01:11:36 +0200 | [diff] [blame] | 10700 | A retry occurs on name server timeout or when the full sequence of DNS query |
| 10701 | type failover is over and we need to start up from the default ANY query |
| 10702 | type. |
| 10703 | |
Baptiste Assmann | 1fa6666 | 2015-04-14 00:28:47 +0200 | [diff] [blame] | 10704 | timeout <event> <time> |
| 10705 | Defines timeouts related to name resolution |
| 10706 | <event> : the event on which the <time> timeout period applies to. |
| 10707 | events available are: |
| 10708 | - retry: time between two DNS queries, when no response have |
| 10709 | been received. |
| 10710 | Default value: 1s |
| 10711 | <time> : time related to the event. It follows the HAProxy time format. |
| 10712 | <time> is expressed in milliseconds. |
| 10713 | |
| 10714 | Example of a resolvers section (with default values): |
| 10715 | |
| 10716 | resolvers mydns |
| 10717 | nameserver dns1 10.0.0.1:53 |
| 10718 | nameserver dns2 10.0.0.2:53 |
| 10719 | resolve_retries 3 |
| 10720 | timeout retry 1s |
| 10721 | hold valid 10s |
| 10722 | |
| 10723 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10724 | 6. HTTP header manipulation |
| 10725 | --------------------------- |
| 10726 | |
| 10727 | In HTTP mode, it is possible to rewrite, add or delete some of the request and |
| 10728 | response headers based on regular expressions. It is also possible to block a |
| 10729 | request or a response if a particular header matches a regular expression, |
| 10730 | which is enough to stop most elementary protocol attacks, and to protect |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 10731 | against information leak from the internal network. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10732 | |
Willy Tarreau | 70dffda | 2014-01-30 03:07:23 +0100 | [diff] [blame] | 10733 | If HAProxy encounters an "Informational Response" (status code 1xx), it is able |
| 10734 | to process all rsp* rules which can allow, deny, rewrite or delete a header, |
| 10735 | but it will refuse to add a header to any such messages as this is not |
| 10736 | HTTP-compliant. The reason for still processing headers in such responses is to |
| 10737 | stop and/or fix any possible information leak which may happen, for instance |
| 10738 | because another downstream equipment would unconditionally add a header, or if |
| 10739 | a server name appears there. When such messages are seen, normal processing |
| 10740 | still occurs on the next non-informational messages. |
Willy Tarreau | 816b979 | 2009-09-15 21:25:21 +0200 | [diff] [blame] | 10741 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10742 | This section covers common usage of the following keywords, described in detail |
| 10743 | in section 4.2 : |
| 10744 | |
| 10745 | - reqadd <string> |
| 10746 | - reqallow <search> |
| 10747 | - reqiallow <search> |
| 10748 | - reqdel <search> |
| 10749 | - reqidel <search> |
| 10750 | - reqdeny <search> |
| 10751 | - reqideny <search> |
| 10752 | - reqpass <search> |
| 10753 | - reqipass <search> |
| 10754 | - reqrep <search> <replace> |
| 10755 | - reqirep <search> <replace> |
| 10756 | - reqtarpit <search> |
| 10757 | - reqitarpit <search> |
| 10758 | - rspadd <string> |
| 10759 | - rspdel <search> |
| 10760 | - rspidel <search> |
| 10761 | - rspdeny <search> |
| 10762 | - rspideny <search> |
| 10763 | - rsprep <search> <replace> |
| 10764 | - rspirep <search> <replace> |
| 10765 | |
| 10766 | With all these keywords, the same conventions are used. The <search> parameter |
| 10767 | is a POSIX extended regular expression (regex) which supports grouping through |
| 10768 | parenthesis (without the backslash). Spaces and other delimiters must be |
| 10769 | prefixed with a backslash ('\') to avoid confusion with a field delimiter. |
| 10770 | Other characters may be prefixed with a backslash to change their meaning : |
| 10771 | |
| 10772 | \t for a tab |
| 10773 | \r for a carriage return (CR) |
| 10774 | \n for a new line (LF) |
| 10775 | \ to mark a space and differentiate it from a delimiter |
| 10776 | \# to mark a sharp and differentiate it from a comment |
| 10777 | \\ to use a backslash in a regex |
| 10778 | \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy) |
| 10779 | \xXX to write the ASCII hex code XX as in the C language |
| 10780 | |
| 10781 | The <replace> parameter contains the string to be used to replace the largest |
| 10782 | portion of text matching the regex. It can make use of the special characters |
| 10783 | above, and can reference a substring which is delimited by parenthesis in the |
| 10784 | regex, by writing a backslash ('\') immediately followed by one digit from 0 to |
| 10785 | 9 indicating the group position (0 designating the entire line). This practice |
| 10786 | is very common to users of the "sed" program. |
| 10787 | |
| 10788 | The <string> parameter represents the string which will systematically be added |
| 10789 | after the last header line. It can also use special character sequences above. |
| 10790 | |
| 10791 | Notes related to these keywords : |
| 10792 | --------------------------------- |
| 10793 | - these keywords are not always convenient to allow/deny based on header |
| 10794 | contents. It is strongly recommended to use ACLs with the "block" keyword |
| 10795 | instead, resulting in far more flexible and manageable rules. |
| 10796 | |
| 10797 | - lines are always considered as a whole. It is not possible to reference |
| 10798 | a header name only or a value only. This is important because of the way |
| 10799 | headers are written (notably the number of spaces after the colon). |
| 10800 | |
| 10801 | - the first line is always considered as a header, which makes it possible to |
| 10802 | rewrite or filter HTTP requests URIs or response codes, but in turn makes |
| 10803 | it harder to distinguish between headers and request line. The regex prefix |
| 10804 | ^[^\ \t]*[\ \t] matches any HTTP method followed by a space, and the prefix |
| 10805 | ^[^ \t:]*: matches any header name followed by a colon. |
| 10806 | |
| 10807 | - for performances reasons, the number of characters added to a request or to |
| 10808 | a response is limited at build time to values between 1 and 4 kB. This |
| 10809 | should normally be far more than enough for most usages. If it is too short |
| 10810 | on occasional usages, it is possible to gain some space by removing some |
| 10811 | useless headers before adding new ones. |
| 10812 | |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 10813 | - keywords beginning with "reqi" and "rspi" are the same as their counterpart |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10814 | without the 'i' letter except that they ignore case when matching patterns. |
| 10815 | |
| 10816 | - when a request passes through a frontend then a backend, all req* rules |
| 10817 | from the frontend will be evaluated, then all req* rules from the backend |
| 10818 | will be evaluated. The reverse path is applied to responses. |
| 10819 | |
| 10820 | - req* statements are applied after "block" statements, so that "block" is |
| 10821 | always the first one, but before "use_backend" in order to permit rewriting |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 10822 | before switching. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10823 | |
| 10824 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10825 | 7. Using ACLs and fetching samples |
| 10826 | ---------------------------------- |
| 10827 | |
| 10828 | Haproxy is capable of extracting data from request or response streams, from |
| 10829 | client or server information, from tables, environmental information etc... |
| 10830 | The action of extracting such data is called fetching a sample. Once retrieved, |
| 10831 | these samples may be used for various purposes such as a key to a stick-table, |
| 10832 | but most common usages consist in matching them against predefined constant |
| 10833 | data called patterns. |
| 10834 | |
| 10835 | |
| 10836 | 7.1. ACL basics |
| 10837 | --------------- |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10838 | |
| 10839 | The use of Access Control Lists (ACL) provides a flexible solution to perform |
| 10840 | content switching and generally to take decisions based on content extracted |
| 10841 | from the request, the response or any environmental status. The principle is |
| 10842 | simple : |
| 10843 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10844 | - extract a data sample from a stream, table or the environment |
Willy Tarreau | e6b11e4 | 2013-11-26 19:02:32 +0100 | [diff] [blame] | 10845 | - optionally apply some format conversion to the extracted sample |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10846 | - apply one or multiple pattern matching methods on this sample |
| 10847 | - perform actions only when a pattern matches the sample |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10848 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10849 | The actions generally consist in blocking a request, selecting a backend, or |
| 10850 | adding a header. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10851 | |
| 10852 | In order to define a test, the "acl" keyword is used. The syntax is : |
| 10853 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10854 | acl <aclname> <criterion> [flags] [operator] [<value>] ... |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10855 | |
| 10856 | This creates a new ACL <aclname> or completes an existing one with new tests. |
| 10857 | Those tests apply to the portion of request/response specified in <criterion> |
| 10858 | and may be adjusted with optional flags [flags]. Some criteria also support |
Willy Tarreau | e6b11e4 | 2013-11-26 19:02:32 +0100 | [diff] [blame] | 10859 | an operator which may be specified before the set of values. Optionally some |
| 10860 | conversion operators may be applied to the sample, and they will be specified |
| 10861 | as a comma-delimited list of keywords just after the first keyword. The values |
| 10862 | are of the type supported by the criterion, and are separated by spaces. |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10863 | |
| 10864 | ACL names must be formed from upper and lower case letters, digits, '-' (dash), |
| 10865 | '_' (underscore) , '.' (dot) and ':' (colon). ACL names are case-sensitive, |
| 10866 | which means that "my_acl" and "My_Acl" are two different ACLs. |
| 10867 | |
| 10868 | There is no enforced limit to the number of ACLs. The unused ones do not affect |
| 10869 | performance, they just consume a small amount of memory. |
| 10870 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10871 | The criterion generally is the name of a sample fetch method, or one of its ACL |
| 10872 | specific declinations. The default test method is implied by the output type of |
| 10873 | this sample fetch method. The ACL declinations can describe alternate matching |
Willy Tarreau | e6b11e4 | 2013-11-26 19:02:32 +0100 | [diff] [blame] | 10874 | methods of a same sample fetch method. The sample fetch methods are the only |
| 10875 | ones supporting a conversion. |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10876 | |
| 10877 | Sample fetch methods return data which can be of the following types : |
| 10878 | - boolean |
| 10879 | - integer (signed or unsigned) |
| 10880 | - IPv4 or IPv6 address |
| 10881 | - string |
| 10882 | - data block |
| 10883 | |
Willy Tarreau | e6b11e4 | 2013-11-26 19:02:32 +0100 | [diff] [blame] | 10884 | Converters transform any of these data into any of these. For example, some |
| 10885 | converters might convert a string to a lower-case string while other ones |
| 10886 | would turn a string to an IPv4 address, or apply a netmask to an IP address. |
| 10887 | The resulting sample is of the type of the last converter applied to the list, |
| 10888 | which defaults to the type of the sample fetch method. |
| 10889 | |
Thierry FOURNIER | 2a06e39 | 2014-05-11 15:49:55 +0200 | [diff] [blame] | 10890 | Each sample or converter returns data of a specific type, specified with its |
| 10891 | keyword in this documentation. When an ACL is declared using a standard sample |
| 10892 | fetch method, certain types automatically involved a default matching method |
| 10893 | which are summarized in the table below : |
| 10894 | |
| 10895 | +---------------------+-----------------+ |
| 10896 | | Sample or converter | Default | |
| 10897 | | output type | matching method | |
| 10898 | +---------------------+-----------------+ |
| 10899 | | boolean | bool | |
| 10900 | +---------------------+-----------------+ |
| 10901 | | integer | int | |
| 10902 | +---------------------+-----------------+ |
| 10903 | | ip | ip | |
| 10904 | +---------------------+-----------------+ |
| 10905 | | string | str | |
| 10906 | +---------------------+-----------------+ |
| 10907 | | binary | none, use "-m" | |
| 10908 | +---------------------+-----------------+ |
| 10909 | |
| 10910 | Note that in order to match a binary samples, it is mandatory to specify a |
| 10911 | matching method, see below. |
| 10912 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10913 | The ACL engine can match these types against patterns of the following types : |
| 10914 | - boolean |
| 10915 | - integer or integer range |
| 10916 | - IP address / network |
| 10917 | - string (exact, substring, suffix, prefix, subdir, domain) |
| 10918 | - regular expression |
| 10919 | - hex block |
| 10920 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 10921 | The following ACL flags are currently supported : |
| 10922 | |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 10923 | -i : ignore case during matching of all subsequent patterns. |
| 10924 | -f : load patterns from a file. |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10925 | -m : use a specific pattern matching method |
Thierry FOURNIER | b7729c9 | 2014-02-11 16:24:41 +0100 | [diff] [blame] | 10926 | -n : forbid the DNS resolutions |
Thierry FOURNIER | 9860c41 | 2014-01-29 14:23:29 +0100 | [diff] [blame] | 10927 | -M : load the file pointed by -f like a map file. |
Thierry FOURNIER | 3534d88 | 2014-01-20 17:01:44 +0100 | [diff] [blame] | 10928 | -u : force the unique id of the ACL |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 10929 | -- : force end of flags. Useful when a string looks like one of the flags. |
| 10930 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10931 | The "-f" flag is followed by the name of a file from which all lines will be |
| 10932 | read as individual values. It is even possible to pass multiple "-f" arguments |
| 10933 | if the patterns are to be loaded from multiple files. Empty lines as well as |
| 10934 | lines beginning with a sharp ('#') will be ignored. All leading spaces and tabs |
| 10935 | will be stripped. If it is absolutely necessary to insert a valid pattern |
| 10936 | beginning with a sharp, just prefix it with a space so that it is not taken for |
| 10937 | a comment. Depending on the data type and match method, haproxy may load the |
| 10938 | lines into a binary tree, allowing very fast lookups. This is true for IPv4 and |
| 10939 | exact string matching. In this case, duplicates will automatically be removed. |
| 10940 | |
Thierry FOURNIER | 9860c41 | 2014-01-29 14:23:29 +0100 | [diff] [blame] | 10941 | The "-M" flag allows an ACL to use a map file. If this flag is set, the file is |
| 10942 | parsed as two column file. The first column contains the patterns used by the |
| 10943 | ACL, and the second column contain the samples. The sample can be used later by |
| 10944 | a map. This can be useful in some rare cases where an ACL would just be used to |
| 10945 | check for the existence of a pattern in a map before a mapping is applied. |
| 10946 | |
Thierry FOURNIER | 3534d88 | 2014-01-20 17:01:44 +0100 | [diff] [blame] | 10947 | The "-u" flag forces the unique id of the ACL. This unique id is used with the |
| 10948 | socket interface to identify ACL and dynamically change its values. Note that a |
| 10949 | file is always identified by its name even if an id is set. |
| 10950 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10951 | Also, note that the "-i" flag applies to subsequent entries and not to entries |
| 10952 | loaded from files preceding it. For instance : |
| 10953 | |
| 10954 | acl valid-ua hdr(user-agent) -f exact-ua.lst -i -f generic-ua.lst test |
| 10955 | |
| 10956 | In this example, each line of "exact-ua.lst" will be exactly matched against |
| 10957 | the "user-agent" header of the request. Then each line of "generic-ua" will be |
| 10958 | case-insensitively matched. Then the word "test" will be insensitively matched |
| 10959 | as well. |
| 10960 | |
| 10961 | The "-m" flag is used to select a specific pattern matching method on the input |
| 10962 | sample. All ACL-specific criteria imply a pattern matching method and generally |
| 10963 | do not need this flag. However, this flag is useful with generic sample fetch |
| 10964 | methods to describe how they're going to be matched against the patterns. This |
| 10965 | is required for sample fetches which return data type for which there is no |
| 10966 | obvious matching method (eg: string or binary). When "-m" is specified and |
| 10967 | followed by a pattern matching method name, this method is used instead of the |
| 10968 | default one for the criterion. This makes it possible to match contents in ways |
| 10969 | that were not initially planned, or with sample fetch methods which return a |
| 10970 | string. The matching method also affects the way the patterns are parsed. |
| 10971 | |
Thierry FOURNIER | b7729c9 | 2014-02-11 16:24:41 +0100 | [diff] [blame] | 10972 | The "-n" flag forbids the dns resolutions. It is used with the load of ip files. |
| 10973 | By default, if the parser cannot parse ip address it considers that the parsed |
| 10974 | string is maybe a domain name and try dns resolution. The flag "-n" disable this |
| 10975 | resolution. It is useful for detecting malformed ip lists. Note that if the DNS |
| 10976 | server is not reachable, the haproxy configuration parsing may last many minutes |
| 10977 | waiting fir the timeout. During this time no error messages are displayed. The |
| 10978 | flag "-n" disable this behavior. Note also that during the runtime, this |
| 10979 | function is disabled for the dynamic acl modifications. |
| 10980 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10981 | There are some restrictions however. Not all methods can be used with all |
| 10982 | sample fetch methods. Also, if "-m" is used in conjunction with "-f", it must |
| 10983 | be placed first. The pattern matching method must be one of the following : |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 10984 | |
| 10985 | - "found" : only check if the requested sample could be found in the stream, |
| 10986 | but do not compare it against any pattern. It is recommended not |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10987 | to pass any pattern to avoid confusion. This matching method is |
| 10988 | particularly useful to detect presence of certain contents such |
| 10989 | as headers, cookies, etc... even if they are empty and without |
| 10990 | comparing them to anything nor counting them. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 10991 | |
| 10992 | - "bool" : check the value as a boolean. It can only be applied to fetches |
| 10993 | which return a boolean or integer value, and takes no pattern. |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10994 | Value zero or false does not match, all other values do match. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 10995 | |
| 10996 | - "int" : match the value as an integer. It can be used with integer and |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 10997 | boolean samples. Boolean false is integer 0, true is integer 1. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 10998 | |
| 10999 | - "ip" : match the value as an IPv4 or IPv6 address. It is compatible |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11000 | with IP address samples only, so it is implied and never needed. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 11001 | |
| 11002 | - "bin" : match the contents against an hexadecimal string representing a |
| 11003 | binary sequence. This may be used with binary or string samples. |
| 11004 | |
| 11005 | - "len" : match the sample's length as an integer. This may be used with |
| 11006 | binary or string samples. |
| 11007 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11008 | - "str" : exact match : match the contents against a string. This may be |
| 11009 | used with binary or string samples. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 11010 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11011 | - "sub" : substring match : check that the contents contain at least one of |
| 11012 | the provided string patterns. This may be used with binary or |
| 11013 | string samples. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 11014 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11015 | - "reg" : regex match : match the contents against a list of regular |
| 11016 | expressions. This may be used with binary or string samples. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 11017 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11018 | - "beg" : prefix match : check that the contents begin like the provided |
| 11019 | string patterns. This may be used with binary or string samples. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 11020 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11021 | - "end" : suffix match : check that the contents end like the provided |
| 11022 | string patterns. This may be used with binary or string samples. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 11023 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11024 | - "dir" : subdir match : check that a slash-delimited portion of the |
| 11025 | contents exactly matches one of the provided string patterns. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 11026 | This may be used with binary or string samples. |
| 11027 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11028 | - "dom" : domain match : check that a dot-delimited portion of the contents |
| 11029 | exactly match one of the provided string patterns. This may be |
| 11030 | used with binary or string samples. |
Willy Tarreau | 5adeda1 | 2013-03-31 22:13:34 +0200 | [diff] [blame] | 11031 | |
| 11032 | For example, to quickly detect the presence of cookie "JSESSIONID" in an HTTP |
| 11033 | request, it is possible to do : |
| 11034 | |
| 11035 | acl jsess_present cook(JSESSIONID) -m found |
| 11036 | |
| 11037 | In order to apply a regular expression on the 500 first bytes of data in the |
| 11038 | buffer, one would use the following acl : |
| 11039 | |
| 11040 | acl script_tag payload(0,500) -m reg -i <script> |
| 11041 | |
Willy Tarreau | e6b11e4 | 2013-11-26 19:02:32 +0100 | [diff] [blame] | 11042 | On systems where the regex library is much slower when using "-i", it is |
| 11043 | possible to convert the sample to lowercase before matching, like this : |
| 11044 | |
| 11045 | acl script_tag payload(0,500),lower -m reg <script> |
| 11046 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11047 | All ACL-specific criteria imply a default matching method. Most often, these |
| 11048 | criteria are composed by concatenating the name of the original sample fetch |
| 11049 | method and the matching method. For example, "hdr_beg" applies the "beg" match |
| 11050 | to samples retrieved using the "hdr" fetch method. Since all ACL-specific |
| 11051 | criteria rely on a sample fetch method, it is always possible instead to use |
| 11052 | the original sample fetch method and the explicit matching method using "-m". |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 11053 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11054 | If an alternate match is specified using "-m" on an ACL-specific criterion, |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 11055 | the matching method is simply applied to the underlying sample fetch method. |
| 11056 | For example, all ACLs below are exact equivalent : |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 11057 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11058 | acl short_form hdr_beg(host) www. |
| 11059 | acl alternate1 hdr_beg(host) -m beg www. |
| 11060 | acl alternate2 hdr_dom(host) -m beg www. |
| 11061 | acl alternate3 hdr(host) -m beg www. |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 11062 | |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 11063 | |
Thierry FOURNIER | 2a06e39 | 2014-05-11 15:49:55 +0200 | [diff] [blame] | 11064 | The table below summarizes the compatibility matrix between sample or converter |
| 11065 | types and the pattern types to fetch against. It indicates for each compatible |
| 11066 | combination the name of the matching method to be used, surrounded with angle |
| 11067 | brackets ">" and "<" when the method is the default one and will work by |
| 11068 | default without "-m". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 11069 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11070 | +-------------------------------------------------+ |
| 11071 | | Input sample type | |
| 11072 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | 2a06e39 | 2014-05-11 15:49:55 +0200 | [diff] [blame] | 11073 | | pattern type | boolean | integer | ip | string | binary | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11074 | +----------------------+---------+---------+---------+---------+---------+ |
| 11075 | | none (presence only) | found | found | found | found | found | |
| 11076 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | 2a06e39 | 2014-05-11 15:49:55 +0200 | [diff] [blame] | 11077 | | none (boolean value) |> bool <| bool | | bool | | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11078 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | 2a06e39 | 2014-05-11 15:49:55 +0200 | [diff] [blame] | 11079 | | integer (value) | int |> int <| int | int | | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11080 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | e3ded59 | 2013-12-06 15:36:54 +0100 | [diff] [blame] | 11081 | | integer (length) | len | len | len | len | len | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11082 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | 2a06e39 | 2014-05-11 15:49:55 +0200 | [diff] [blame] | 11083 | | IP address | | |> ip <| ip | ip | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11084 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | 2a06e39 | 2014-05-11 15:49:55 +0200 | [diff] [blame] | 11085 | | exact string | str | str | str |> str <| str | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11086 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | e3ded59 | 2013-12-06 15:36:54 +0100 | [diff] [blame] | 11087 | | prefix | beg | beg | beg | beg | beg | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11088 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | e3ded59 | 2013-12-06 15:36:54 +0100 | [diff] [blame] | 11089 | | suffix | end | end | end | end | end | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11090 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | e3ded59 | 2013-12-06 15:36:54 +0100 | [diff] [blame] | 11091 | | substring | sub | sub | sub | sub | sub | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11092 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | e3ded59 | 2013-12-06 15:36:54 +0100 | [diff] [blame] | 11093 | | subdir | dir | dir | dir | dir | dir | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11094 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | e3ded59 | 2013-12-06 15:36:54 +0100 | [diff] [blame] | 11095 | | domain | dom | dom | dom | dom | dom | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11096 | +----------------------+---------+---------+---------+---------+---------+ |
Thierry FOURNIER | e3ded59 | 2013-12-06 15:36:54 +0100 | [diff] [blame] | 11097 | | regex | reg | reg | reg | reg | reg | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11098 | +----------------------+---------+---------+---------+---------+---------+ |
| 11099 | | hex block | | | | bin | bin | |
| 11100 | +----------------------+---------+---------+---------+---------+---------+ |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11101 | |
| 11102 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11103 | 7.1.1. Matching booleans |
| 11104 | ------------------------ |
| 11105 | |
| 11106 | In order to match a boolean, no value is needed and all values are ignored. |
| 11107 | Boolean matching is used by default for all fetch methods of type "boolean". |
| 11108 | When boolean matching is used, the fetched value is returned as-is, which means |
| 11109 | that a boolean "true" will always match and a boolean "false" will never match. |
| 11110 | |
| 11111 | Boolean matching may also be enforced using "-m bool" on fetch methods which |
| 11112 | return an integer value. Then, integer value 0 is converted to the boolean |
| 11113 | "false" and all other values are converted to "true". |
| 11114 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11115 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11116 | 7.1.2. Matching integers |
| 11117 | ------------------------ |
| 11118 | |
| 11119 | Integer matching applies by default to integer fetch methods. It can also be |
| 11120 | enforced on boolean fetches using "-m int". In this case, "false" is converted |
| 11121 | to the integer 0, and "true" is converted to the integer 1. |
| 11122 | |
| 11123 | Integer matching also supports integer ranges and operators. Note that integer |
| 11124 | matching only applies to positive values. A range is a value expressed with a |
| 11125 | lower and an upper bound separated with a colon, both of which may be omitted. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11126 | |
| 11127 | For instance, "1024:65535" is a valid range to represent a range of |
| 11128 | unprivileged ports, and "1024:" would also work. "0:1023" is a valid |
| 11129 | representation of privileged ports, and ":1023" would also work. |
| 11130 | |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 11131 | As a special case, some ACL functions support decimal numbers which are in fact |
| 11132 | two integers separated by a dot. This is used with some version checks for |
| 11133 | instance. All integer properties apply to those decimal numbers, including |
| 11134 | ranges and operators. |
| 11135 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11136 | For an easier usage, comparison operators are also supported. Note that using |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 11137 | operators with ranges does not make much sense and is strongly discouraged. |
| 11138 | Similarly, it does not make much sense to perform order comparisons with a set |
| 11139 | of values. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11140 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 11141 | Available operators for integer matching are : |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11142 | |
| 11143 | eq : true if the tested value equals at least one value |
| 11144 | ge : true if the tested value is greater than or equal to at least one value |
| 11145 | gt : true if the tested value is greater than at least one value |
| 11146 | le : true if the tested value is less than or equal to at least one value |
| 11147 | lt : true if the tested value is less than at least one value |
| 11148 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 11149 | For instance, the following ACL matches any negative Content-Length header : |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11150 | |
| 11151 | acl negative-length hdr_val(content-length) lt 0 |
| 11152 | |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 11153 | This one matches SSL versions between 3.0 and 3.1 (inclusive) : |
| 11154 | |
| 11155 | acl sslv3 req_ssl_ver 3:3.1 |
| 11156 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11157 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11158 | 7.1.3. Matching strings |
| 11159 | ----------------------- |
| 11160 | |
| 11161 | String matching applies to string or binary fetch methods, and exists in 6 |
| 11162 | different forms : |
| 11163 | |
| 11164 | - exact match (-m str) : the extracted string must exactly match the |
| 11165 | patterns ; |
| 11166 | |
| 11167 | - substring match (-m sub) : the patterns are looked up inside the |
| 11168 | extracted string, and the ACL matches if any of them is found inside ; |
| 11169 | |
| 11170 | - prefix match (-m beg) : the patterns are compared with the beginning of |
| 11171 | the extracted string, and the ACL matches if any of them matches. |
| 11172 | |
| 11173 | - suffix match (-m end) : the patterns are compared with the end of the |
| 11174 | extracted string, and the ACL matches if any of them matches. |
| 11175 | |
| 11176 | - subdir match (-m sub) : the patterns are looked up inside the extracted |
| 11177 | string, delimited with slashes ("/"), and the ACL matches if any of them |
| 11178 | matches. |
| 11179 | |
| 11180 | - domain match (-m dom) : the patterns are looked up inside the extracted |
| 11181 | string, delimited with dots ("."), and the ACL matches if any of them |
| 11182 | matches. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11183 | |
| 11184 | String matching applies to verbatim strings as they are passed, with the |
| 11185 | exception of the backslash ("\") which makes it possible to escape some |
| 11186 | characters such as the space. If the "-i" flag is passed before the first |
| 11187 | string, then the matching will be performed ignoring the case. In order |
| 11188 | 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] | 11189 | before the first string. Same applies of course to match the string "--". |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11190 | |
| 11191 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11192 | 7.1.4. Matching regular expressions (regexes) |
| 11193 | --------------------------------------------- |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11194 | |
| 11195 | Just like with string matching, regex matching applies to verbatim strings as |
| 11196 | they are passed, with the exception of the backslash ("\") which makes it |
| 11197 | possible to escape some characters such as the space. If the "-i" flag is |
| 11198 | passed before the first regex, then the matching will be performed ignoring |
| 11199 | 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] | 11200 | the "--" flag before the first string. Same principle applies of course to |
| 11201 | match the string "--". |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11202 | |
| 11203 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11204 | 7.1.5. Matching arbitrary data blocks |
| 11205 | ------------------------------------- |
| 11206 | |
| 11207 | It is possible to match some extracted samples against a binary block which may |
| 11208 | not safely be represented as a string. For this, the patterns must be passed as |
| 11209 | a series of hexadecimal digits in an even number, when the match method is set |
| 11210 | to binary. Each sequence of two digits will represent a byte. The hexadecimal |
| 11211 | digits may be used upper or lower case. |
| 11212 | |
| 11213 | Example : |
| 11214 | # match "Hello\n" in the input stream (\x48 \x65 \x6c \x6c \x6f \x0a) |
| 11215 | acl hello payload(0,6) -m bin 48656c6c6f0a |
| 11216 | |
| 11217 | |
| 11218 | 7.1.6. Matching IPv4 and IPv6 addresses |
| 11219 | --------------------------------------- |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11220 | |
| 11221 | IPv4 addresses values can be specified either as plain addresses or with a |
| 11222 | netmask appended, in which case the IPv4 address matches whenever it is |
| 11223 | within the network. Plain addresses may also be replaced with a resolvable |
Willy Tarreau | d2a4aa2 | 2008-01-31 15:28:22 +0100 | [diff] [blame] | 11224 | host name, but this practice is generally discouraged as it makes it more |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 11225 | difficult to read and debug configurations. If hostnames are used, you should |
| 11226 | at least ensure that they are present in /etc/hosts so that the configuration |
| 11227 | does not depend on any random DNS match at the moment the configuration is |
| 11228 | parsed. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11229 | |
Willy Tarreau | ceb4ac9 | 2012-04-28 00:41:46 +0200 | [diff] [blame] | 11230 | IPv6 may be entered in their usual form, with or without a netmask appended. |
| 11231 | Only bit counts are accepted for IPv6 netmasks. In order to avoid any risk of |
| 11232 | trouble with randomly resolved IP addresses, host names are never allowed in |
| 11233 | IPv6 patterns. |
| 11234 | |
| 11235 | HAProxy is also able to match IPv4 addresses with IPv6 addresses in the |
| 11236 | following situations : |
| 11237 | - tested address is IPv4, pattern address is IPv4, the match applies |
| 11238 | in IPv4 using the supplied mask if any. |
| 11239 | - tested address is IPv6, pattern address is IPv6, the match applies |
| 11240 | in IPv6 using the supplied mask if any. |
| 11241 | - tested address is IPv6, pattern address is IPv4, the match applies in IPv4 |
| 11242 | using the pattern's mask if the IPv6 address matches with 2002:IPV4::, |
| 11243 | ::IPV4 or ::ffff:IPV4, otherwise it fails. |
| 11244 | - tested address is IPv4, pattern address is IPv6, the IPv4 address is first |
| 11245 | converted to IPv6 by prefixing ::ffff: in front of it, then the match is |
| 11246 | applied in IPv6 using the supplied IPv6 mask. |
| 11247 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11248 | |
| 11249 | 7.2. Using ACLs to form conditions |
| 11250 | ---------------------------------- |
| 11251 | |
| 11252 | Some actions are only performed upon a valid condition. A condition is a |
| 11253 | combination of ACLs with operators. 3 operators are supported : |
| 11254 | |
| 11255 | - AND (implicit) |
| 11256 | - OR (explicit with the "or" keyword or the "||" operator) |
| 11257 | - Negation with the exclamation mark ("!") |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11258 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11259 | A condition is formed as a disjunctive form: |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 11260 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11261 | [!]acl1 [!]acl2 ... [!]acln { or [!]acl1 [!]acl2 ... [!]acln } ... |
Willy Tarreau | bef91e7 | 2013-03-31 23:14:46 +0200 | [diff] [blame] | 11262 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11263 | Such conditions are generally used after an "if" or "unless" statement, |
| 11264 | indicating when the condition will trigger the action. |
Willy Tarreau | bef91e7 | 2013-03-31 23:14:46 +0200 | [diff] [blame] | 11265 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11266 | For instance, to block HTTP requests to the "*" URL with methods other than |
| 11267 | "OPTIONS", as well as POST requests without content-length, and GET or HEAD |
| 11268 | requests with a content-length greater than 0, and finally every request which |
| 11269 | is not either GET/HEAD/POST/OPTIONS ! |
| 11270 | |
| 11271 | acl missing_cl hdr_cnt(Content-length) eq 0 |
| 11272 | block if HTTP_URL_STAR !METH_OPTIONS || METH_POST missing_cl |
| 11273 | block if METH_GET HTTP_CONTENT |
| 11274 | block unless METH_GET or METH_POST or METH_OPTIONS |
| 11275 | |
| 11276 | To select a different backend for requests to static contents on the "www" site |
| 11277 | and to every request on the "img", "video", "download" and "ftp" hosts : |
| 11278 | |
| 11279 | acl url_static path_beg /static /images /img /css |
| 11280 | acl url_static path_end .gif .png .jpg .css .js |
| 11281 | acl host_www hdr_beg(host) -i www |
| 11282 | acl host_static hdr_beg(host) -i img. video. download. ftp. |
| 11283 | |
| 11284 | # now use backend "static" for all static-only hosts, and for static urls |
| 11285 | # of host "www". Use backend "www" for the rest. |
| 11286 | use_backend static if host_static or host_www url_static |
| 11287 | use_backend www if host_www |
| 11288 | |
| 11289 | It is also possible to form rules using "anonymous ACLs". Those are unnamed ACL |
| 11290 | expressions that are built on the fly without needing to be declared. They must |
| 11291 | be enclosed between braces, with a space before and after each brace (because |
| 11292 | the braces must be seen as independent words). Example : |
| 11293 | |
| 11294 | The following rule : |
| 11295 | |
| 11296 | acl missing_cl hdr_cnt(Content-length) eq 0 |
| 11297 | block if METH_POST missing_cl |
| 11298 | |
| 11299 | Can also be written that way : |
| 11300 | |
| 11301 | block if METH_POST { hdr_cnt(Content-length) eq 0 } |
| 11302 | |
| 11303 | It is generally not recommended to use this construct because it's a lot easier |
| 11304 | to leave errors in the configuration when written that way. However, for very |
| 11305 | simple rules matching only one source IP address for instance, it can make more |
| 11306 | sense to use them than to declare ACLs with random names. Another example of |
| 11307 | good use is the following : |
| 11308 | |
| 11309 | With named ACLs : |
| 11310 | |
| 11311 | acl site_dead nbsrv(dynamic) lt 2 |
| 11312 | acl site_dead nbsrv(static) lt 2 |
| 11313 | monitor fail if site_dead |
| 11314 | |
| 11315 | With anonymous ACLs : |
| 11316 | |
| 11317 | monitor fail if { nbsrv(dynamic) lt 2 } || { nbsrv(static) lt 2 } |
| 11318 | |
| 11319 | See section 4.2 for detailed help on the "block" and "use_backend" keywords. |
| 11320 | |
| 11321 | |
| 11322 | 7.3. Fetching samples |
| 11323 | --------------------- |
| 11324 | |
| 11325 | Historically, sample fetch methods were only used to retrieve data to match |
| 11326 | against patterns using ACLs. With the arrival of stick-tables, a new class of |
| 11327 | sample fetch methods was created, most often sharing the same syntax as their |
| 11328 | ACL counterpart. These sample fetch methods are also known as "fetches". As |
| 11329 | of now, ACLs and fetches have converged. All ACL fetch methods have been made |
| 11330 | available as fetch methods, and ACLs may use any sample fetch method as well. |
| 11331 | |
| 11332 | This section details all available sample fetch methods and their output type. |
| 11333 | Some sample fetch methods have deprecated aliases that are used to maintain |
| 11334 | compatibility with existing configurations. They are then explicitly marked as |
| 11335 | deprecated and should not be used in new setups. |
| 11336 | |
| 11337 | The ACL derivatives are also indicated when available, with their respective |
| 11338 | matching methods. These ones all have a well defined default pattern matching |
| 11339 | method, so it is never necessary (though allowed) to pass the "-m" option to |
| 11340 | indicate how the sample will be matched using ACLs. |
| 11341 | |
| 11342 | As indicated in the sample type versus matching compatibility matrix above, |
| 11343 | when using a generic sample fetch method in an ACL, the "-m" option is |
| 11344 | mandatory unless the sample type is one of boolean, integer, IPv4 or IPv6. When |
| 11345 | the same keyword exists as an ACL keyword and as a standard fetch method, the |
| 11346 | ACL engine will automatically pick the ACL-only one by default. |
| 11347 | |
| 11348 | Some of these keywords support one or multiple mandatory arguments, and one or |
| 11349 | multiple optional arguments. These arguments are strongly typed and are checked |
| 11350 | when the configuration is parsed so that there is no risk of running with an |
| 11351 | incorrect argument (eg: an unresolved backend name). Fetch function arguments |
| 11352 | are passed between parenthesis and are delimited by commas. When an argument |
| 11353 | is optional, it will be indicated below between square brackets ('[ ]'). When |
| 11354 | all arguments are optional, the parenthesis may be omitted. |
| 11355 | |
| 11356 | Thus, the syntax of a standard sample fetch method is one of the following : |
| 11357 | - name |
| 11358 | - name(arg1) |
| 11359 | - name(arg1,arg2) |
| 11360 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11361 | |
| 11362 | 7.3.1. Converters |
| 11363 | ----------------- |
| 11364 | |
Willy Tarreau | e6b11e4 | 2013-11-26 19:02:32 +0100 | [diff] [blame] | 11365 | Sample fetch methods may be combined with transformations to be applied on top |
| 11366 | of the fetched sample (also called "converters"). These combinations form what |
| 11367 | is called "sample expressions" and the result is a "sample". Initially this |
| 11368 | was only supported by "stick on" and "stick store-request" directives but this |
| 11369 | has now be extended to all places where samples may be used (acls, log-format, |
| 11370 | unique-id-format, add-header, ...). |
| 11371 | |
| 11372 | These transformations are enumerated as a series of specific keywords after the |
| 11373 | sample fetch method. These keywords may equally be appended immediately after |
| 11374 | the fetch keyword's argument, delimited by a comma. These keywords can also |
| 11375 | support some arguments (eg: a netmask) which must be passed in parenthesis. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 11376 | |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11377 | A certain category of converters are bitwise and arithmetic operators which |
| 11378 | support performing basic operations on integers. Some bitwise operations are |
| 11379 | supported (and, or, xor, cpl) and some arithmetic operations are supported |
| 11380 | (add, sub, mul, div, mod, neg). Some comparators are provided (odd, even, not, |
| 11381 | bool) which make it possible to report a match without having to write an ACL. |
| 11382 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11383 | The currently available list of transformation keywords include : |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 11384 | |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11385 | add(<value>) |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11386 | Adds <value> to the input value of type signed integer, and returns the |
Thierry FOURNIER | 5d86fae | 2015-07-07 21:10:16 +0200 | [diff] [blame] | 11387 | result as a signed integer. <value> can be a numeric value or a variable |
| 11388 | name. The name of the variable starts by an indication about its scope. The |
| 11389 | allowed scopes are: |
| 11390 | "sess" : the variable is shared with all the session, |
| 11391 | "txn" : the variable is shared with all the transaction (request and |
| 11392 | response), |
| 11393 | "req" : the variable is shared only during the request processing, |
| 11394 | "res" : the variable is shared only during the response processing. |
| 11395 | This prefix is followed by a name. The separator is a '.'. The name may only |
| 11396 | contain characters 'a-z', 'A-Z', '0-9' and '_'. |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11397 | |
| 11398 | and(<value>) |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11399 | Performs a bitwise "AND" between <value> and the input value of type signed |
Thierry FOURNIER | 5d86fae | 2015-07-07 21:10:16 +0200 | [diff] [blame] | 11400 | integer, and returns the result as an signed integer. <value> can be a |
| 11401 | numeric value or a variable name. The name of the variable starts by an |
| 11402 | indication about its scope. The allowed scopes are: |
| 11403 | "sess" : the variable is shared with all the session, |
| 11404 | "txn" : the variable is shared with all the transaction (request and |
| 11405 | response), |
| 11406 | "req" : the variable is shared only during the request processing, |
| 11407 | "res" : the variable is shared only during the response processing. |
| 11408 | This prefix is followed by a name. The separator is a '.'. The name may only |
| 11409 | contain characters 'a-z', 'A-Z', '0-9' and '_'. |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11410 | |
Emeric Brun | 53d1a98 | 2014-04-30 18:21:37 +0200 | [diff] [blame] | 11411 | base64 |
| 11412 | Converts a binary input sample to a base64 string. It is used to log or |
| 11413 | transfer binary content in a way that can be reliably transferred (eg: |
| 11414 | an SSL ID can be copied in a header). |
| 11415 | |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11416 | bool |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11417 | Returns a boolean TRUE if the input value of type signed integer is |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11418 | non-null, otherwise returns FALSE. Used in conjunction with and(), it can be |
| 11419 | used to report true/false for bit testing on input values (eg: verify the |
| 11420 | presence of a flag). |
| 11421 | |
Emeric Brun | 54c4ac8 | 2014-11-03 15:32:43 +0100 | [diff] [blame] | 11422 | bytes(<offset>[,<length>]) |
| 11423 | Extracts some bytes from an input binary sample. The result is a binary |
| 11424 | sample starting at an offset (in bytes) of the original sample and |
| 11425 | optionnaly truncated at the given length. |
| 11426 | |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11427 | cpl |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11428 | Takes the input value of type signed integer, applies a ones-complement |
| 11429 | (flips all bits) and returns the result as an signed integer. |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11430 | |
Willy Tarreau | 8059977 | 2015-01-20 19:35:24 +0100 | [diff] [blame] | 11431 | crc32([<avalanche>]) |
| 11432 | Hashes a binary input sample into an unsigned 32-bit quantity using the CRC32 |
| 11433 | hash function. Optionally, it is possible to apply a full avalanche hash |
| 11434 | function to the output if the optional <avalanche> argument equals 1. This |
| 11435 | converter uses the same functions as used by the various hash-based load |
| 11436 | balancing algorithms, so it will provide exactly the same results. It is |
| 11437 | provided for compatibility with other software which want a CRC32 to be |
| 11438 | computed on some input keys, so it follows the most common implementation as |
| 11439 | found in Ethernet, Gzip, PNG, etc... It is slower than the other algorithms |
| 11440 | but may provide a better or at least less predictable distribution. It must |
| 11441 | not be used for security purposes as a 32-bit hash is trivial to break. See |
| 11442 | also "djb2", "sdbm", "wt6" and the "hash-type" directive. |
| 11443 | |
David Carlier | 29b3ca3 | 2015-09-25 14:09:21 +0100 | [diff] [blame] | 11444 | da-csv-conv(<prop>[,<prop>*]) |
David Carlier | 4542b10 | 2015-06-01 13:54:29 +0200 | [diff] [blame] | 11445 | Asks the DeviceAtlas converter to identify the User Agent string passed on |
| 11446 | input, and to emit a string made of the concatenation of the properties |
| 11447 | enumerated in argument, delimited by the separator defined by the global |
| 11448 | keyword "deviceatlas-property-separator", or by default the pipe character |
| 11449 | ('|'). There's a limit of 5 different properties imposed by the haproxy |
| 11450 | configuration language. |
| 11451 | |
| 11452 | Example: |
| 11453 | frontend www |
| 11454 | bind *:8881 |
| 11455 | default_backend servers |
| 11456 | http-request set-header X-DeviceAtlas-Data %[req.fhdr(User-Agent),da-csv(primaryHardwareType,osName,osVersion,browserName,browserVersion)] |
| 11457 | |
Thierry FOURNIER | 9687c77 | 2015-05-07 15:46:29 +0200 | [diff] [blame] | 11458 | debug |
| 11459 | This converter is used as debug tool. It dumps on screen the content and the |
| 11460 | type of the input sample. The sample is returned as is on its output. This |
| 11461 | converter only exists when haproxy was built with debugging enabled. |
| 11462 | |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11463 | div(<value>) |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11464 | Divides the input value of type signed integer by <value>, and returns the |
| 11465 | result as an signed integer. If <value> is null, the largest unsigned |
Thierry FOURNIER | 5d86fae | 2015-07-07 21:10:16 +0200 | [diff] [blame] | 11466 | integer is returned (typically 2^63-1). <value> can be a numeric value or a |
| 11467 | variable name. The name of the variable starts by an indication about it |
| 11468 | scope. The scope allowed are: |
| 11469 | "sess" : the variable is shared with all the session, |
| 11470 | "txn" : the variable is shared with all the transaction (request and |
| 11471 | response), |
| 11472 | "req" : the variable is shared only during the request processing, |
| 11473 | "res" : the variable is shared only during the response processing. |
| 11474 | This prefix is followed by a name. The separator is a '.'. The name may only |
| 11475 | contain characters 'a-z', 'A-Z', '0-9' and '_'. |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11476 | |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 11477 | djb2([<avalanche>]) |
| 11478 | Hashes a binary input sample into an unsigned 32-bit quantity using the DJB2 |
| 11479 | hash function. Optionally, it is possible to apply a full avalanche hash |
| 11480 | function to the output if the optional <avalanche> argument equals 1. This |
| 11481 | converter uses the same functions as used by the various hash-based load |
| 11482 | balancing algorithms, so it will provide exactly the same results. It is |
| 11483 | mostly intended for debugging, but can be used as a stick-table entry to |
| 11484 | collect rough statistics. It must not be used for security purposes as a |
Willy Tarreau | 8059977 | 2015-01-20 19:35:24 +0100 | [diff] [blame] | 11485 | 32-bit hash is trivial to break. See also "crc32", "sdbm", "wt6" and the |
| 11486 | "hash-type" directive. |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 11487 | |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11488 | even |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11489 | Returns a boolean TRUE if the input value of type signed integer is even |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11490 | otherwise returns FALSE. It is functionally equivalent to "not,and(1),bool". |
| 11491 | |
Emeric Brun | f399b0d | 2014-11-03 17:07:03 +0100 | [diff] [blame] | 11492 | field(<index>,<delimiters>) |
| 11493 | Extracts the substring at the given index considering given delimiters from |
| 11494 | an input string. Indexes start at 1 and delimiters are a string formatted |
| 11495 | list of chars. |
| 11496 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11497 | hex |
| 11498 | Converts a binary input sample to an hex string containing two hex digits per |
| 11499 | input byte. It is used to log or transfer hex dumps of some binary input data |
| 11500 | in a way that can be reliably transferred (eg: an SSL ID can be copied in a |
| 11501 | header). |
Thierry FOURNIER | 2f49d6d | 2014-03-12 15:01:52 +0100 | [diff] [blame] | 11502 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11503 | http_date([<offset>]) |
| 11504 | Converts an integer supposed to contain a date since epoch to a string |
| 11505 | representing this date in a format suitable for use in HTTP header fields. If |
| 11506 | an offset value is specified, then it is a number of seconds that is added to |
| 11507 | the date before the conversion is operated. This is particularly useful to |
| 11508 | emit Date header fields, Expires values in responses when combined with a |
| 11509 | positive offset, or Last-Modified values when the offset is negative. |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11510 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 11511 | in_table(<table>) |
| 11512 | Uses the string representation of the input sample to perform a look up in |
| 11513 | the specified table. If the key is not found in the table, a boolean false |
| 11514 | is returned. Otherwise a boolean true is returned. This can be used to verify |
| 11515 | the presence of a certain key in a table tracking some elements (eg: whether |
| 11516 | or not a source IP address or an Authorization header was already seen). |
| 11517 | |
Willy Tarreau | ffcb2e4 | 2014-07-10 16:29:08 +0200 | [diff] [blame] | 11518 | ipmask(<mask>) |
| 11519 | Apply a mask to an IPv4 address, and use the result for lookups and storage. |
| 11520 | This can be used to make all hosts within a certain mask to share the same |
| 11521 | table entries and as such use the same server. The mask can be passed in |
| 11522 | dotted form (eg: 255.255.255.0) or in CIDR form (eg: 24). |
| 11523 | |
Thierry FOURNIER | 317e1c4 | 2014-08-12 10:20:47 +0200 | [diff] [blame] | 11524 | json([<input-code>]) |
| 11525 | Escapes the input string and produces an ASCII ouput string ready to use as a |
| 11526 | JSON string. The converter tries to decode the input string according to the |
| 11527 | <input-code> parameter. It can be "ascii", "utf8", "utf8s", "utf8"" or |
| 11528 | "utf8ps". The "ascii" decoder never fails. The "utf8" decoder detects 3 types |
| 11529 | of errors: |
| 11530 | - bad UTF-8 sequence (lone continuation byte, bad number of continuation |
| 11531 | bytes, ...) |
| 11532 | - invalid range (the decoded value is within a UTF-8 prohibited range), |
| 11533 | - code overlong (the value is encoded with more bytes than necessary). |
| 11534 | |
| 11535 | The UTF-8 JSON encoding can produce a "too long value" error when the UTF-8 |
| 11536 | character is greater than 0xffff because the JSON string escape specification |
| 11537 | only authorizes 4 hex digits for the value encoding. The UTF-8 decoder exists |
| 11538 | in 4 variants designated by a combination of two suffix letters : "p" for |
| 11539 | "permissive" and "s" for "silently ignore". The behaviors of the decoders |
| 11540 | are : |
| 11541 | - "ascii" : never fails ; |
| 11542 | - "utf8" : fails on any detected errors ; |
| 11543 | - "utf8s" : never fails, but removes characters corresponding to errors ; |
| 11544 | - "utf8p" : accepts and fixes the overlong errors, but fails on any other |
| 11545 | error ; |
| 11546 | - "utf8ps" : never fails, accepts and fixes the overlong errors, but removes |
| 11547 | characters corresponding to the other errors. |
| 11548 | |
| 11549 | This converter is particularly useful for building properly escaped JSON for |
| 11550 | logging to servers which consume JSON-formated traffic logs. |
| 11551 | |
| 11552 | Example: |
| 11553 | capture request header user-agent len 150 |
| 11554 | capture request header Host len 15 |
| 11555 | log-format {"ip":"%[src]","user-agent":"%[capture.req.hdr(1),json]"} |
| 11556 | |
| 11557 | Input request from client 127.0.0.1: |
| 11558 | GET / HTTP/1.0 |
| 11559 | User-Agent: Very "Ugly" UA 1/2 |
| 11560 | |
| 11561 | Output log: |
| 11562 | {"ip":"127.0.0.1","user-agent":"Very \"Ugly\" UA 1\/2"} |
| 11563 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11564 | language(<value>[,<default>]) |
| 11565 | Returns the value with the highest q-factor from a list as extracted from the |
| 11566 | "accept-language" header using "req.fhdr". Values with no q-factor have a |
| 11567 | q-factor of 1. Values with a q-factor of 0 are dropped. Only values which |
| 11568 | belong to the list of semi-colon delimited <values> will be considered. The |
| 11569 | argument <value> syntax is "lang[;lang[;lang[;...]]]". If no value matches the |
| 11570 | given list and a default value is provided, it is returned. Note that language |
| 11571 | names may have a variant after a dash ('-'). If this variant is present in the |
| 11572 | list, it will be matched, but if it is not, only the base language is checked. |
| 11573 | The match is case-sensitive, and the output string is always one of those |
| 11574 | provided in arguments. The ordering of arguments is meaningless, only the |
| 11575 | ordering of the values in the request counts, as the first value among |
| 11576 | multiple sharing the same q-factor is used. |
Thierry FOURNIER | ad90351 | 2014-04-11 17:51:01 +0200 | [diff] [blame] | 11577 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11578 | Example : |
Thierry FOURNIER | ad90351 | 2014-04-11 17:51:01 +0200 | [diff] [blame] | 11579 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11580 | # this configuration switches to the backend matching a |
| 11581 | # given language based on the request : |
Thierry FOURNIER | ad90351 | 2014-04-11 17:51:01 +0200 | [diff] [blame] | 11582 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11583 | acl es req.fhdr(accept-language),language(es;fr;en) -m str es |
| 11584 | acl fr req.fhdr(accept-language),language(es;fr;en) -m str fr |
| 11585 | acl en req.fhdr(accept-language),language(es;fr;en) -m str en |
| 11586 | use_backend spanish if es |
| 11587 | use_backend french if fr |
| 11588 | use_backend english if en |
| 11589 | default_backend choose_your_language |
Thierry FOURNIER | ad90351 | 2014-04-11 17:51:01 +0200 | [diff] [blame] | 11590 | |
Willy Tarreau | ffcb2e4 | 2014-07-10 16:29:08 +0200 | [diff] [blame] | 11591 | lower |
| 11592 | Convert a string sample to lower case. This can only be placed after a string |
| 11593 | sample fetch function or after a transformation keyword returning a string |
| 11594 | type. The result is of type string. |
| 11595 | |
Willy Tarreau | 0dbfdba | 2014-07-10 16:37:47 +0200 | [diff] [blame] | 11596 | ltime(<format>[,<offset>]) |
| 11597 | Converts an integer supposed to contain a date since epoch to a string |
| 11598 | representing this date in local time using a format defined by the <format> |
| 11599 | string using strftime(3). The purpose is to allow any date format to be used |
| 11600 | in logs. An optional <offset> in seconds may be applied to the input date |
| 11601 | (positive or negative). See the strftime() man page for the format supported |
| 11602 | by your operating system. See also the utime converter. |
| 11603 | |
| 11604 | Example : |
| 11605 | |
| 11606 | # Emit two colons, one with the local time and another with ip:port |
| 11607 | # Eg: 20140710162350 127.0.0.1:57325 |
| 11608 | log-format %[date,ltime(%Y%m%d%H%M%S)]\ %ci:%cp |
| 11609 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11610 | map(<map_file>[,<default_value>]) |
| 11611 | map_<match_type>(<map_file>[,<default_value>]) |
| 11612 | map_<match_type>_<output_type>(<map_file>[,<default_value>]) |
| 11613 | Search the input value from <map_file> using the <match_type> matching method, |
| 11614 | and return the associated value converted to the type <output_type>. If the |
| 11615 | input value cannot be found in the <map_file>, the converter returns the |
| 11616 | <default_value>. If the <default_value> is not set, the converter fails and |
| 11617 | acts as if no input value could be fetched. If the <match_type> is not set, it |
| 11618 | defaults to "str". Likewise, if the <output_type> is not set, it defaults to |
| 11619 | "str". For convenience, the "map" keyword is an alias for "map_str" and maps a |
| 11620 | string to another string. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 11621 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11622 | It is important to avoid overlapping between the keys : IP addresses and |
| 11623 | strings are stored in trees, so the first of the finest match will be used. |
| 11624 | Other keys are stored in lists, so the first matching occurrence will be used. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 11625 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11626 | The following array contains the list of all map functions avalaible sorted by |
| 11627 | input type, match type and output type. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 11628 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11629 | input type | match method | output type str | output type int | output type ip |
| 11630 | -----------+--------------+-----------------+-----------------+--------------- |
| 11631 | str | str | map_str | map_str_int | map_str_ip |
| 11632 | -----------+--------------+-----------------+-----------------+--------------- |
Willy Tarreau | 787a4c0 | 2014-05-10 07:55:30 +0200 | [diff] [blame] | 11633 | str | beg | map_beg | map_beg_int | map_end_ip |
| 11634 | -----------+--------------+-----------------+-----------------+--------------- |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11635 | str | sub | map_sub | map_sub_int | map_sub_ip |
| 11636 | -----------+--------------+-----------------+-----------------+--------------- |
| 11637 | str | dir | map_dir | map_dir_int | map_dir_ip |
| 11638 | -----------+--------------+-----------------+-----------------+--------------- |
| 11639 | str | dom | map_dom | map_dom_int | map_dom_ip |
| 11640 | -----------+--------------+-----------------+-----------------+--------------- |
| 11641 | str | end | map_end | map_end_int | map_end_ip |
| 11642 | -----------+--------------+-----------------+-----------------+--------------- |
| 11643 | str | reg | map_reg | map_reg_int | map_reg_ip |
| 11644 | -----------+--------------+-----------------+-----------------+--------------- |
| 11645 | int | int | map_int | map_int_int | map_int_ip |
| 11646 | -----------+--------------+-----------------+-----------------+--------------- |
| 11647 | ip | ip | map_ip | map_ip_int | map_ip_ip |
| 11648 | -----------+--------------+-----------------+-----------------+--------------- |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 11649 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11650 | The file contains one key + value per line. Lines which start with '#' are |
| 11651 | ignored, just like empty lines. Leading tabs and spaces are stripped. The key |
| 11652 | is then the first "word" (series of non-space/tabs characters), and the value |
| 11653 | is what follows this series of space/tab till the end of the line excluding |
| 11654 | trailing spaces/tabs. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 11655 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11656 | Example : |
| 11657 | |
| 11658 | # this is a comment and is ignored |
| 11659 | 2.22.246.0/23 United Kingdom \n |
| 11660 | <-><-----------><--><------------><----> |
| 11661 | | | | | `- trailing spaces ignored |
| 11662 | | | | `---------- value |
| 11663 | | | `-------------------- middle spaces ignored |
| 11664 | | `---------------------------- key |
| 11665 | `------------------------------------ leading spaces ignored |
| 11666 | |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11667 | mod(<value>) |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11668 | Divides the input value of type signed integer by <value>, and returns the |
| 11669 | remainder as an signed integer. If <value> is null, then zero is returned. |
Thierry FOURNIER | 5d86fae | 2015-07-07 21:10:16 +0200 | [diff] [blame] | 11670 | <value> can be a numeric value or a variable name. The name of the variable |
| 11671 | starts by an indication about its scope. The allowed scopes are: |
| 11672 | "sess" : the variable is shared with all the session, |
| 11673 | "txn" : the variable is shared with all the transaction (request and |
| 11674 | response), |
| 11675 | "req" : the variable is shared only during the request processing, |
| 11676 | "res" : the variable is shared only during the response processing. |
| 11677 | This prefix is followed by a name. The separator is a '.'. The name may only |
| 11678 | contain characters 'a-z', 'A-Z', '0-9' and '_'. |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11679 | |
| 11680 | mul(<value>) |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11681 | Multiplies the input value of type signed integer by <value>, and returns |
Thierry FOURNIER | 00c005c | 2015-07-08 01:10:21 +0200 | [diff] [blame] | 11682 | the product as an signed integer. In case of overflow, the largest possible |
| 11683 | value for the sign is returned so that the operation doesn't wrap around. |
Thierry FOURNIER | 5d86fae | 2015-07-07 21:10:16 +0200 | [diff] [blame] | 11684 | <value> can be a numeric value or a variable name. The name of the variable |
| 11685 | starts by an indication about its scope. The allowed scopes are: |
| 11686 | "sess" : the variable is shared with all the session, |
| 11687 | "txn" : the variable is shared with all the transaction (request and |
| 11688 | response), |
| 11689 | "req" : the variable is shared only during the request processing, |
| 11690 | "res" : the variable is shared only during the response processing. |
| 11691 | This prefix is followed by a name. The separator is a '.'. The name may only |
| 11692 | contain characters 'a-z', 'A-Z', '0-9' and '_'. |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11693 | |
| 11694 | neg |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11695 | Takes the input value of type signed integer, computes the opposite value, |
| 11696 | and returns the remainder as an signed integer. 0 is identity. This operator |
| 11697 | is provided for reversed subtracts : in order to subtract the input from a |
| 11698 | constant, simply perform a "neg,add(value)". |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11699 | |
| 11700 | not |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11701 | Returns a boolean FALSE if the input value of type signed integer is |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11702 | non-null, otherwise returns TRUE. Used in conjunction with and(), it can be |
| 11703 | used to report true/false for bit testing on input values (eg: verify the |
| 11704 | absence of a flag). |
| 11705 | |
| 11706 | odd |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11707 | Returns a boolean TRUE if the input value of type signed integer is odd |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11708 | otherwise returns FALSE. It is functionally equivalent to "and(1),bool". |
| 11709 | |
| 11710 | or(<value>) |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11711 | Performs a bitwise "OR" between <value> and the input value of type signed |
Thierry FOURNIER | 5d86fae | 2015-07-07 21:10:16 +0200 | [diff] [blame] | 11712 | integer, and returns the result as an signed integer. <value> can be a |
| 11713 | numeric value or a variable name. The name of the variable starts by an |
| 11714 | indication about its scope. The allowed scopes are: |
| 11715 | "sess" : the variable is shared with all the session, |
| 11716 | "txn" : the variable is shared with all the transaction (request and |
| 11717 | response), |
| 11718 | "req" : the variable is shared only during the request processing, |
| 11719 | "res" : the variable is shared only during the response processing. |
| 11720 | This prefix is followed by a name. The separator is a '.'. The name may only |
| 11721 | contain characters 'a-z', 'A-Z', '0-9' and '_'. |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11722 | |
Willy Tarreau | c4dc350 | 2015-01-23 20:39:28 +0100 | [diff] [blame] | 11723 | regsub(<regex>,<subst>[,<flags>]) |
Willy Tarreau | 7eda849 | 2015-01-20 19:47:06 +0100 | [diff] [blame] | 11724 | Applies a regex-based substitution to the input string. It does the same |
| 11725 | operation as the well-known "sed" utility with "s/<regex>/<subst>/". By |
| 11726 | default it will replace in the input string the first occurrence of the |
| 11727 | largest part matching the regular expression <regex> with the substitution |
| 11728 | string <subst>. It is possible to replace all occurrences instead by adding |
| 11729 | the flag "g" in the third argument <flags>. It is also possible to make the |
| 11730 | regex case insensitive by adding the flag "i" in <flags>. Since <flags> is a |
| 11731 | string, it is made up from the concatenation of all desired flags. Thus if |
| 11732 | both "i" and "g" are desired, using "gi" or "ig" will have the same effect. |
| 11733 | It is important to note that due to the current limitations of the |
| 11734 | configuration parser, some characters such as closing parenthesis or comma |
| 11735 | are not possible to use in the arguments. The first use of this converter is |
| 11736 | to replace certain characters or sequence of characters with other ones. |
| 11737 | |
| 11738 | Example : |
| 11739 | |
| 11740 | # de-duplicate "/" in header "x-path". |
| 11741 | # input: x-path: /////a///b/c/xzxyz/ |
| 11742 | # output: x-path: /a/b/c/xzxyz/ |
| 11743 | http-request set-header x-path %[hdr(x-path),regsub(/+,/,g)] |
| 11744 | |
Thierry FOURNIER | 35ab275 | 2015-05-28 13:22:03 +0200 | [diff] [blame] | 11745 | capture-req(<id>) |
| 11746 | Capture the string entry in the request slot <id> and returns the entry as |
| 11747 | is. If the slot doesn't exist, the capture fails silently. |
| 11748 | |
| 11749 | See also: "declare capture", "http-request capture", |
| 11750 | "http-response capture", "req.hdr.capture" and |
| 11751 | "res.hdr.capture" (sample fetches). |
| 11752 | |
| 11753 | capture-res(<id>) |
| 11754 | Capture the string entry in the response slot <id> and returns the entry as |
| 11755 | is. If the slot doesn't exist, the capture fails silently. |
| 11756 | |
| 11757 | See also: "declare capture", "http-request capture", |
| 11758 | "http-response capture", "req.hdr.capture" and |
| 11759 | "res.hdr.capture" (sample fetches). |
| 11760 | |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 11761 | sdbm([<avalanche>]) |
| 11762 | Hashes a binary input sample into an unsigned 32-bit quantity using the SDBM |
| 11763 | hash function. Optionally, it is possible to apply a full avalanche hash |
| 11764 | function to the output if the optional <avalanche> argument equals 1. This |
| 11765 | converter uses the same functions as used by the various hash-based load |
| 11766 | balancing algorithms, so it will provide exactly the same results. It is |
| 11767 | mostly intended for debugging, but can be used as a stick-table entry to |
| 11768 | collect rough statistics. It must not be used for security purposes as a |
Willy Tarreau | 8059977 | 2015-01-20 19:35:24 +0100 | [diff] [blame] | 11769 | 32-bit hash is trivial to break. See also "crc32", "djb2", "wt6" and the |
| 11770 | "hash-type" directive. |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 11771 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 11772 | set-var(<var name>) |
| 11773 | Sets a variable with the input content and return the content on the output as |
| 11774 | is. The variable keep the value and the associated input type. The name of the |
| 11775 | variable starts by an indication about it scope. The scope allowed are: |
| 11776 | "sess" : the variable is shared with all the session, |
| 11777 | "txn" : the variable is shared with all the transaction (request and |
| 11778 | response), |
| 11779 | "req" : the variable is shared only during the request processing, |
| 11780 | "res" : the variable is shared only during the response processing. |
| 11781 | This prefix is followed by a name. The separator is a '.'. The name may only |
| 11782 | contain characters 'a-z', 'A-Z', '0-9' and '_'. |
| 11783 | |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11784 | sub(<value>) |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11785 | Subtracts <value> from the input value of type signed integer, and returns |
| 11786 | the result as an signed integer. Note: in order to subtract the input from |
Thierry FOURNIER | 5d86fae | 2015-07-07 21:10:16 +0200 | [diff] [blame] | 11787 | a constant, simply perform a "neg,add(value)". <value> can be a numeric value |
| 11788 | or a variable name. The name of the variable starts by an indication about its |
| 11789 | scope. The allowed scopes are: |
| 11790 | "sess" : the variable is shared with all the session, |
| 11791 | "txn" : the variable is shared with all the transaction (request and |
| 11792 | response), |
| 11793 | "req" : the variable is shared only during the request processing, |
| 11794 | "res" : the variable is shared only during the response processing. |
| 11795 | This prefix is followed by a name. The separator is a '.'. The name may only |
| 11796 | contain characters 'a-z', 'A-Z', '0-9' and '_'. |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11797 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 11798 | table_bytes_in_rate(<table>) |
| 11799 | Uses the string representation of the input sample to perform a look up in |
| 11800 | the specified table. If the key is not found in the table, integer value zero |
| 11801 | is returned. Otherwise the converter returns the average client-to-server |
| 11802 | bytes rate associated with the input sample in the designated table, measured |
| 11803 | in amount of bytes over the period configured in the table. See also the |
| 11804 | sc_bytes_in_rate sample fetch keyword. |
| 11805 | |
| 11806 | |
| 11807 | table_bytes_out_rate(<table>) |
| 11808 | Uses the string representation of the input sample to perform a look up in |
| 11809 | the specified table. If the key is not found in the table, integer value zero |
| 11810 | is returned. Otherwise the converter returns the average server-to-client |
| 11811 | bytes rate associated with the input sample in the designated table, measured |
| 11812 | in amount of bytes over the period configured in the table. See also the |
| 11813 | sc_bytes_out_rate sample fetch keyword. |
| 11814 | |
| 11815 | table_conn_cnt(<table>) |
| 11816 | Uses the string representation of the input sample to perform a look up in |
| 11817 | the specified table. If the key is not found in the table, integer value zero |
| 11818 | is returned. Otherwise the converter returns the cumulated amount of incoming |
| 11819 | connections associated with the input sample in the designated table. See |
| 11820 | also the sc_conn_cnt sample fetch keyword. |
| 11821 | |
| 11822 | table_conn_cur(<table>) |
| 11823 | Uses the string representation of the input sample to perform a look up in |
| 11824 | the specified table. If the key is not found in the table, integer value zero |
| 11825 | is returned. Otherwise the converter returns the current amount of concurrent |
| 11826 | tracked connections associated with the input sample in the designated table. |
| 11827 | See also the sc_conn_cur sample fetch keyword. |
| 11828 | |
| 11829 | table_conn_rate(<table>) |
| 11830 | Uses the string representation of the input sample to perform a look up in |
| 11831 | the specified table. If the key is not found in the table, integer value zero |
| 11832 | is returned. Otherwise the converter returns the average incoming connection |
| 11833 | rate associated with the input sample in the designated table. See also the |
| 11834 | sc_conn_rate sample fetch keyword. |
| 11835 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 11836 | table_gpt0(<table>) |
| 11837 | Uses the string representation of the input sample to perform a look up in |
| 11838 | the specified table. If the key is not found in the table, boolean value zero |
| 11839 | is returned. Otherwise the converter returns the current value of the first |
| 11840 | general purpose tag associated with the input sample in the designated table. |
| 11841 | See also the sc_get_gpt0 sample fetch keyword. |
| 11842 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 11843 | table_gpc0(<table>) |
| 11844 | Uses the string representation of the input sample to perform a look up in |
| 11845 | the specified table. If the key is not found in the table, integer value zero |
| 11846 | is returned. Otherwise the converter returns the current value of the first |
| 11847 | general purpose counter associated with the input sample in the designated |
| 11848 | table. See also the sc_get_gpc0 sample fetch keyword. |
| 11849 | |
| 11850 | table_gpc0_rate(<table>) |
| 11851 | Uses the string representation of the input sample to perform a look up in |
| 11852 | the specified table. If the key is not found in the table, integer value zero |
| 11853 | is returned. Otherwise the converter returns the frequency which the gpc0 |
| 11854 | counter was incremented over the configured period in the table, associated |
| 11855 | with the input sample in the designated table. See also the sc_get_gpc0_rate |
| 11856 | sample fetch keyword. |
| 11857 | |
| 11858 | table_http_err_cnt(<table>) |
| 11859 | Uses the string representation of the input sample to perform a look up in |
| 11860 | the specified table. If the key is not found in the table, integer value zero |
| 11861 | is returned. Otherwise the converter returns the cumulated amount of HTTP |
| 11862 | errors associated with the input sample in the designated table. See also the |
| 11863 | sc_http_err_cnt sample fetch keyword. |
| 11864 | |
| 11865 | table_http_err_rate(<table>) |
| 11866 | Uses the string representation of the input sample to perform a look up in |
| 11867 | the specified table. If the key is not found in the table, integer value zero |
| 11868 | is returned. Otherwise the average rate of HTTP errors associated with the |
| 11869 | input sample in the designated table, measured in amount of errors over the |
| 11870 | period configured in the table. See also the sc_http_err_rate sample fetch |
| 11871 | keyword. |
| 11872 | |
| 11873 | table_http_req_cnt(<table>) |
| 11874 | Uses the string representation of the input sample to perform a look up in |
| 11875 | the specified table. If the key is not found in the table, integer value zero |
| 11876 | is returned. Otherwise the converter returns the cumulated amount of HTTP |
| 11877 | requests associated with the input sample in the designated table. See also |
| 11878 | the sc_http_req_cnt sample fetch keyword. |
| 11879 | |
| 11880 | table_http_req_rate(<table>) |
| 11881 | Uses the string representation of the input sample to perform a look up in |
| 11882 | the specified table. If the key is not found in the table, integer value zero |
| 11883 | is returned. Otherwise the average rate of HTTP requests associated with the |
| 11884 | input sample in the designated table, measured in amount of requests over the |
| 11885 | period configured in the table. See also the sc_http_req_rate sample fetch |
| 11886 | keyword. |
| 11887 | |
| 11888 | table_kbytes_in(<table>) |
| 11889 | Uses the string representation of the input sample to perform a look up in |
| 11890 | the specified table. If the key is not found in the table, integer value zero |
| 11891 | is returned. Otherwise the converter returns the cumulated amount of client- |
| 11892 | to-server data associated with the input sample in the designated table, |
| 11893 | measured in kilobytes. The test is currently performed on 32-bit integers, |
| 11894 | which limits values to 4 terabytes. See also the sc_kbytes_in sample fetch |
| 11895 | keyword. |
| 11896 | |
| 11897 | table_kbytes_out(<table>) |
| 11898 | Uses the string representation of the input sample to perform a look up in |
| 11899 | the specified table. If the key is not found in the table, integer value zero |
| 11900 | is returned. Otherwise the converter returns the cumulated amount of server- |
| 11901 | to-client data associated with the input sample in the designated table, |
| 11902 | measured in kilobytes. The test is currently performed on 32-bit integers, |
| 11903 | which limits values to 4 terabytes. See also the sc_kbytes_out sample fetch |
| 11904 | keyword. |
| 11905 | |
| 11906 | table_server_id(<table>) |
| 11907 | Uses the string representation of the input sample to perform a look up in |
| 11908 | the specified table. If the key is not found in the table, integer value zero |
| 11909 | is returned. Otherwise the converter returns the server ID associated with |
| 11910 | the input sample in the designated table. A server ID is associated to a |
| 11911 | sample by a "stick" rule when a connection to a server succeeds. A server ID |
| 11912 | zero means that no server is associated with this key. |
| 11913 | |
| 11914 | table_sess_cnt(<table>) |
| 11915 | Uses the string representation of the input sample to perform a look up in |
| 11916 | the specified table. If the key is not found in the table, integer value zero |
| 11917 | is returned. Otherwise the converter returns the cumulated amount of incoming |
| 11918 | sessions associated with the input sample in the designated table. Note that |
| 11919 | a session here refers to an incoming connection being accepted by the |
| 11920 | "tcp-request connection" rulesets. See also the sc_sess_cnt sample fetch |
| 11921 | keyword. |
| 11922 | |
| 11923 | table_sess_rate(<table>) |
| 11924 | Uses the string representation of the input sample to perform a look up in |
| 11925 | the specified table. If the key is not found in the table, integer value zero |
| 11926 | is returned. Otherwise the converter returns the average incoming session |
| 11927 | rate associated with the input sample in the designated table. Note that a |
| 11928 | session here refers to an incoming connection being accepted by the |
| 11929 | "tcp-request connection" rulesets. See also the sc_sess_rate sample fetch |
| 11930 | keyword. |
| 11931 | |
| 11932 | table_trackers(<table>) |
| 11933 | Uses the string representation of the input sample to perform a look up in |
| 11934 | the specified table. If the key is not found in the table, integer value zero |
| 11935 | is returned. Otherwise the converter returns the current amount of concurrent |
| 11936 | connections tracking the same key as the input sample in the designated |
| 11937 | table. It differs from table_conn_cur in that it does not rely on any stored |
| 11938 | information but on the table's reference count (the "use" value which is |
| 11939 | returned by "show table" on the CLI). This may sometimes be more suited for |
| 11940 | layer7 tracking. It can be used to tell a server how many concurrent |
| 11941 | connections there are from a given address for example. See also the |
| 11942 | sc_trackers sample fetch keyword. |
| 11943 | |
Willy Tarreau | ffcb2e4 | 2014-07-10 16:29:08 +0200 | [diff] [blame] | 11944 | upper |
| 11945 | Convert a string sample to upper case. This can only be placed after a string |
| 11946 | sample fetch function or after a transformation keyword returning a string |
| 11947 | type. The result is of type string. |
| 11948 | |
Thierry FOURNIER | 82ff3c9 | 2015-05-07 15:46:20 +0200 | [diff] [blame] | 11949 | url_dec |
| 11950 | Takes an url-encoded string provided as input and returns the decoded |
| 11951 | version as output. The input and the output are of type string. |
| 11952 | |
Willy Tarreau | 0dbfdba | 2014-07-10 16:37:47 +0200 | [diff] [blame] | 11953 | utime(<format>[,<offset>]) |
| 11954 | Converts an integer supposed to contain a date since epoch to a string |
| 11955 | representing this date in UTC time using a format defined by the <format> |
| 11956 | string using strftime(3). The purpose is to allow any date format to be used |
| 11957 | in logs. An optional <offset> in seconds may be applied to the input date |
| 11958 | (positive or negative). See the strftime() man page for the format supported |
| 11959 | by your operating system. See also the ltime converter. |
| 11960 | |
| 11961 | Example : |
| 11962 | |
| 11963 | # Emit two colons, one with the UTC time and another with ip:port |
| 11964 | # Eg: 20140710162350 127.0.0.1:57325 |
| 11965 | log-format %[date,utime(%Y%m%d%H%M%S)]\ %ci:%cp |
| 11966 | |
Emeric Brun | c9a0f6d | 2014-11-25 14:09:01 +0100 | [diff] [blame] | 11967 | word(<index>,<delimiters>) |
| 11968 | Extracts the nth word considering given delimiters from an input string. |
| 11969 | Indexes start at 1 and delimiters are a string formatted list of chars. |
| 11970 | |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 11971 | wt6([<avalanche>]) |
| 11972 | Hashes a binary input sample into an unsigned 32-bit quantity using the WT6 |
| 11973 | hash function. Optionally, it is possible to apply a full avalanche hash |
| 11974 | function to the output if the optional <avalanche> argument equals 1. This |
| 11975 | converter uses the same functions as used by the various hash-based load |
| 11976 | balancing algorithms, so it will provide exactly the same results. It is |
| 11977 | mostly intended for debugging, but can be used as a stick-table entry to |
| 11978 | collect rough statistics. It must not be used for security purposes as a |
Willy Tarreau | 8059977 | 2015-01-20 19:35:24 +0100 | [diff] [blame] | 11979 | 32-bit hash is trivial to break. See also "crc32", "djb2", "sdbm", and the |
| 11980 | "hash-type" directive. |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 11981 | |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11982 | xor(<value>) |
| 11983 | Performs a bitwise "XOR" (exclusive OR) between <value> and the input value |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 11984 | of type signed integer, and returns the result as an signed integer. |
Thierry FOURNIER | 5d86fae | 2015-07-07 21:10:16 +0200 | [diff] [blame] | 11985 | <value> can be a numeric value or a variable name. The name of the variable |
| 11986 | starts by an indication about its scope. The allowed scopes are: |
| 11987 | "sess" : the variable is shared with all the session, |
| 11988 | "txn" : the variable is shared with all the transaction (request and |
| 11989 | response), |
| 11990 | "req" : the variable is shared only during the request processing, |
| 11991 | "res" : the variable is shared only during the response processing. |
| 11992 | This prefix is followed by a name. The separator is a '.'. The name may only |
| 11993 | contain characters 'a-z', 'A-Z', '0-9' and '_'. |
Willy Tarreau | 9770787 | 2015-01-27 15:12:13 +0100 | [diff] [blame] | 11994 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 11995 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 11996 | 7.3.2. Fetching samples from internal states |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 11997 | -------------------------------------------- |
| 11998 | |
| 11999 | A first set of sample fetch methods applies to internal information which does |
| 12000 | not even relate to any client information. These ones are sometimes used with |
| 12001 | "monitor-fail" directives to report an internal status to external watchers. |
| 12002 | The sample fetch methods described in this section are usable anywhere. |
| 12003 | |
| 12004 | always_false : boolean |
| 12005 | Always returns the boolean "false" value. It may be used with ACLs as a |
| 12006 | temporary replacement for another one when adjusting configurations. |
| 12007 | |
| 12008 | always_true : boolean |
| 12009 | Always returns the boolean "true" value. It may be used with ACLs as a |
| 12010 | temporary replacement for another one when adjusting configurations. |
| 12011 | |
| 12012 | avg_queue([<backend>]) : integer |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 12013 | Returns the total number of queued connections of the designated backend |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12014 | divided by the number of active servers. The current backend is used if no |
| 12015 | backend is specified. This is very similar to "queue" except that the size of |
| 12016 | the farm is considered, in order to give a more accurate measurement of the |
| 12017 | time it may take for a new connection to be processed. The main usage is with |
| 12018 | ACL to return a sorry page to new users when it becomes certain they will get |
| 12019 | a degraded service, or to pass to the backend servers in a header so that |
| 12020 | they decide to work in degraded mode or to disable some functions to speed up |
| 12021 | the processing a bit. Note that in the event there would not be any active |
| 12022 | server anymore, twice the number of queued connections would be considered as |
| 12023 | the measured value. This is a fair estimate, as we expect one server to get |
| 12024 | back soon anyway, but we still prefer to send new traffic to another backend |
| 12025 | if in better shape. See also the "queue", "be_conn", and "be_sess_rate" |
| 12026 | sample fetches. |
Krzysztof Piotr Oledzki | 346f76d | 2010-01-12 21:59:30 +0100 | [diff] [blame] | 12027 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12028 | be_conn([<backend>]) : integer |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 12029 | Applies to the number of currently established connections on the backend, |
| 12030 | possibly including the connection being evaluated. If no backend name is |
| 12031 | specified, the current one is used. But it is also possible to check another |
| 12032 | backend. It can be used to use a specific farm when the nominal one is full. |
| 12033 | See also the "fe_conn", "queue" and "be_sess_rate" criteria. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 12034 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12035 | be_sess_rate([<backend>]) : integer |
| 12036 | Returns an integer value corresponding to the sessions creation rate on the |
| 12037 | backend, in number of new sessions per second. This is used with ACLs to |
| 12038 | switch to an alternate backend when an expensive or fragile one reaches too |
| 12039 | high a session rate, or to limit abuse of service (eg. prevent sucking of an |
| 12040 | online dictionary). It can also be useful to add this element to logs using a |
| 12041 | log-format directive. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 12042 | |
| 12043 | Example : |
| 12044 | # Redirect to an error page if the dictionary is requested too often |
| 12045 | backend dynamic |
| 12046 | mode http |
| 12047 | acl being_scanned be_sess_rate gt 100 |
| 12048 | redirect location /denied.html if being_scanned |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 12049 | |
Thierry FOURNIER | cc10329 | 2015-06-06 19:30:17 +0200 | [diff] [blame] | 12050 | bin(<hexa>) : bin |
| 12051 | Returns a binary chain. The input is the hexadecimal representation |
| 12052 | of the string. |
| 12053 | |
| 12054 | bool(<bool>) : bool |
| 12055 | Returns a boolean value. <bool> can be 'true', 'false', '1' or '0'. |
| 12056 | 'false' and '0' are the same. 'true' and '1' are the same. |
| 12057 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12058 | connslots([<backend>]) : integer |
| 12059 | Returns an integer value corresponding to the number of connection slots |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 12060 | still available in the backend, by totaling the maximum amount of |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12061 | connections on all servers and the maximum queue size. This is probably only |
| 12062 | used with ACLs. |
Tait Clarridge | 7896d52 | 2012-12-05 21:39:31 -0500 | [diff] [blame] | 12063 | |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 12064 | The basic idea here is to be able to measure the number of connection "slots" |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 12065 | still available (connection + queue), so that anything beyond that (intended |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 12066 | usage; see "use_backend" keyword) can be redirected to a different backend. |
| 12067 | |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 12068 | 'connslots' = number of available server connection slots, + number of |
| 12069 | available server queue slots. |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 12070 | |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 12071 | Note that while "fe_conn" may be used, "connslots" comes in especially |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 12072 | useful when you have a case of traffic going to one single ip, splitting into |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12073 | multiple backends (perhaps using ACLs to do name-based load balancing) and |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 12074 | you want to be able to differentiate between different backends, and their |
| 12075 | available "connslots". Also, whereas "nbsrv" only measures servers that are |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12076 | actually *down*, this fetch is more fine-grained and looks into the number of |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 12077 | available connection slots as well. See also "queue" and "avg_queue". |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 12078 | |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 12079 | OTHER CAVEATS AND NOTES: at this point in time, the code does not take care |
| 12080 | of dynamic connections. Also, if any of the server maxconn, or maxqueue is 0, |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12081 | then this fetch clearly does not make sense, in which case the value returned |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 12082 | will be -1. |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 12083 | |
Willy Tarreau | 6236d3a | 2013-07-25 14:28:25 +0200 | [diff] [blame] | 12084 | date([<offset>]) : integer |
| 12085 | Returns the current date as the epoch (number of seconds since 01/01/1970). |
| 12086 | If an offset value is specified, then it is a number of seconds that is added |
| 12087 | to the current date before returning the value. This is particularly useful |
| 12088 | to compute relative dates, as both positive and negative offsets are allowed. |
Willy Tarreau | 276fae9 | 2013-07-25 14:36:01 +0200 | [diff] [blame] | 12089 | It is useful combined with the http_date converter. |
| 12090 | |
| 12091 | Example : |
| 12092 | |
| 12093 | # set an expires header to now+1 hour in every response |
| 12094 | http-response set-header Expires %[date(3600),http_date] |
Willy Tarreau | 6236d3a | 2013-07-25 14:28:25 +0200 | [diff] [blame] | 12095 | |
Willy Tarreau | 595ec54 | 2013-06-12 21:34:28 +0200 | [diff] [blame] | 12096 | env(<name>) : string |
| 12097 | Returns a string containing the value of environment variable <name>. As a |
| 12098 | reminder, environment variables are per-process and are sampled when the |
| 12099 | process starts. This can be useful to pass some information to a next hop |
| 12100 | server, or with ACLs to take specific action when the process is started a |
| 12101 | certain way. |
| 12102 | |
| 12103 | Examples : |
| 12104 | # Pass the Via header to next hop with the local hostname in it |
| 12105 | http-request add-header Via 1.1\ %[env(HOSTNAME)] |
| 12106 | |
| 12107 | # reject cookie-less requests when the STOP environment variable is set |
| 12108 | http-request deny if !{ cook(SESSIONID) -m found } { env(STOP) -m found } |
| 12109 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12110 | fe_conn([<frontend>]) : integer |
| 12111 | Returns the number of currently established connections on the frontend, |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 12112 | possibly including the connection being evaluated. If no frontend name is |
| 12113 | specified, the current one is used. But it is also possible to check another |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12114 | frontend. It can be used to return a sorry page before hard-blocking, or to |
| 12115 | use a specific backend to drain new requests when the farm is considered |
| 12116 | full. This is mostly used with ACLs but can also be used to pass some |
| 12117 | statistics to servers in HTTP headers. See also the "dst_conn", "be_conn", |
| 12118 | "fe_sess_rate" fetches. |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 12119 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12120 | fe_sess_rate([<frontend>]) : integer |
| 12121 | Returns an integer value corresponding to the sessions creation rate on the |
| 12122 | frontend, in number of new sessions per second. This is used with ACLs to |
| 12123 | limit the incoming session rate to an acceptable range in order to prevent |
| 12124 | abuse of service at the earliest moment, for example when combined with other |
| 12125 | layer 4 ACLs in order to force the clients to wait a bit for the rate to go |
| 12126 | down below the limit. It can also be useful to add this element to logs using |
| 12127 | a log-format directive. See also the "rate-limit sessions" directive for use |
| 12128 | in frontends. |
Willy Tarreau | 079ff0a | 2009-03-05 21:34:28 +0100 | [diff] [blame] | 12129 | |
| 12130 | Example : |
| 12131 | # This frontend limits incoming mails to 10/s with a max of 100 |
| 12132 | # concurrent connections. We accept any connection below 10/s, and |
| 12133 | # force excess clients to wait for 100 ms. Since clients are limited to |
| 12134 | # 100 max, there cannot be more than 10 incoming mails per second. |
| 12135 | frontend mail |
| 12136 | bind :25 |
| 12137 | mode tcp |
| 12138 | maxconn 100 |
| 12139 | acl too_fast fe_sess_rate ge 10 |
| 12140 | tcp-request inspect-delay 100ms |
| 12141 | tcp-request content accept if ! too_fast |
| 12142 | tcp-request content accept if WAIT_END |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 12143 | |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 12144 | int(<integer>) : signed integer |
| 12145 | Returns a signed integer. |
| 12146 | |
Thierry FOURNIER | cc10329 | 2015-06-06 19:30:17 +0200 | [diff] [blame] | 12147 | ipv4(<ipv4>) : ipv4 |
| 12148 | Returns an ipv4. |
| 12149 | |
| 12150 | ipv6(<ipv6>) : ipv6 |
| 12151 | Returns an ipv6. |
| 12152 | |
| 12153 | meth(<method>) : method |
| 12154 | Returns a method. |
| 12155 | |
Willy Tarreau | 0f30d26 | 2014-11-24 16:02:05 +0100 | [diff] [blame] | 12156 | nbproc : integer |
| 12157 | Returns an integer value corresponding to the number of processes that were |
| 12158 | started (it equals the global "nbproc" setting). This is useful for logging |
| 12159 | and debugging purposes. |
| 12160 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12161 | nbsrv([<backend>]) : integer |
| 12162 | Returns an integer value corresponding to the number of usable servers of |
| 12163 | either the current backend or the named backend. This is mostly used with |
| 12164 | ACLs but can also be useful when added to logs. This is normally used to |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 12165 | switch to an alternate backend when the number of servers is too low to |
| 12166 | to handle some load. It is useful to report a failure when combined with |
| 12167 | "monitor fail". |
Willy Tarreau | 079ff0a | 2009-03-05 21:34:28 +0100 | [diff] [blame] | 12168 | |
Willy Tarreau | 0f30d26 | 2014-11-24 16:02:05 +0100 | [diff] [blame] | 12169 | proc : integer |
| 12170 | Returns an integer value corresponding to the position of the process calling |
| 12171 | the function, between 1 and global.nbproc. This is useful for logging and |
| 12172 | debugging purposes. |
| 12173 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12174 | queue([<backend>]) : integer |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 12175 | Returns the total number of queued connections of the designated backend, |
| 12176 | including all the connections in server queues. If no backend name is |
| 12177 | specified, the current one is used, but it is also possible to check another |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12178 | one. This is useful with ACLs or to pass statistics to backend servers. This |
| 12179 | can be used to take actions when queuing goes above a known level, generally |
| 12180 | indicating a surge of traffic or a massive slowdown on the servers. One |
| 12181 | possible action could be to reject new users but still accept old ones. See |
| 12182 | also the "avg_queue", "be_conn", and "be_sess_rate" fetches. |
| 12183 | |
Willy Tarreau | 84310e2 | 2014-02-14 11:59:04 +0100 | [diff] [blame] | 12184 | rand([<range>]) : integer |
| 12185 | Returns a random integer value within a range of <range> possible values, |
| 12186 | starting at zero. If the range is not specified, it defaults to 2^32, which |
| 12187 | gives numbers between 0 and 4294967295. It can be useful to pass some values |
| 12188 | needed to take some routing decisions for example, or just for debugging |
| 12189 | purposes. This random must not be used for security purposes. |
| 12190 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12191 | srv_conn([<backend>/]<server>) : integer |
| 12192 | Returns an integer value corresponding to the number of currently established |
| 12193 | connections on the designated server, possibly including the connection being |
| 12194 | evaluated. If <backend> is omitted, then the server is looked up in the |
| 12195 | current backend. It can be used to use a specific farm when one server is |
| 12196 | full, or to inform the server about our view of the number of active |
| 12197 | connections with it. See also the "fe_conn", "be_conn" and "queue" fetch |
| 12198 | methods. |
| 12199 | |
| 12200 | srv_is_up([<backend>/]<server>) : boolean |
| 12201 | Returns true when the designated server is UP, and false when it is either |
| 12202 | DOWN or in maintenance mode. If <backend> is omitted, then the server is |
| 12203 | looked up in the current backend. It is mainly used to take action based on |
| 12204 | an external status reported via a health check (eg: a geographical site's |
| 12205 | availability). Another possible use which is more of a hack consists in |
| 12206 | using dummy servers as boolean variables that can be enabled or disabled from |
| 12207 | the CLI, so that rules depending on those ACLs can be tweaked in realtime. |
| 12208 | |
| 12209 | srv_sess_rate([<backend>/]<server>) : integer |
| 12210 | Returns an integer corresponding to the sessions creation rate on the |
| 12211 | designated server, in number of new sessions per second. If <backend> is |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 12212 | omitted, then the server is looked up in the current backend. This is mostly |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12213 | used with ACLs but can make sense with logs too. This is used to switch to an |
| 12214 | alternate backend when an expensive or fragile one reaches too high a session |
| 12215 | rate, or to limit abuse of service (eg. prevent latent requests from |
| 12216 | overloading servers). |
| 12217 | |
| 12218 | Example : |
| 12219 | # Redirect to a separate back |
| 12220 | acl srv1_full srv_sess_rate(be1/srv1) gt 50 |
| 12221 | acl srv2_full srv_sess_rate(be1/srv2) gt 50 |
| 12222 | use_backend be2 if srv1_full or srv2_full |
| 12223 | |
Willy Tarreau | 0f30d26 | 2014-11-24 16:02:05 +0100 | [diff] [blame] | 12224 | stopping : boolean |
| 12225 | Returns TRUE if the process calling the function is currently stopping. This |
| 12226 | can be useful for logging, or for relaxing certain checks or helping close |
| 12227 | certain connections upon graceful shutdown. |
| 12228 | |
Thierry FOURNIER | cc10329 | 2015-06-06 19:30:17 +0200 | [diff] [blame] | 12229 | str(<string>) : string |
| 12230 | Returns a string. |
| 12231 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12232 | table_avl([<table>]) : integer |
| 12233 | Returns the total number of available entries in the current proxy's |
| 12234 | stick-table or in the designated stick-table. See also table_cnt. |
| 12235 | |
| 12236 | table_cnt([<table>]) : integer |
| 12237 | Returns the total number of entries currently in use in the current proxy's |
| 12238 | stick-table or in the designated stick-table. See also src_conn_cnt and |
| 12239 | table_avl for other entry counting methods. |
| 12240 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 12241 | var(<var-name>) : undefined |
| 12242 | Returns a variable with the stored type. If the variable is not set, the |
| 12243 | sample fetch fails. The name of the variable starts by an indication about its |
| 12244 | scope. The scope allowed are: |
| 12245 | "sess" : the variable is shared with all the session, |
| 12246 | "txn" : the variable is shared with all the transaction (request and |
| 12247 | response), |
| 12248 | "req" : the variable is shared only during the request processing, |
| 12249 | "res" : the variable is shared only during the response processing. |
| 12250 | This prefix is followed by a name. The separator is a '.'. The name may only |
| 12251 | contain characters 'a-z', 'A-Z', '0-9' and '_'. |
| 12252 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12253 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 12254 | 7.3.3. Fetching samples at Layer 4 |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12255 | ---------------------------------- |
| 12256 | |
| 12257 | The layer 4 usually describes just the transport layer which in haproxy is |
| 12258 | closest to the connection, where no content is yet made available. The fetch |
| 12259 | methods described here are usable as low as the "tcp-request connection" rule |
| 12260 | sets unless they require some future information. Those generally include |
| 12261 | TCP/IP addresses and ports, as well as elements from stick-tables related to |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12262 | the incoming connection. For retrieving a value from a sticky counters, the |
| 12263 | counter number can be explicitly set as 0, 1, or 2 using the pre-defined |
| 12264 | "sc0_", "sc1_", or "sc2_" prefix, or it can be specified as the first integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12265 | argument when using the "sc_" prefix. An optional table may be specified with |
| 12266 | the "sc*" form, in which case the currently tracked key will be looked up into |
| 12267 | this alternate table instead of the table currently being tracked. |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12268 | |
| 12269 | be_id : integer |
| 12270 | Returns an integer containing the current backend's id. It can be used in |
| 12271 | frontends with responses to check which backend processed the request. |
| 12272 | |
| 12273 | dst : ip |
| 12274 | This is the destination IPv4 address of the connection on the client side, |
| 12275 | which is the address the client connected to. It can be useful when running |
| 12276 | in transparent mode. It is of type IP and works on both IPv4 and IPv6 tables. |
| 12277 | On IPv6 tables, IPv4 address is mapped to its IPv6 equivalent, according to |
| 12278 | RFC 4291. |
| 12279 | |
| 12280 | dst_conn : integer |
| 12281 | Returns an integer value corresponding to the number of currently established |
| 12282 | connections on the same socket including the one being evaluated. It is |
| 12283 | normally used with ACLs but can as well be used to pass the information to |
| 12284 | servers in an HTTP header or in logs. It can be used to either return a sorry |
| 12285 | page before hard-blocking, or to use a specific backend to drain new requests |
| 12286 | when the socket is considered saturated. This offers the ability to assign |
| 12287 | different limits to different listening ports or addresses. See also the |
| 12288 | "fe_conn" and "be_conn" fetches. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 12289 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12290 | dst_port : integer |
| 12291 | Returns an integer value corresponding to the destination TCP port of the |
| 12292 | connection on the client side, which is the port the client connected to. |
| 12293 | This might be used when running in transparent mode, when assigning dynamic |
| 12294 | ports to some clients for a whole application session, to stick all users to |
| 12295 | a same server, or to pass the destination port information to a server using |
| 12296 | an HTTP header. |
| 12297 | |
| 12298 | fe_id : integer |
| 12299 | Returns an integer containing the current frontend's id. It can be used in |
| 12300 | backends to check from which backend it was called, or to stick all users |
| 12301 | coming via a same frontend to the same server. |
| 12302 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12303 | sc_bytes_in_rate(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12304 | sc0_bytes_in_rate([<table>]) : integer |
| 12305 | sc1_bytes_in_rate([<table>]) : integer |
| 12306 | sc2_bytes_in_rate([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12307 | Returns the average client-to-server bytes rate from the currently tracked |
| 12308 | counters, measured in amount of bytes over the period configured in the |
| 12309 | table. See also src_bytes_in_rate. |
| 12310 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12311 | sc_bytes_out_rate(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12312 | sc0_bytes_out_rate([<table>]) : integer |
| 12313 | sc1_bytes_out_rate([<table>]) : integer |
| 12314 | sc2_bytes_out_rate([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12315 | Returns the average server-to-client bytes rate from the currently tracked |
| 12316 | counters, measured in amount of bytes over the period configured in the |
| 12317 | table. See also src_bytes_out_rate. |
| 12318 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12319 | sc_clr_gpc0(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12320 | sc0_clr_gpc0([<table>]) : integer |
| 12321 | sc1_clr_gpc0([<table>]) : integer |
| 12322 | sc2_clr_gpc0([<table>]) : integer |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 12323 | Clears the first General Purpose Counter associated to the currently tracked |
| 12324 | counters, and returns its previous value. Before the first invocation, the |
Willy Tarreau | 869948b | 2013-01-04 14:14:57 +0100 | [diff] [blame] | 12325 | stored value is zero, so first invocation will always return zero. This is |
| 12326 | typically used as a second ACL in an expression in order to mark a connection |
| 12327 | when a first ACL was verified : |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 12328 | |
| 12329 | # block if 5 consecutive requests continue to come faster than 10 sess |
| 12330 | # per second, and reset the counter as soon as the traffic slows down. |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 12331 | acl abuse sc0_http_req_rate gt 10 |
| 12332 | acl kill sc0_inc_gpc0 gt 5 |
| 12333 | acl save sc0_clr_gpc0 ge 0 |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 12334 | tcp-request connection accept if !abuse save |
| 12335 | tcp-request connection reject if abuse kill |
| 12336 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12337 | sc_conn_cnt(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12338 | sc0_conn_cnt([<table>]) : integer |
| 12339 | sc1_conn_cnt([<table>]) : integer |
| 12340 | sc2_conn_cnt([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12341 | Returns the cumulated number of incoming connections from currently tracked |
| 12342 | counters. See also src_conn_cnt. |
| 12343 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12344 | sc_conn_cur(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12345 | sc0_conn_cur([<table>]) : integer |
| 12346 | sc1_conn_cur([<table>]) : integer |
| 12347 | sc2_conn_cur([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12348 | Returns the current amount of concurrent connections tracking the same |
| 12349 | tracked counters. This number is automatically incremented when tracking |
| 12350 | begins and decremented when tracking stops. See also src_conn_cur. |
| 12351 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12352 | sc_conn_rate(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12353 | sc0_conn_rate([<table>]) : integer |
| 12354 | sc1_conn_rate([<table>]) : integer |
| 12355 | sc2_conn_rate([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12356 | Returns the average connection rate from the currently tracked counters, |
| 12357 | measured in amount of connections over the period configured in the table. |
| 12358 | See also src_conn_rate. |
| 12359 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12360 | sc_get_gpc0(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12361 | sc0_get_gpc0([<table>]) : integer |
| 12362 | sc1_get_gpc0([<table>]) : integer |
| 12363 | sc2_get_gpc0([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12364 | Returns the value of the first General Purpose Counter associated to the |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12365 | currently tracked counters. See also src_get_gpc0 and sc/sc0/sc1/sc2_inc_gpc0. |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 12366 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 12367 | sc_get_gpt0(<ctr>[,<table>]) : integer |
| 12368 | sc0_get_gpt0([<table>]) : integer |
| 12369 | sc1_get_gpt0([<table>]) : integer |
| 12370 | sc2_get_gpt0([<table>]) : integer |
| 12371 | Returns the value of the first General Purpose Tag associated to the |
| 12372 | currently tracked counters. See also src_get_gpt0. |
| 12373 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12374 | sc_gpc0_rate(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12375 | sc0_gpc0_rate([<table>]) : integer |
| 12376 | sc1_gpc0_rate([<table>]) : integer |
| 12377 | sc2_gpc0_rate([<table>]) : integer |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 12378 | Returns the average increment rate of the first General Purpose Counter |
| 12379 | associated to the currently tracked counters. It reports the frequency |
| 12380 | which the gpc0 counter was incremented over the configured period. See also |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12381 | src_gpc0_rate, sc/sc0/sc1/sc2_get_gpc0, and sc/sc0/sc1/sc2_inc_gpc0. Note |
| 12382 | that the "gpc0_rate" counter must be stored in the stick-table for a value to |
| 12383 | be returned, as "gpc0" only holds the event count. |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12384 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12385 | sc_http_err_cnt(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12386 | sc0_http_err_cnt([<table>]) : integer |
| 12387 | sc1_http_err_cnt([<table>]) : integer |
| 12388 | sc2_http_err_cnt([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12389 | Returns the cumulated number of HTTP errors from the currently tracked |
| 12390 | counters. This includes the both request errors and 4xx error responses. |
| 12391 | See also src_http_err_cnt. |
| 12392 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12393 | sc_http_err_rate(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12394 | sc0_http_err_rate([<table>]) : integer |
| 12395 | sc1_http_err_rate([<table>]) : integer |
| 12396 | sc2_http_err_rate([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12397 | Returns the average rate of HTTP errors from the currently tracked counters, |
| 12398 | measured in amount of errors over the period configured in the table. This |
| 12399 | includes the both request errors and 4xx error responses. See also |
| 12400 | src_http_err_rate. |
| 12401 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12402 | sc_http_req_cnt(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12403 | sc0_http_req_cnt([<table>]) : integer |
| 12404 | sc1_http_req_cnt([<table>]) : integer |
| 12405 | sc2_http_req_cnt([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12406 | Returns the cumulated number of HTTP requests from the currently tracked |
| 12407 | counters. This includes every started request, valid or not. See also |
| 12408 | src_http_req_cnt. |
| 12409 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12410 | sc_http_req_rate(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12411 | sc0_http_req_rate([<table>]) : integer |
| 12412 | sc1_http_req_rate([<table>]) : integer |
| 12413 | sc2_http_req_rate([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12414 | Returns the average rate of HTTP requests from the currently tracked |
| 12415 | counters, measured in amount of requests over the period configured in |
| 12416 | the table. This includes every started request, valid or not. See also |
| 12417 | src_http_req_rate. |
| 12418 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12419 | sc_inc_gpc0(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12420 | sc0_inc_gpc0([<table>]) : integer |
| 12421 | sc1_inc_gpc0([<table>]) : integer |
| 12422 | sc2_inc_gpc0([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12423 | Increments the first General Purpose Counter associated to the currently |
Willy Tarreau | 869948b | 2013-01-04 14:14:57 +0100 | [diff] [blame] | 12424 | tracked counters, and returns its new value. Before the first invocation, |
| 12425 | the stored value is zero, so first invocation will increase it to 1 and will |
| 12426 | return 1. This is typically used as a second ACL in an expression in order |
| 12427 | to mark a connection when a first ACL was verified : |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12428 | |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 12429 | acl abuse sc0_http_req_rate gt 10 |
| 12430 | acl kill sc0_inc_gpc0 gt 0 |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12431 | tcp-request connection reject if abuse kill |
| 12432 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12433 | sc_kbytes_in(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12434 | sc0_kbytes_in([<table>]) : integer |
| 12435 | sc1_kbytes_in([<table>]) : integer |
| 12436 | sc2_kbytes_in([<table>]) : integer |
Willy Tarreau | a01b974 | 2014-07-10 15:29:24 +0200 | [diff] [blame] | 12437 | Returns the total amount of client-to-server data from the currently tracked |
| 12438 | counters, measured in kilobytes. The test is currently performed on 32-bit |
| 12439 | integers, which limits values to 4 terabytes. See also src_kbytes_in. |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12440 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12441 | sc_kbytes_out(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12442 | sc0_kbytes_out([<table>]) : integer |
| 12443 | sc1_kbytes_out([<table>]) : integer |
| 12444 | sc2_kbytes_out([<table>]) : integer |
Willy Tarreau | a01b974 | 2014-07-10 15:29:24 +0200 | [diff] [blame] | 12445 | Returns the total amount of server-to-client data from the currently tracked |
| 12446 | counters, measured in kilobytes. The test is currently performed on 32-bit |
| 12447 | integers, which limits values to 4 terabytes. See also src_kbytes_out. |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12448 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12449 | sc_sess_cnt(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12450 | sc0_sess_cnt([<table>]) : integer |
| 12451 | sc1_sess_cnt([<table>]) : integer |
| 12452 | sc2_sess_cnt([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12453 | Returns the cumulated number of incoming connections that were transformed |
| 12454 | into sessions, which means that they were accepted by a "tcp-request |
| 12455 | connection" rule, from the currently tracked counters. A backend may count |
| 12456 | more sessions than connections because each connection could result in many |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 12457 | backend sessions if some HTTP keep-alive is performed over the connection |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12458 | with the client. See also src_sess_cnt. |
| 12459 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12460 | sc_sess_rate(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12461 | sc0_sess_rate([<table>]) : integer |
| 12462 | sc1_sess_rate([<table>]) : integer |
| 12463 | sc2_sess_rate([<table>]) : integer |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12464 | Returns the average session rate from the currently tracked counters, |
| 12465 | measured in amount of sessions over the period configured in the table. A |
| 12466 | session is a connection that got past the early "tcp-request connection" |
| 12467 | rules. A backend may count more sessions than connections because each |
| 12468 | connection could result in many backend sessions if some HTTP keep-alive is |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 12469 | performed over the connection with the client. See also src_sess_rate. |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12470 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12471 | sc_tracked(<ctr>[,<table>]) : boolean |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12472 | sc0_tracked([<table>]) : boolean |
| 12473 | sc1_tracked([<table>]) : boolean |
| 12474 | sc2_tracked([<table>]) : boolean |
Willy Tarreau | 6f1615f | 2013-06-03 15:15:22 +0200 | [diff] [blame] | 12475 | Returns true if the designated session counter is currently being tracked by |
| 12476 | the current session. This can be useful when deciding whether or not we want |
| 12477 | to set some values in a header passed to the server. |
| 12478 | |
Cyril Bonté | 62ba870 | 2014-04-22 23:52:25 +0200 | [diff] [blame] | 12479 | sc_trackers(<ctr>[,<table>]) : integer |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 12480 | sc0_trackers([<table>]) : integer |
| 12481 | sc1_trackers([<table>]) : integer |
| 12482 | sc2_trackers([<table>]) : integer |
Willy Tarreau | 2406db4 | 2012-12-09 12:16:43 +0100 | [diff] [blame] | 12483 | Returns the current amount of concurrent connections tracking the same |
| 12484 | tracked counters. This number is automatically incremented when tracking |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 12485 | begins and decremented when tracking stops. It differs from sc0_conn_cur in |
Willy Tarreau | 2406db4 | 2012-12-09 12:16:43 +0100 | [diff] [blame] | 12486 | that it does not rely on any stored information but on the table's reference |
| 12487 | count (the "use" value which is returned by "show table" on the CLI). This |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12488 | may sometimes be more suited for layer7 tracking. It can be used to tell a |
| 12489 | server how many concurrent connections there are from a given address for |
| 12490 | example. |
Willy Tarreau | 2406db4 | 2012-12-09 12:16:43 +0100 | [diff] [blame] | 12491 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12492 | so_id : integer |
| 12493 | Returns an integer containing the current listening socket's id. It is useful |
| 12494 | in frontends involving many "bind" lines, or to stick all users coming via a |
| 12495 | same socket to the same server. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 12496 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12497 | src : ip |
| 12498 | This is the source IPv4 address of the client of the session. It is of type |
| 12499 | IP and works on both IPv4 and IPv6 tables. On IPv6 tables, IPv4 addresses are |
| 12500 | mapped to their IPv6 equivalent, according to RFC 4291. Note that it is the |
| 12501 | TCP-level source address which is used, and not the address of a client |
| 12502 | behind a proxy. However if the "accept-proxy" bind directive is used, it can |
| 12503 | be the address of a client behind another PROXY-protocol compatible component |
| 12504 | for all rule sets except "tcp-request connection" which sees the real address. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 12505 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 12506 | Example: |
| 12507 | # add an HTTP header in requests with the originating address' country |
| 12508 | http-request set-header X-Country %[src,map_ip(geoip.lst)] |
| 12509 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12510 | src_bytes_in_rate([<table>]) : integer |
| 12511 | Returns the average bytes rate from the incoming connection's source address |
| 12512 | in the current proxy's stick-table or in the designated stick-table, measured |
| 12513 | in amount of bytes over the period configured in the table. If the address is |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12514 | not found, zero is returned. See also sc/sc0/sc1/sc2_bytes_in_rate. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12515 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12516 | src_bytes_out_rate([<table>]) : integer |
| 12517 | Returns the average bytes rate to the incoming connection's source address in |
| 12518 | the current proxy's stick-table or in the designated stick-table, measured in |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12519 | amount of bytes over the period configured in the table. If the address is |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12520 | not found, zero is returned. See also sc/sc0/sc1/sc2_bytes_out_rate. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12521 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12522 | src_clr_gpc0([<table>]) : integer |
| 12523 | Clears the first General Purpose Counter associated to the incoming |
| 12524 | connection's source address in the current proxy's stick-table or in the |
| 12525 | designated stick-table, and returns its previous value. If the address is not |
| 12526 | found, an entry is created and 0 is returned. This is typically used as a |
| 12527 | second ACL in an expression in order to mark a connection when a first ACL |
| 12528 | was verified : |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 12529 | |
| 12530 | # block if 5 consecutive requests continue to come faster than 10 sess |
| 12531 | # per second, and reset the counter as soon as the traffic slows down. |
| 12532 | acl abuse src_http_req_rate gt 10 |
| 12533 | acl kill src_inc_gpc0 gt 5 |
Willy Tarreau | 869948b | 2013-01-04 14:14:57 +0100 | [diff] [blame] | 12534 | acl save src_clr_gpc0 ge 0 |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 12535 | tcp-request connection accept if !abuse save |
| 12536 | tcp-request connection reject if abuse kill |
| 12537 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12538 | src_conn_cnt([<table>]) : integer |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12539 | Returns the cumulated number of connections initiated from the current |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12540 | incoming connection's source address in the current proxy's stick-table or in |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12541 | the designated stick-table. If the address is not found, zero is returned. |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12542 | See also sc/sc0/sc1/sc2_conn_cnt. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12543 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12544 | src_conn_cur([<table>]) : integer |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12545 | Returns the current amount of concurrent connections initiated from the |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12546 | current incoming connection's source address in the current proxy's |
| 12547 | stick-table or in the designated stick-table. If the address is not found, |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12548 | zero is returned. See also sc/sc0/sc1/sc2_conn_cur. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12549 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12550 | src_conn_rate([<table>]) : integer |
| 12551 | Returns the average connection rate from the incoming connection's source |
| 12552 | address in the current proxy's stick-table or in the designated stick-table, |
| 12553 | measured in amount of connections over the period configured in the table. If |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12554 | the address is not found, zero is returned. See also sc/sc0/sc1/sc2_conn_rate. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12555 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12556 | src_get_gpc0([<table>]) : integer |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12557 | Returns the value of the first General Purpose Counter associated to the |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12558 | incoming connection's source address in the current proxy's stick-table or in |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12559 | the designated stick-table. If the address is not found, zero is returned. |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12560 | See also sc/sc0/sc1/sc2_get_gpc0 and src_inc_gpc0. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12561 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 12562 | src_get_gpt0([<table>]) : integer |
| 12563 | Returns the value of the first General Purpose Tag associated to the |
| 12564 | incoming connection's source address in the current proxy's stick-table or in |
| 12565 | the designated stick-table. If the address is not found, zero is returned. |
| 12566 | See also sc/sc0/sc1/sc2_get_gpt0. |
| 12567 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12568 | src_gpc0_rate([<table>]) : integer |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 12569 | Returns the average increment rate of the first General Purpose Counter |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12570 | associated to the incoming connection's source address in the current proxy's |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 12571 | stick-table or in the designated stick-table. It reports the frequency |
| 12572 | which the gpc0 counter was incremented over the configured period. See also |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12573 | sc/sc0/sc1/sc2_gpc0_rate, src_get_gpc0, and sc/sc0/sc1/sc2_inc_gpc0. Note |
| 12574 | that the "gpc0_rate" counter must be stored in the stick-table for a value to |
| 12575 | be returned, as "gpc0" only holds the event count. |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 12576 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12577 | src_http_err_cnt([<table>]) : integer |
| 12578 | Returns the cumulated number of HTTP errors from the incoming connection's |
| 12579 | source address in the current proxy's stick-table or in the designated |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12580 | stick-table. This includes the both request errors and 4xx error responses. |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12581 | See also sc/sc0/sc1/sc2_http_err_cnt. If the address is not found, zero is |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12582 | returned. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12583 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12584 | src_http_err_rate([<table>]) : integer |
| 12585 | Returns the average rate of HTTP errors from the incoming connection's source |
| 12586 | address in the current proxy's stick-table or in the designated stick-table, |
| 12587 | measured in amount of errors over the period configured in the table. This |
| 12588 | includes the both request errors and 4xx error responses. If the address is |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12589 | not found, zero is returned. See also sc/sc0/sc1/sc2_http_err_rate. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12590 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12591 | src_http_req_cnt([<table>]) : integer |
| 12592 | Returns the cumulated number of HTTP requests from the incoming connection's |
| 12593 | source address in the current proxy's stick-table or in the designated stick- |
| 12594 | table. This includes every started request, valid or not. If the address is |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12595 | not found, zero is returned. See also sc/sc0/sc1/sc2_http_req_cnt. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12596 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12597 | src_http_req_rate([<table>]) : integer |
| 12598 | Returns the average rate of HTTP requests from the incoming connection's |
| 12599 | source address in the current proxy's stick-table or in the designated stick- |
| 12600 | table, measured in amount of requests over the period configured in the |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12601 | table. This includes every started request, valid or not. If the address is |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12602 | not found, zero is returned. See also sc/sc0/sc1/sc2_http_req_rate. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12603 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12604 | src_inc_gpc0([<table>]) : integer |
| 12605 | Increments the first General Purpose Counter associated to the incoming |
| 12606 | connection's source address in the current proxy's stick-table or in the |
| 12607 | designated stick-table, and returns its new value. If the address is not |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 12608 | found, an entry is created and 1 is returned. See also sc0/sc2/sc2_inc_gpc0. |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12609 | This is typically used as a second ACL in an expression in order to mark a |
| 12610 | connection when a first ACL was verified : |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12611 | |
| 12612 | acl abuse src_http_req_rate gt 10 |
Willy Tarreau | 869948b | 2013-01-04 14:14:57 +0100 | [diff] [blame] | 12613 | acl kill src_inc_gpc0 gt 0 |
Willy Tarreau | e965652 | 2010-08-17 15:40:09 +0200 | [diff] [blame] | 12614 | tcp-request connection reject if abuse kill |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12615 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12616 | src_kbytes_in([<table>]) : integer |
Willy Tarreau | a01b974 | 2014-07-10 15:29:24 +0200 | [diff] [blame] | 12617 | Returns the total amount of data received from the incoming connection's |
| 12618 | source address in the current proxy's stick-table or in the designated |
| 12619 | stick-table, measured in kilobytes. If the address is not found, zero is |
| 12620 | returned. The test is currently performed on 32-bit integers, which limits |
| 12621 | values to 4 terabytes. See also sc/sc0/sc1/sc2_kbytes_in. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12622 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12623 | src_kbytes_out([<table>]) : integer |
Willy Tarreau | a01b974 | 2014-07-10 15:29:24 +0200 | [diff] [blame] | 12624 | Returns the total amount of data sent to the incoming connection's source |
| 12625 | address in the current proxy's stick-table or in the designated stick-table, |
| 12626 | measured in kilobytes. If the address is not found, zero is returned. The |
| 12627 | test is currently performed on 32-bit integers, which limits values to 4 |
| 12628 | terabytes. See also sc/sc0/sc1/sc2_kbytes_out. |
Willy Tarreau | a975b8f | 2010-06-05 19:13:27 +0200 | [diff] [blame] | 12629 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12630 | src_port : integer |
| 12631 | Returns an integer value corresponding to the TCP source port of the |
| 12632 | connection on the client side, which is the port the client connected from. |
| 12633 | Usage of this function is very limited as modern protocols do not care much |
| 12634 | about source ports nowadays. |
Willy Tarreau | 079ff0a | 2009-03-05 21:34:28 +0100 | [diff] [blame] | 12635 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12636 | src_sess_cnt([<table>]) : integer |
| 12637 | Returns the cumulated number of connections initiated from the incoming |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12638 | connection's source IPv4 address in the current proxy's stick-table or in the |
| 12639 | designated stick-table, that were transformed into sessions, which means that |
| 12640 | they were accepted by "tcp-request" rules. If the address is not found, zero |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12641 | is returned. See also sc/sc0/sc1/sc2_sess_cnt. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12642 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12643 | src_sess_rate([<table>]) : integer |
| 12644 | Returns the average session rate from the incoming connection's source |
| 12645 | address in the current proxy's stick-table or in the designated stick-table, |
| 12646 | measured in amount of sessions over the period configured in the table. A |
| 12647 | session is a connection that went past the early "tcp-request" rules. If the |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 12648 | address is not found, zero is returned. See also sc/sc0/sc1/sc2_sess_rate. |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12649 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12650 | src_updt_conn_cnt([<table>]) : integer |
| 12651 | Creates or updates the entry associated to the incoming connection's source |
| 12652 | address in the current proxy's stick-table or in the designated stick-table. |
| 12653 | This table must be configured to store the "conn_cnt" data type, otherwise |
| 12654 | the match will be ignored. The current count is incremented by one, and the |
| 12655 | expiration timer refreshed. The updated count is returned, so this match |
| 12656 | can't return zero. This was used to reject service abusers based on their |
| 12657 | source address. Note: it is recommended to use the more complete "track-sc*" |
| 12658 | actions in "tcp-request" rules instead. |
Willy Tarreau | a975b8f | 2010-06-05 19:13:27 +0200 | [diff] [blame] | 12659 | |
| 12660 | Example : |
| 12661 | # This frontend limits incoming SSH connections to 3 per 10 second for |
| 12662 | # each source address, and rejects excess connections until a 10 second |
| 12663 | # silence is observed. At most 20 addresses are tracked. |
| 12664 | listen ssh |
| 12665 | bind :22 |
| 12666 | mode tcp |
| 12667 | maxconn 100 |
Willy Tarreau | c9705a1 | 2010-07-27 20:05:50 +0200 | [diff] [blame] | 12668 | stick-table type ip size 20 expire 10s store conn_cnt |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12669 | tcp-request content reject if { src_updt_conn_cnt gt 3 } |
Willy Tarreau | a975b8f | 2010-06-05 19:13:27 +0200 | [diff] [blame] | 12670 | server local 127.0.0.1:22 |
| 12671 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12672 | srv_id : integer |
| 12673 | Returns an integer containing the server's id when processing the response. |
| 12674 | While it's almost only used with ACLs, it may be used for logging or |
| 12675 | debugging. |
Hervé COMMOWICK | daa824e | 2011-08-05 12:09:44 +0200 | [diff] [blame] | 12676 | |
Hervé COMMOWICK | 35ed801 | 2010-12-15 14:04:51 +0100 | [diff] [blame] | 12677 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 12678 | 7.3.4. Fetching samples at Layer 5 |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12679 | ---------------------------------- |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 12680 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12681 | The layer 5 usually describes just the session layer which in haproxy is |
| 12682 | closest to the session once all the connection handshakes are finished, but |
| 12683 | when no content is yet made available. The fetch methods described here are |
| 12684 | usable as low as the "tcp-request content" rule sets unless they require some |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 12685 | future information. Those generally include the results of SSL negotiations. |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 12686 | |
Emeric Brun | 645ae79 | 2014-04-30 14:21:06 +0200 | [diff] [blame] | 12687 | ssl_bc : boolean |
| 12688 | Returns true when the back connection was made via an SSL/TLS transport |
| 12689 | layer and is locally deciphered. This means the outgoing connection was made |
| 12690 | other a server with the "ssl" option. |
| 12691 | |
| 12692 | ssl_bc_alg_keysize : integer |
| 12693 | Returns the symmetric cipher key size supported in bits when the outgoing |
| 12694 | connection was made over an SSL/TLS transport layer. |
| 12695 | |
| 12696 | ssl_bc_cipher : string |
| 12697 | Returns the name of the used cipher when the outgoing connection was made |
| 12698 | over an SSL/TLS transport layer. |
| 12699 | |
| 12700 | ssl_bc_protocol : string |
| 12701 | Returns the name of the used protocol when the outgoing connection was made |
| 12702 | over an SSL/TLS transport layer. |
| 12703 | |
Emeric Brun | b73a9b0 | 2014-04-30 18:49:19 +0200 | [diff] [blame] | 12704 | ssl_bc_unique_id : binary |
Emeric Brun | 645ae79 | 2014-04-30 14:21:06 +0200 | [diff] [blame] | 12705 | When the outgoing connection was made over an SSL/TLS transport layer, |
Emeric Brun | b73a9b0 | 2014-04-30 18:49:19 +0200 | [diff] [blame] | 12706 | returns the TLS unique ID as defined in RFC5929 section 3. The unique id |
| 12707 | can be encoded to base64 using the converter: "ssl_bc_unique_id,base64". |
Emeric Brun | 645ae79 | 2014-04-30 14:21:06 +0200 | [diff] [blame] | 12708 | |
| 12709 | ssl_bc_session_id : binary |
| 12710 | Returns the SSL ID of the back connection when the outgoing connection was |
| 12711 | made over an SSL/TLS transport layer. It is useful to log if we want to know |
| 12712 | if session was reused or not. |
| 12713 | |
| 12714 | ssl_bc_use_keysize : integer |
| 12715 | Returns the symmetric cipher key size used in bits when the outgoing |
| 12716 | connection was made over an SSL/TLS transport layer. |
| 12717 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12718 | ssl_c_ca_err : integer |
| 12719 | When the incoming connection was made over an SSL/TLS transport layer, |
| 12720 | returns the ID of the first error detected during verification of the client |
| 12721 | certificate at depth > 0, or 0 if no error was encountered during this |
| 12722 | verification process. Please refer to your SSL library's documentation to |
| 12723 | find the exhaustive list of error codes. |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 12724 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12725 | ssl_c_ca_err_depth : integer |
| 12726 | When the incoming connection was made over an SSL/TLS transport layer, |
| 12727 | returns the depth in the CA chain of the first error detected during the |
| 12728 | verification of the client certificate. If no error is encountered, 0 is |
| 12729 | returned. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 12730 | |
Emeric Brun | 43e7958 | 2014-10-29 19:03:26 +0100 | [diff] [blame] | 12731 | ssl_c_der : binary |
| 12732 | Returns the DER formatted certificate presented by the client when the |
| 12733 | incoming connection was made over an SSL/TLS transport layer. When used for |
| 12734 | an ACL, the value(s) to match against can be passed in hexadecimal form. |
| 12735 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12736 | ssl_c_err : integer |
| 12737 | When the incoming connection was made over an SSL/TLS transport layer, |
| 12738 | returns the ID of the first error detected during verification at depth 0, or |
| 12739 | 0 if no error was encountered during this verification process. Please refer |
| 12740 | to your SSL library's documentation to find the exhaustive list of error |
| 12741 | codes. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 12742 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12743 | ssl_c_i_dn([<entry>[,<occ>]]) : string |
| 12744 | When the incoming connection was made over an SSL/TLS transport layer, |
| 12745 | returns the full distinguished name of the issuer of the certificate |
| 12746 | presented by the client when no <entry> is specified, or the value of the |
| 12747 | first given entry found from the beginning of the DN. If a positive/negative |
| 12748 | occurrence number is specified as the optional second argument, it returns |
| 12749 | the value of the nth given entry value from the beginning/end of the DN. |
| 12750 | For instance, "ssl_c_i_dn(OU,2)" the second organization unit, and |
| 12751 | "ssl_c_i_dn(CN)" retrieves the common name. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 12752 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12753 | ssl_c_key_alg : string |
| 12754 | Returns the name of the algorithm used to generate the key of the certificate |
| 12755 | presented by the client when the incoming connection was made over an SSL/TLS |
| 12756 | transport layer. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 12757 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12758 | ssl_c_notafter : string |
| 12759 | Returns the end date presented by the client as a formatted string |
| 12760 | YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS |
| 12761 | transport layer. |
Emeric Brun | bede3d0 | 2009-06-30 17:54:00 +0200 | [diff] [blame] | 12762 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12763 | ssl_c_notbefore : string |
| 12764 | Returns the start date presented by the client as a formatted string |
| 12765 | YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS |
| 12766 | transport layer. |
Willy Tarreau | b6672b5 | 2011-12-12 17:23:41 +0100 | [diff] [blame] | 12767 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12768 | ssl_c_s_dn([<entry>[,<occ>]]) : string |
| 12769 | When the incoming connection was made over an SSL/TLS transport layer, |
| 12770 | returns the full distinguished name of the subject of the certificate |
| 12771 | presented by the client when no <entry> is specified, or the value of the |
| 12772 | first given entry found from the beginning of the DN. If a positive/negative |
| 12773 | occurrence number is specified as the optional second argument, it returns |
| 12774 | the value of the nth given entry value from the beginning/end of the DN. |
| 12775 | For instance, "ssl_c_s_dn(OU,2)" the second organization unit, and |
| 12776 | "ssl_c_s_dn(CN)" retrieves the common name. |
Willy Tarreau | b6672b5 | 2011-12-12 17:23:41 +0100 | [diff] [blame] | 12777 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12778 | ssl_c_serial : binary |
| 12779 | Returns the serial of the certificate presented by the client when the |
| 12780 | incoming connection was made over an SSL/TLS transport layer. When used for |
| 12781 | an ACL, the value(s) to match against can be passed in hexadecimal form. |
Emeric Brun | 2525b6b | 2012-10-18 15:59:43 +0200 | [diff] [blame] | 12782 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12783 | ssl_c_sha1 : binary |
| 12784 | Returns the SHA-1 fingerprint of the certificate presented by the client when |
| 12785 | the incoming connection was made over an SSL/TLS transport layer. This can be |
| 12786 | used to stick a client to a server, or to pass this information to a server. |
Willy Tarreau | 2d0caa3 | 2014-07-02 19:01:22 +0200 | [diff] [blame] | 12787 | Note that the output is binary, so if you want to pass that signature to the |
| 12788 | server, you need to encode it in hex or base64, such as in the example below: |
| 12789 | |
| 12790 | http-request set-header X-SSL-Client-SHA1 %[ssl_c_sha1,hex] |
Emeric Brun | 2525b6b | 2012-10-18 15:59:43 +0200 | [diff] [blame] | 12791 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12792 | ssl_c_sig_alg : string |
| 12793 | Returns the name of the algorithm used to sign the certificate presented by |
| 12794 | the client when the incoming connection was made over an SSL/TLS transport |
| 12795 | layer. |
Emeric Brun | 8785589 | 2012-10-17 17:39:35 +0200 | [diff] [blame] | 12796 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12797 | ssl_c_used : boolean |
| 12798 | Returns true if current SSL session uses a client certificate even if current |
| 12799 | connection uses SSL session resumption. See also "ssl_fc_has_crt". |
Emeric Brun | 7f56e74 | 2012-10-19 18:15:40 +0200 | [diff] [blame] | 12800 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12801 | ssl_c_verify : integer |
| 12802 | Returns the verify result error ID when the incoming connection was made over |
| 12803 | an SSL/TLS transport layer, otherwise zero if no error is encountered. Please |
| 12804 | refer to your SSL library's documentation for an exhaustive list of error |
| 12805 | codes. |
Emeric Brun | ce5ad80 | 2012-10-22 14:11:22 +0200 | [diff] [blame] | 12806 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12807 | ssl_c_version : integer |
| 12808 | Returns the version of the certificate presented by the client when the |
| 12809 | incoming connection was made over an SSL/TLS transport layer. |
Emeric Brun | ce5ad80 | 2012-10-22 14:11:22 +0200 | [diff] [blame] | 12810 | |
Emeric Brun | 43e7958 | 2014-10-29 19:03:26 +0100 | [diff] [blame] | 12811 | ssl_f_der : binary |
| 12812 | Returns the DER formatted certificate presented by the frontend when the |
| 12813 | incoming connection was made over an SSL/TLS transport layer. When used for |
| 12814 | an ACL, the value(s) to match against can be passed in hexadecimal form. |
| 12815 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12816 | ssl_f_i_dn([<entry>[,<occ>]]) : string |
| 12817 | When the incoming connection was made over an SSL/TLS transport layer, |
| 12818 | returns the full distinguished name of the issuer of the certificate |
| 12819 | presented by the frontend when no <entry> is specified, or the value of the |
| 12820 | first given entry found from the beginning of the DN. If a positive/negative |
Emeric Brun | 8785589 | 2012-10-17 17:39:35 +0200 | [diff] [blame] | 12821 | occurrence number is specified as the optional second argument, it returns |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12822 | the value of the nth given entry value from the beginning/end of the DN. |
| 12823 | For instance, "ssl_f_i_dn(OU,2)" the second organization unit, and |
| 12824 | "ssl_f_i_dn(CN)" retrieves the common name. |
Emeric Brun | 8785589 | 2012-10-17 17:39:35 +0200 | [diff] [blame] | 12825 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12826 | ssl_f_key_alg : string |
| 12827 | Returns the name of the algorithm used to generate the key of the certificate |
| 12828 | presented by the frontend when the incoming connection was made over an |
| 12829 | SSL/TLS transport layer. |
Emeric Brun | 7f56e74 | 2012-10-19 18:15:40 +0200 | [diff] [blame] | 12830 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12831 | ssl_f_notafter : string |
| 12832 | Returns the end date presented by the frontend as a formatted string |
| 12833 | YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS |
| 12834 | transport layer. |
Emeric Brun | 2525b6b | 2012-10-18 15:59:43 +0200 | [diff] [blame] | 12835 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12836 | ssl_f_notbefore : string |
| 12837 | Returns the start date presented by the frontend as a formatted string |
| 12838 | YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS |
| 12839 | transport layer. |
Emeric Brun | 8785589 | 2012-10-17 17:39:35 +0200 | [diff] [blame] | 12840 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12841 | ssl_f_s_dn([<entry>[,<occ>]]) : string |
| 12842 | When the incoming connection was made over an SSL/TLS transport layer, |
| 12843 | returns the full distinguished name of the subject of the certificate |
| 12844 | presented by the frontend when no <entry> is specified, or the value of the |
| 12845 | first given entry found from the beginning of the DN. If a positive/negative |
| 12846 | occurrence number is specified as the optional second argument, it returns |
| 12847 | the value of the nth given entry value from the beginning/end of the DN. |
| 12848 | For instance, "ssl_f_s_dn(OU,2)" the second organization unit, and |
| 12849 | "ssl_f_s_dn(CN)" retrieves the common name. |
Emeric Brun | ce5ad80 | 2012-10-22 14:11:22 +0200 | [diff] [blame] | 12850 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12851 | ssl_f_serial : binary |
| 12852 | Returns the serial of the certificate presented by the frontend when the |
| 12853 | incoming connection was made over an SSL/TLS transport layer. When used for |
| 12854 | an ACL, the value(s) to match against can be passed in hexadecimal form. |
Emeric Brun | 8785589 | 2012-10-17 17:39:35 +0200 | [diff] [blame] | 12855 | |
Emeric Brun | 55f4fa8 | 2014-04-30 17:11:25 +0200 | [diff] [blame] | 12856 | ssl_f_sha1 : binary |
| 12857 | Returns the SHA-1 fingerprint of the certificate presented by the frontend |
| 12858 | when the incoming connection was made over an SSL/TLS transport layer. This |
| 12859 | can be used to know which certificate was chosen using SNI. |
| 12860 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12861 | ssl_f_sig_alg : string |
| 12862 | Returns the name of the algorithm used to sign the certificate presented by |
| 12863 | the frontend when the incoming connection was made over an SSL/TLS transport |
| 12864 | layer. |
Emeric Brun | 7f56e74 | 2012-10-19 18:15:40 +0200 | [diff] [blame] | 12865 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12866 | ssl_f_version : integer |
| 12867 | Returns the version of the certificate presented by the frontend when the |
| 12868 | incoming connection was made over an SSL/TLS transport layer. |
| 12869 | |
| 12870 | ssl_fc : boolean |
Emeric Brun | 2525b6b | 2012-10-18 15:59:43 +0200 | [diff] [blame] | 12871 | Returns true when the front connection was made via an SSL/TLS transport |
| 12872 | layer and is locally deciphered. This means it has matched a socket declared |
| 12873 | with a "bind" line having the "ssl" option. |
| 12874 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12875 | Example : |
| 12876 | # This passes "X-Proto: https" to servers when client connects over SSL |
| 12877 | listen http-https |
| 12878 | bind :80 |
| 12879 | bind :443 ssl crt /etc/haproxy.pem |
| 12880 | http-request add-header X-Proto https if { ssl_fc } |
| 12881 | |
| 12882 | ssl_fc_alg_keysize : integer |
| 12883 | Returns the symmetric cipher key size supported in bits when the incoming |
| 12884 | connection was made over an SSL/TLS transport layer. |
| 12885 | |
| 12886 | ssl_fc_alpn : string |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 12887 | This extracts the Application Layer Protocol Negotiation field from an |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12888 | incoming connection made via a TLS transport layer and locally deciphered by |
| 12889 | haproxy. The result is a string containing the protocol name advertised by |
| 12890 | the client. The SSL library must have been built with support for TLS |
| 12891 | extensions enabled (check haproxy -vv). Note that the TLS ALPN extension is |
| 12892 | not advertised unless the "alpn" keyword on the "bind" line specifies a |
| 12893 | protocol list. Also, nothing forces the client to pick a protocol from this |
| 12894 | list, any other one may be requested. The TLS ALPN extension is meant to |
| 12895 | replace the TLS NPN extension. See also "ssl_fc_npn". |
| 12896 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12897 | ssl_fc_cipher : string |
| 12898 | Returns the name of the used cipher when the incoming connection was made |
| 12899 | over an SSL/TLS transport layer. |
Willy Tarreau | ab861d3 | 2013-04-02 02:30:41 +0200 | [diff] [blame] | 12900 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12901 | ssl_fc_has_crt : boolean |
Emeric Brun | 2525b6b | 2012-10-18 15:59:43 +0200 | [diff] [blame] | 12902 | Returns true if a client certificate is present in an incoming connection over |
| 12903 | SSL/TLS transport layer. Useful if 'verify' statement is set to 'optional'. |
Emeric Brun | 9143d37 | 2012-12-20 15:44:16 +0100 | [diff] [blame] | 12904 | Note: on SSL session resumption with Session ID or TLS ticket, client |
| 12905 | certificate is not present in the current connection but may be retrieved |
| 12906 | from the cache or the ticket. So prefer "ssl_c_used" if you want to check if |
| 12907 | current SSL session uses a client certificate. |
Emeric Brun | 2525b6b | 2012-10-18 15:59:43 +0200 | [diff] [blame] | 12908 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12909 | ssl_fc_has_sni : boolean |
| 12910 | This checks for the presence of a Server Name Indication TLS extension (SNI) |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 12911 | in an incoming connection was made over an SSL/TLS transport layer. Returns |
| 12912 | true when the incoming connection presents a TLS SNI field. This requires |
| 12913 | that the SSL library is build with support for TLS extensions enabled (check |
| 12914 | haproxy -vv). |
Willy Tarreau | 7875d09 | 2012-09-10 08:20:03 +0200 | [diff] [blame] | 12915 | |
Nenad Merdanovic | 26ea822 | 2015-05-18 02:28:57 +0200 | [diff] [blame] | 12916 | ssl_fc_is_resumed: boolean |
| 12917 | Returns true if the SSL/TLS session has been resumed through the use of |
| 12918 | SSL session cache or TLS tickets. |
| 12919 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12920 | ssl_fc_npn : string |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 12921 | This extracts the Next Protocol Negotiation field from an incoming connection |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12922 | made via a TLS transport layer and locally deciphered by haproxy. The result |
| 12923 | is a string containing the protocol name advertised by the client. The SSL |
| 12924 | library must have been built with support for TLS extensions enabled (check |
| 12925 | haproxy -vv). Note that the TLS NPN extension is not advertised unless the |
| 12926 | "npn" keyword on the "bind" line specifies a protocol list. Also, nothing |
| 12927 | forces the client to pick a protocol from this list, any other one may be |
| 12928 | requested. Please note that the TLS NPN extension was replaced with ALPN. |
Willy Tarreau | a33c654 | 2012-10-15 13:19:06 +0200 | [diff] [blame] | 12929 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12930 | ssl_fc_protocol : string |
| 12931 | Returns the name of the used protocol when the incoming connection was made |
| 12932 | over an SSL/TLS transport layer. |
Willy Tarreau | 7875d09 | 2012-09-10 08:20:03 +0200 | [diff] [blame] | 12933 | |
Emeric Brun | b73a9b0 | 2014-04-30 18:49:19 +0200 | [diff] [blame] | 12934 | ssl_fc_unique_id : binary |
David S | c1ad52e | 2014-04-08 18:48:47 -0400 | [diff] [blame] | 12935 | When the incoming connection was made over an SSL/TLS transport layer, |
Emeric Brun | b73a9b0 | 2014-04-30 18:49:19 +0200 | [diff] [blame] | 12936 | returns the TLS unique ID as defined in RFC5929 section 3. The unique id |
| 12937 | can be encoded to base64 using the converter: "ssl_bc_unique_id,base64". |
David S | c1ad52e | 2014-04-08 18:48:47 -0400 | [diff] [blame] | 12938 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12939 | ssl_fc_session_id : binary |
| 12940 | Returns the SSL ID of the front connection when the incoming connection was |
| 12941 | made over an SSL/TLS transport layer. It is useful to stick a given client to |
| 12942 | a server. It is important to note that some browsers refresh their session ID |
| 12943 | every few minutes. |
Willy Tarreau | 7875d09 | 2012-09-10 08:20:03 +0200 | [diff] [blame] | 12944 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12945 | ssl_fc_sni : string |
| 12946 | This extracts the Server Name Indication TLS extension (SNI) field from an |
| 12947 | incoming connection made via an SSL/TLS transport layer and locally |
| 12948 | deciphered by haproxy. The result (when present) typically is a string |
| 12949 | matching the HTTPS host name (253 chars or less). The SSL library must have |
| 12950 | been built with support for TLS extensions enabled (check haproxy -vv). |
| 12951 | |
| 12952 | This fetch is different from "req_ssl_sni" above in that it applies to the |
| 12953 | connection being deciphered by haproxy and not to SSL contents being blindly |
| 12954 | forwarded. See also "ssl_fc_sni_end" and "ssl_fc_sni_reg" below. This |
Cyril Bonté | 9c1eb1e | 2012-10-09 22:45:34 +0200 | [diff] [blame] | 12955 | requires that the SSL library is build with support for TLS extensions |
| 12956 | enabled (check haproxy -vv). |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 12957 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12958 | ACL derivatives : |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12959 | ssl_fc_sni_end : suffix match |
| 12960 | ssl_fc_sni_reg : regex match |
Emeric Brun | 589fcad | 2012-10-16 14:13:26 +0200 | [diff] [blame] | 12961 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12962 | ssl_fc_use_keysize : integer |
| 12963 | Returns the symmetric cipher key size used in bits when the incoming |
| 12964 | connection was made over an SSL/TLS transport layer. |
Willy Tarreau | b6fb420 | 2008-07-20 11:18:28 +0200 | [diff] [blame] | 12965 | |
Willy Tarreau | b6fb420 | 2008-07-20 11:18:28 +0200 | [diff] [blame] | 12966 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 12967 | 7.3.5. Fetching samples from buffer contents (Layer 6) |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12968 | ------------------------------------------------------ |
Willy Tarreau | b6fb420 | 2008-07-20 11:18:28 +0200 | [diff] [blame] | 12969 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12970 | Fetching samples from buffer contents is a bit different from the previous |
| 12971 | sample fetches above because the sampled data are ephemeral. These data can |
| 12972 | only be used when they're available and will be lost when they're forwarded. |
| 12973 | For this reason, samples fetched from buffer contents during a request cannot |
| 12974 | be used in a response for example. Even while the data are being fetched, they |
| 12975 | can change. Sometimes it is necessary to set some delays or combine multiple |
| 12976 | sample fetch methods to ensure that the expected data are complete and usable, |
| 12977 | for example through TCP request content inspection. Please see the "tcp-request |
| 12978 | content" keyword for more detailed information on the subject. |
Willy Tarreau | 6264477 | 2008-07-16 18:36:06 +0200 | [diff] [blame] | 12979 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12980 | payload(<offset>,<length>) : binary (deprecated) |
| 12981 | This is an alias for "req.payload" when used in the context of a request (eg: |
| 12982 | "stick on", "stick match"), and for "res.payload" when used in the context of |
| 12983 | a response such as in "stick store response". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 12984 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12985 | payload_lv(<offset1>,<length>[,<offset2>]) : binary (deprecated) |
| 12986 | This is an alias for "req.payload_lv" when used in the context of a request |
| 12987 | (eg: "stick on", "stick match"), and for "res.payload_lv" when used in the |
| 12988 | context of a response such as in "stick store response". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 12989 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 12990 | req.len : integer |
| 12991 | req_len : integer (deprecated) |
| 12992 | Returns an integer value corresponding to the number of bytes present in the |
| 12993 | request buffer. This is mostly used in ACL. It is important to understand |
| 12994 | that this test does not return false as long as the buffer is changing. This |
| 12995 | means that a check with equality to zero will almost always immediately match |
| 12996 | at the beginning of the session, while a test for more data will wait for |
| 12997 | that data to come in and return false only when haproxy is certain that no |
| 12998 | more data will come in. This test was designed to be used with TCP request |
| 12999 | content inspection. |
Willy Tarreau | a7ad50c | 2012-04-29 15:39:40 +0200 | [diff] [blame] | 13000 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13001 | req.payload(<offset>,<length>) : binary |
| 13002 | This extracts a binary block of <length> bytes and starting at byte <offset> |
Willy Tarreau | 00f0084 | 2013-08-02 11:07:32 +0200 | [diff] [blame] | 13003 | in the request buffer. As a special case, if the <length> argument is zero, |
| 13004 | the the whole buffer from <offset> to the end is extracted. This can be used |
| 13005 | with ACLs in order to check for the presence of some content in a buffer at |
| 13006 | any location. |
Willy Tarreau | a7ad50c | 2012-04-29 15:39:40 +0200 | [diff] [blame] | 13007 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13008 | ACL alternatives : |
| 13009 | payload(<offset>,<length>) : hex binary match |
Willy Tarreau | a7ad50c | 2012-04-29 15:39:40 +0200 | [diff] [blame] | 13010 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13011 | req.payload_lv(<offset1>,<length>[,<offset2>]) : binary |
| 13012 | This extracts a binary block whose size is specified at <offset1> for <length> |
| 13013 | bytes, and which starts at <offset2> if specified or just after the length in |
| 13014 | the request buffer. The <offset2> parameter also supports relative offsets if |
| 13015 | prepended with a '+' or '-' sign. |
Willy Tarreau | a7ad50c | 2012-04-29 15:39:40 +0200 | [diff] [blame] | 13016 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13017 | ACL alternatives : |
| 13018 | payload_lv(<offset1>,<length>[,<offset2>]) : hex binary match |
Willy Tarreau | a7ad50c | 2012-04-29 15:39:40 +0200 | [diff] [blame] | 13019 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13020 | Example : please consult the example from the "stick store-response" keyword. |
Willy Tarreau | a7ad50c | 2012-04-29 15:39:40 +0200 | [diff] [blame] | 13021 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13022 | req.proto_http : boolean |
| 13023 | req_proto_http : boolean (deprecated) |
| 13024 | Returns true when data in the request buffer look like HTTP and correctly |
| 13025 | parses as such. It is the same parser as the common HTTP request parser which |
| 13026 | is used so there should be no surprises. The test does not match until the |
| 13027 | request is complete, failed or timed out. This test may be used to report the |
| 13028 | protocol in TCP logs, but the biggest use is to block TCP request analysis |
| 13029 | until a complete HTTP request is present in the buffer, for example to track |
| 13030 | a header. |
Willy Tarreau | a7ad50c | 2012-04-29 15:39:40 +0200 | [diff] [blame] | 13031 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13032 | Example: |
| 13033 | # track request counts per "base" (concatenation of Host+URL) |
| 13034 | tcp-request inspect-delay 10s |
| 13035 | tcp-request content reject if !HTTP |
Willy Tarreau | be4a3ef | 2013-06-17 15:04:07 +0200 | [diff] [blame] | 13036 | tcp-request content track-sc0 base table req-rate |
Willy Tarreau | a7ad50c | 2012-04-29 15:39:40 +0200 | [diff] [blame] | 13037 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13038 | req.rdp_cookie([<name>]) : string |
| 13039 | rdp_cookie([<name>]) : string (deprecated) |
| 13040 | When the request buffer looks like the RDP protocol, extracts the RDP cookie |
| 13041 | <name>, or any cookie if unspecified. The parser only checks for the first |
| 13042 | cookie, as illustrated in the RDP protocol specification. The cookie name is |
| 13043 | case insensitive. Generally the "MSTS" cookie name will be used, as it can |
| 13044 | contain the user name of the client connecting to the server if properly |
| 13045 | configured on the client. The "MSTSHASH" cookie is often used as well for |
| 13046 | session stickiness to servers. |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13047 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13048 | This differs from "balance rdp-cookie" in that any balancing algorithm may be |
| 13049 | used and thus the distribution of clients to backend servers is not linked to |
| 13050 | a hash of the RDP cookie. It is envisaged that using a balancing algorithm |
| 13051 | such as "balance roundrobin" or "balance leastconn" will lead to a more even |
| 13052 | distribution of clients to backend servers than the hash used by "balance |
| 13053 | rdp-cookie". |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13054 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13055 | ACL derivatives : |
| 13056 | req_rdp_cookie([<name>]) : exact string match |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13057 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13058 | Example : |
| 13059 | listen tse-farm |
| 13060 | bind 0.0.0.0:3389 |
| 13061 | # wait up to 5s for an RDP cookie in the request |
| 13062 | tcp-request inspect-delay 5s |
| 13063 | tcp-request content accept if RDP_COOKIE |
| 13064 | # apply RDP cookie persistence |
| 13065 | persist rdp-cookie |
| 13066 | # Persist based on the mstshash cookie |
| 13067 | # This is only useful makes sense if |
| 13068 | # balance rdp-cookie is not used |
| 13069 | stick-table type string size 204800 |
| 13070 | stick on req.rdp_cookie(mstshash) |
| 13071 | server srv1 1.1.1.1:3389 |
| 13072 | server srv1 1.1.1.2:3389 |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13073 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13074 | See also : "balance rdp-cookie", "persist rdp-cookie", "tcp-request" and the |
| 13075 | "req_rdp_cookie" ACL. |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13076 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13077 | req.rdp_cookie_cnt([name]) : integer |
| 13078 | rdp_cookie_cnt([name]) : integer (deprecated) |
| 13079 | Tries to parse the request buffer as RDP protocol, then returns an integer |
| 13080 | corresponding to the number of RDP cookies found. If an optional cookie name |
| 13081 | is passed, only cookies matching this name are considered. This is mostly |
| 13082 | used in ACL. |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13083 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13084 | ACL derivatives : |
| 13085 | req_rdp_cookie_cnt([<name>]) : integer match |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13086 | |
Nenad Merdanovic | 5fc7d7e | 2015-07-07 22:00:17 +0200 | [diff] [blame] | 13087 | req.ssl_ec_ext : boolean |
| 13088 | Returns a boolean identifying if client sent the Supported Elliptic Curves |
| 13089 | Extension as defined in RFC4492, section 5.1. within the SSL ClientHello |
| 13090 | message. This can be used to present ECC compatible clients with EC certificate |
| 13091 | and to use RSA for all others, on the same IP address. Note that this only |
| 13092 | applies to raw contents found in the request buffer and not to contents |
| 13093 | deciphered via an SSL data layer, so this will not work with "bind" lines |
| 13094 | having the "ssl" option. |
| 13095 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13096 | req.ssl_hello_type : integer |
| 13097 | req_ssl_hello_type : integer (deprecated) |
| 13098 | Returns an integer value containing the type of the SSL hello message found |
| 13099 | in the request buffer if the buffer contains data that parse as a complete |
| 13100 | SSL (v3 or superior) client hello message. Note that this only applies to raw |
| 13101 | contents found in the request buffer and not to contents deciphered via an |
| 13102 | SSL data layer, so this will not work with "bind" lines having the "ssl" |
| 13103 | option. This is mostly used in ACL to detect presence of an SSL hello message |
| 13104 | that is supposed to contain an SSL session ID usable for stickiness. |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13105 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13106 | req.ssl_sni : string |
| 13107 | req_ssl_sni : string (deprecated) |
| 13108 | Returns a string containing the value of the Server Name TLS extension sent |
| 13109 | by a client in a TLS stream passing through the request buffer if the buffer |
| 13110 | contains data that parse as a complete SSL (v3 or superior) client hello |
| 13111 | message. Note that this only applies to raw contents found in the request |
| 13112 | buffer and not to contents deciphered via an SSL data layer, so this will not |
| 13113 | work with "bind" lines having the "ssl" option. SNI normally contains the |
| 13114 | name of the host the client tries to connect to (for recent browsers). SNI is |
| 13115 | useful for allowing or denying access to certain hosts when SSL/TLS is used |
| 13116 | by the client. This test was designed to be used with TCP request content |
| 13117 | inspection. If content switching is needed, it is recommended to first wait |
| 13118 | for a complete client hello (type 1), like in the example below. See also |
| 13119 | "ssl_fc_sni". |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13120 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13121 | ACL derivatives : |
| 13122 | req_ssl_sni : exact string match |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13123 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13124 | Examples : |
| 13125 | # Wait for a client hello for at most 5 seconds |
| 13126 | tcp-request inspect-delay 5s |
| 13127 | tcp-request content accept if { req_ssl_hello_type 1 } |
| 13128 | use_backend bk_allow if { req_ssl_sni -f allowed_sites } |
| 13129 | default_backend bk_sorry_page |
Willy Tarreau | 04aa6a9 | 2012-04-06 18:57:55 +0200 | [diff] [blame] | 13130 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13131 | res.ssl_hello_type : integer |
| 13132 | rep_ssl_hello_type : integer (deprecated) |
| 13133 | Returns an integer value containing the type of the SSL hello message found |
| 13134 | in the response buffer if the buffer contains data that parses as a complete |
| 13135 | SSL (v3 or superior) hello message. Note that this only applies to raw |
| 13136 | contents found in the response buffer and not to contents deciphered via an |
| 13137 | SSL data layer, so this will not work with "server" lines having the "ssl" |
| 13138 | option. This is mostly used in ACL to detect presence of an SSL hello message |
| 13139 | that is supposed to contain an SSL session ID usable for stickiness. |
Willy Tarreau | 5153936 | 2012-05-08 12:46:28 +0200 | [diff] [blame] | 13140 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13141 | req.ssl_ver : integer |
| 13142 | req_ssl_ver : integer (deprecated) |
| 13143 | Returns an integer value containing the version of the SSL/TLS protocol of a |
| 13144 | stream present in the request buffer. Both SSLv2 hello messages and SSLv3 |
| 13145 | messages are supported. TLSv1 is announced as SSL version 3.1. The value is |
| 13146 | composed of the major version multiplied by 65536, added to the minor |
| 13147 | version. Note that this only applies to raw contents found in the request |
| 13148 | buffer and not to contents deciphered via an SSL data layer, so this will not |
| 13149 | work with "bind" lines having the "ssl" option. The ACL version of the test |
| 13150 | matches against a decimal notation in the form MAJOR.MINOR (eg: 3.1). This |
| 13151 | fetch is mostly used in ACL. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13152 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13153 | ACL derivatives : |
| 13154 | req_ssl_ver : decimal match |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13155 | |
Willy Tarreau | 47e8eba | 2013-09-11 23:28:46 +0200 | [diff] [blame] | 13156 | res.len : integer |
| 13157 | Returns an integer value corresponding to the number of bytes present in the |
| 13158 | response buffer. This is mostly used in ACL. It is important to understand |
| 13159 | that this test does not return false as long as the buffer is changing. This |
| 13160 | means that a check with equality to zero will almost always immediately match |
| 13161 | at the beginning of the session, while a test for more data will wait for |
| 13162 | that data to come in and return false only when haproxy is certain that no |
| 13163 | more data will come in. This test was designed to be used with TCP response |
| 13164 | content inspection. |
| 13165 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13166 | res.payload(<offset>,<length>) : binary |
| 13167 | This extracts a binary block of <length> bytes and starting at byte <offset> |
Willy Tarreau | 00f0084 | 2013-08-02 11:07:32 +0200 | [diff] [blame] | 13168 | in the response buffer. As a special case, if the <length> argument is zero, |
| 13169 | the the whole buffer from <offset> to the end is extracted. This can be used |
| 13170 | with ACLs in order to check for the presence of some content in a buffer at |
| 13171 | any location. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13172 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13173 | res.payload_lv(<offset1>,<length>[,<offset2>]) : binary |
| 13174 | This extracts a binary block whose size is specified at <offset1> for <length> |
| 13175 | bytes, and which starts at <offset2> if specified or just after the length in |
| 13176 | the response buffer. The <offset2> parameter also supports relative offsets |
| 13177 | if prepended with a '+' or '-' sign. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13178 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13179 | Example : please consult the example from the "stick store-response" keyword. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13180 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13181 | wait_end : boolean |
| 13182 | This fetch either returns true when the inspection period is over, or does |
| 13183 | not fetch. It is only used in ACLs, in conjunction with content analysis to |
| 13184 | avoid returning a wrong verdict early. It may also be used to delay some |
| 13185 | actions, such as a delayed reject for some special addresses. Since it either |
| 13186 | stops the rules evaluation or immediately returns true, it is recommended to |
| 13187 | use this acl as the last one in a rule. Please note that the default ACL |
| 13188 | "WAIT_END" is always usable without prior declaration. This test was designed |
| 13189 | to be used with TCP request content inspection. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13190 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13191 | Examples : |
| 13192 | # delay every incoming request by 2 seconds |
| 13193 | tcp-request inspect-delay 2s |
| 13194 | tcp-request content accept if WAIT_END |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13195 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13196 | # don't immediately tell bad guys they are rejected |
| 13197 | tcp-request inspect-delay 10s |
| 13198 | acl goodguys src 10.0.0.0/24 |
| 13199 | acl badguys src 10.0.1.0/24 |
| 13200 | tcp-request content accept if goodguys |
| 13201 | tcp-request content reject if badguys WAIT_END |
| 13202 | tcp-request content reject |
| 13203 | |
| 13204 | |
Thierry FOURNIER | 060762e | 2014-04-23 13:29:15 +0200 | [diff] [blame] | 13205 | 7.3.6. Fetching HTTP samples (Layer 7) |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13206 | -------------------------------------- |
| 13207 | |
| 13208 | It is possible to fetch samples from HTTP contents, requests and responses. |
| 13209 | This application layer is also called layer 7. It is only possible to fetch the |
| 13210 | data in this section when a full HTTP request or response has been parsed from |
| 13211 | its respective request or response buffer. This is always the case with all |
| 13212 | HTTP specific rules and for sections running with "mode http". When using TCP |
| 13213 | content inspection, it may be necessary to support an inspection delay in order |
| 13214 | to let the request or response come in first. These fetches may require a bit |
| 13215 | more CPU resources than the layer 4 ones, but not much since the request and |
| 13216 | response are indexed. |
| 13217 | |
| 13218 | base : string |
| 13219 | This returns the concatenation of the first Host header and the path part of |
| 13220 | the request, which starts at the first slash and ends before the question |
| 13221 | mark. It can be useful in virtual hosted environments to detect URL abuses as |
| 13222 | well as to improve shared caches efficiency. Using this with a limited size |
| 13223 | stick table also allows one to collect statistics about most commonly |
| 13224 | requested objects by host/path. With ACLs it can allow simple content |
| 13225 | switching rules involving the host and the path at the same time, such as |
| 13226 | "www.example.com/favicon.ico". See also "path" and "uri". |
| 13227 | |
| 13228 | ACL derivatives : |
| 13229 | base : exact string match |
| 13230 | base_beg : prefix match |
| 13231 | base_dir : subdir match |
| 13232 | base_dom : domain match |
| 13233 | base_end : suffix match |
| 13234 | base_len : length match |
| 13235 | base_reg : regex match |
| 13236 | base_sub : substring match |
| 13237 | |
| 13238 | base32 : integer |
| 13239 | This returns a 32-bit hash of the value returned by the "base" fetch method |
| 13240 | above. This is useful to track per-URL activity on high traffic sites without |
| 13241 | having to store all URLs. Instead a shorter hash is stored, saving a lot of |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 13242 | memory. The output type is an unsigned integer. The hash function used is |
| 13243 | SDBM with full avalanche on the output. Technically, base32 is exactly equal |
| 13244 | to "base,sdbm(1)". |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13245 | |
| 13246 | base32+src : binary |
| 13247 | This returns the concatenation of the base32 fetch above and the src fetch |
| 13248 | below. The resulting type is of type binary, with a size of 8 or 20 bytes |
| 13249 | depending on the source address family. This can be used to track per-IP, |
| 13250 | per-URL counters. |
| 13251 | |
William Lallemand | 65ad6e1 | 2014-01-31 15:08:02 +0100 | [diff] [blame] | 13252 | capture.req.hdr(<idx>) : string |
| 13253 | This extracts the content of the header captured by the "capture request |
| 13254 | header", idx is the position of the capture keyword in the configuration. |
| 13255 | The first entry is an index of 0. See also: "capture request header". |
| 13256 | |
| 13257 | capture.req.method : string |
| 13258 | This extracts the METHOD of an HTTP request. It can be used in both request |
| 13259 | and response. Unlike "method", it can be used in both request and response |
| 13260 | because it's allocated. |
| 13261 | |
| 13262 | capture.req.uri : string |
| 13263 | This extracts the request's URI, which starts at the first slash and ends |
| 13264 | before the first space in the request (without the host part). Unlike "path" |
| 13265 | and "url", it can be used in both request and response because it's |
| 13266 | allocated. |
| 13267 | |
Willy Tarreau | 3c1b5ec | 2014-04-24 23:41:57 +0200 | [diff] [blame] | 13268 | capture.req.ver : string |
| 13269 | This extracts the request's HTTP version and returns either "HTTP/1.0" or |
| 13270 | "HTTP/1.1". Unlike "req.ver", it can be used in both request, response, and |
| 13271 | logs because it relies on a persistent flag. |
| 13272 | |
William Lallemand | 65ad6e1 | 2014-01-31 15:08:02 +0100 | [diff] [blame] | 13273 | capture.res.hdr(<idx>) : string |
| 13274 | This extracts the content of the header captured by the "capture response |
| 13275 | header", idx is the position of the capture keyword in the configuration. |
| 13276 | The first entry is an index of 0. |
| 13277 | See also: "capture response header" |
| 13278 | |
Willy Tarreau | 3c1b5ec | 2014-04-24 23:41:57 +0200 | [diff] [blame] | 13279 | capture.res.ver : string |
| 13280 | This extracts the response's HTTP version and returns either "HTTP/1.0" or |
| 13281 | "HTTP/1.1". Unlike "res.ver", it can be used in logs because it relies on a |
| 13282 | persistent flag. |
| 13283 | |
Willy Tarreau | a5910cc | 2015-05-02 00:46:08 +0200 | [diff] [blame] | 13284 | req.body : binary |
| 13285 | This returns the HTTP request's available body as a block of data. It |
| 13286 | requires that the request body has been buffered made available using |
| 13287 | "option http-buffer-request". In case of chunked-encoded body, currently only |
| 13288 | the first chunk is analyzed. |
| 13289 | |
Thierry FOURNIER | 9826c77 | 2015-05-20 15:50:54 +0200 | [diff] [blame] | 13290 | req.body_param([<name>) : string |
| 13291 | This fetch assumes that the body of the POST request is url-encoded. The user |
| 13292 | can check if the "content-type" contains the value |
| 13293 | "application/x-www-form-urlencoded". This extracts the first occurrence of the |
| 13294 | parameter <name> in the body, which ends before '&'. The parameter name is |
| 13295 | case-sensitive. If no name is given, any parameter will match, and the first |
| 13296 | one will be returned. The result is a string corresponding to the value of the |
| 13297 | parameter <name> as presented in the request body (no URL decoding is |
| 13298 | performed). Note that the ACL version of this fetch iterates over multiple |
| 13299 | parameters and will iteratively report all parameters values if no name is |
| 13300 | given. |
| 13301 | |
Willy Tarreau | a5910cc | 2015-05-02 00:46:08 +0200 | [diff] [blame] | 13302 | req.body_len : integer |
| 13303 | This returns the length of the HTTP request's available body in bytes. It may |
| 13304 | be lower than the advertised length if the body is larger than the buffer. It |
| 13305 | requires that the request body has been buffered made available using |
| 13306 | "option http-buffer-request". |
| 13307 | |
| 13308 | req.body_size : integer |
| 13309 | This returns the advertised length of the HTTP request's body in bytes. It |
| 13310 | will represent the advertised Content-Length header, or the size of the first |
| 13311 | chunk in case of chunked encoding. In order to parse the chunks, it requires |
| 13312 | that the request body has been buffered made available using |
| 13313 | "option http-buffer-request". |
| 13314 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13315 | req.cook([<name>]) : string |
| 13316 | cook([<name>]) : string (deprecated) |
| 13317 | This extracts the last occurrence of the cookie name <name> on a "Cookie" |
| 13318 | header line from the request, and returns its value as string. If no name is |
| 13319 | specified, the first cookie value is returned. When used with ACLs, all |
| 13320 | matching cookies are evaluated. Spaces around the name and the value are |
| 13321 | ignored as requested by the Cookie header specification (RFC6265). The cookie |
| 13322 | name is case-sensitive. Empty cookies are valid, so an empty cookie may very |
| 13323 | well return an empty value if it is present. Use the "found" match to detect |
| 13324 | presence. Use the res.cook() variant for response cookies sent by the server. |
| 13325 | |
| 13326 | ACL derivatives : |
| 13327 | cook([<name>]) : exact string match |
| 13328 | cook_beg([<name>]) : prefix match |
| 13329 | cook_dir([<name>]) : subdir match |
| 13330 | cook_dom([<name>]) : domain match |
| 13331 | cook_end([<name>]) : suffix match |
| 13332 | cook_len([<name>]) : length match |
| 13333 | cook_reg([<name>]) : regex match |
| 13334 | cook_sub([<name>]) : substring match |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13335 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13336 | req.cook_cnt([<name>]) : integer |
| 13337 | cook_cnt([<name>]) : integer (deprecated) |
| 13338 | Returns an integer value representing the number of occurrences of the cookie |
| 13339 | <name> in the request, or all cookies if <name> is not specified. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13340 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13341 | req.cook_val([<name>]) : integer |
| 13342 | cook_val([<name>]) : integer (deprecated) |
| 13343 | This extracts the last occurrence of the cookie name <name> on a "Cookie" |
| 13344 | header line from the request, and converts its value to an integer which is |
| 13345 | returned. If no name is specified, the first cookie value is returned. When |
| 13346 | used in ACLs, all matching names are iterated over until a value matches. |
Willy Tarreau | 0e69854 | 2011-09-16 08:32:32 +0200 | [diff] [blame] | 13347 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13348 | cookie([<name>]) : string (deprecated) |
| 13349 | This extracts the last occurrence of the cookie name <name> on a "Cookie" |
| 13350 | header line from the request, or a "Set-Cookie" header from the response, and |
| 13351 | returns its value as a string. A typical use is to get multiple clients |
| 13352 | sharing a same profile use the same server. This can be similar to what |
Willy Tarreau | 294d0f0 | 2015-08-10 19:40:12 +0200 | [diff] [blame] | 13353 | "appsession" did with the "request-learn" statement, but with support for |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13354 | multi-peer synchronization and state keeping across restarts. If no name is |
| 13355 | specified, the first cookie value is returned. This fetch should not be used |
| 13356 | anymore and should be replaced by req.cook() or res.cook() instead as it |
| 13357 | ambiguously uses the direction based on the context where it is used. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13358 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13359 | hdr([<name>[,<occ>]]) : string |
| 13360 | This is equivalent to req.hdr() when used on requests, and to res.hdr() when |
| 13361 | used on responses. Please refer to these respective fetches for more details. |
| 13362 | In case of doubt about the fetch direction, please use the explicit ones. |
| 13363 | Note that contrary to the hdr() sample fetch method, the hdr_* ACL keywords |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 13364 | unambiguously apply to the request headers. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13365 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13366 | req.fhdr(<name>[,<occ>]) : string |
| 13367 | This extracts the last occurrence of header <name> in an HTTP request. When |
| 13368 | used from an ACL, all occurrences are iterated over until a match is found. |
| 13369 | Optionally, a specific occurrence might be specified as a position number. |
| 13370 | Positive values indicate a position from the first occurrence, with 1 being |
| 13371 | the first one. Negative values indicate positions relative to the last one, |
| 13372 | with -1 being the last one. It differs from req.hdr() in that any commas |
| 13373 | present in the value are returned and are not used as delimiters. This is |
| 13374 | sometimes useful with headers such as User-Agent. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13375 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13376 | req.fhdr_cnt([<name>]) : integer |
| 13377 | Returns an integer value representing the number of occurrences of request |
| 13378 | header field name <name>, or the total number of header fields if <name> is |
| 13379 | not specified. Contrary to its req.hdr_cnt() cousin, this function returns |
| 13380 | the number of full line headers and does not stop on commas. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13381 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13382 | req.hdr([<name>[,<occ>]]) : string |
| 13383 | This extracts the last occurrence of header <name> in an HTTP request. When |
| 13384 | used from an ACL, all occurrences are iterated over until a match is found. |
| 13385 | Optionally, a specific occurrence might be specified as a position number. |
| 13386 | Positive values indicate a position from the first occurrence, with 1 being |
| 13387 | the first one. Negative values indicate positions relative to the last one, |
| 13388 | with -1 being the last one. A typical use is with the X-Forwarded-For header |
| 13389 | once converted to IP, associated with an IP stick-table. The function |
| 13390 | considers any comma as a delimiter for distinct values. If full-line headers |
| 13391 | are desired instead, use req.fhdr(). Please carefully check RFC2616 to know |
| 13392 | how certain headers are supposed to be parsed. Also, some of them are case |
| 13393 | insensitive (eg: Connection). |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13394 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13395 | ACL derivatives : |
| 13396 | hdr([<name>[,<occ>]]) : exact string match |
| 13397 | hdr_beg([<name>[,<occ>]]) : prefix match |
| 13398 | hdr_dir([<name>[,<occ>]]) : subdir match |
| 13399 | hdr_dom([<name>[,<occ>]]) : domain match |
| 13400 | hdr_end([<name>[,<occ>]]) : suffix match |
| 13401 | hdr_len([<name>[,<occ>]]) : length match |
| 13402 | hdr_reg([<name>[,<occ>]]) : regex match |
| 13403 | hdr_sub([<name>[,<occ>]]) : substring match |
| 13404 | |
| 13405 | req.hdr_cnt([<name>]) : integer |
| 13406 | hdr_cnt([<header>]) : integer (deprecated) |
| 13407 | Returns an integer value representing the number of occurrences of request |
| 13408 | header field name <name>, or the total number of header field values if |
| 13409 | <name> is not specified. It is important to remember that one header line may |
| 13410 | count as several headers if it has several values. The function considers any |
| 13411 | comma as a delimiter for distinct values. If full-line headers are desired |
| 13412 | instead, req.fhdr_cnt() should be used instead. With ACLs, it can be used to |
| 13413 | detect presence, absence or abuse of a specific header, as well as to block |
| 13414 | request smuggling attacks by rejecting requests which contain more than one |
| 13415 | of certain headers. See "req.hdr" for more information on header matching. |
| 13416 | |
| 13417 | req.hdr_ip([<name>[,<occ>]]) : ip |
| 13418 | hdr_ip([<name>[,<occ>]]) : ip (deprecated) |
| 13419 | This extracts the last occurrence of header <name> in an HTTP request, |
| 13420 | converts it to an IPv4 or IPv6 address and returns this address. When used |
| 13421 | with ACLs, all occurrences are checked, and if <name> is omitted, every value |
| 13422 | of every header is checked. Optionally, a specific occurrence might be |
| 13423 | specified as a position number. Positive values indicate a position from the |
| 13424 | first occurrence, with 1 being the first one. Negative values indicate |
| 13425 | positions relative to the last one, with -1 being the last one. A typical use |
| 13426 | is with the X-Forwarded-For and X-Client-IP headers. |
| 13427 | |
| 13428 | req.hdr_val([<name>[,<occ>]]) : integer |
| 13429 | hdr_val([<name>[,<occ>]]) : integer (deprecated) |
| 13430 | This extracts the last occurrence of header <name> in an HTTP request, and |
| 13431 | converts it to an integer value. When used with ACLs, all occurrences are |
| 13432 | checked, and if <name> is omitted, every value of every header is checked. |
| 13433 | Optionally, a specific occurrence might be specified as a position number. |
| 13434 | Positive values indicate a position from the first occurrence, with 1 being |
| 13435 | the first one. Negative values indicate positions relative to the last one, |
| 13436 | with -1 being the last one. A typical use is with the X-Forwarded-For header. |
| 13437 | |
| 13438 | http_auth(<userlist>) : boolean |
| 13439 | Returns a boolean indicating whether the authentication data received from |
| 13440 | the client match a username & password stored in the specified userlist. This |
| 13441 | fetch function is not really useful outside of ACLs. Currently only http |
| 13442 | basic auth is supported. |
| 13443 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 13444 | http_auth_group(<userlist>) : string |
| 13445 | Returns a string corresponding to the user name found in the authentication |
| 13446 | data received from the client if both the user name and password are valid |
| 13447 | according to the specified userlist. The main purpose is to use it in ACLs |
| 13448 | where it is then checked whether the user belongs to any group within a list. |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13449 | This fetch function is not really useful outside of ACLs. Currently only http |
| 13450 | basic auth is supported. |
| 13451 | |
| 13452 | ACL derivatives : |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 13453 | http_auth_group(<userlist>) : group ... |
| 13454 | Returns true when the user extracted from the request and whose password is |
| 13455 | valid according to the specified userlist belongs to at least one of the |
| 13456 | groups. |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13457 | |
| 13458 | http_first_req : boolean |
Willy Tarreau | 7f18e52 | 2010-10-22 20:04:13 +0200 | [diff] [blame] | 13459 | Returns true when the request being processed is the first one of the |
| 13460 | connection. This can be used to add or remove headers that may be missing |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13461 | from some requests when a request is not the first one, or to help grouping |
| 13462 | requests in the logs. |
Willy Tarreau | 7f18e52 | 2010-10-22 20:04:13 +0200 | [diff] [blame] | 13463 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13464 | method : integer + string |
| 13465 | Returns an integer value corresponding to the method in the HTTP request. For |
| 13466 | example, "GET" equals 1 (check sources to establish the matching). Value 9 |
| 13467 | means "other method" and may be converted to a string extracted from the |
| 13468 | stream. This should not be used directly as a sample, this is only meant to |
| 13469 | be used from ACLs, which transparently convert methods from patterns to these |
| 13470 | integer + string values. Some predefined ACL already check for most common |
| 13471 | methods. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13472 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13473 | ACL derivatives : |
| 13474 | method : case insensitive method match |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13475 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13476 | Example : |
| 13477 | # only accept GET and HEAD requests |
| 13478 | acl valid_method method GET HEAD |
| 13479 | http-request deny if ! valid_method |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13480 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13481 | path : string |
| 13482 | This extracts the request's URL path, which starts at the first slash and |
| 13483 | ends before the question mark (without the host part). A typical use is with |
| 13484 | prefetch-capable caches, and with portals which need to aggregate multiple |
| 13485 | information from databases and keep them in caches. Note that with outgoing |
| 13486 | caches, it would be wiser to use "url" instead. With ACLs, it's typically |
| 13487 | used to match exact file names (eg: "/login.php"), or directory parts using |
| 13488 | the derivative forms. See also the "url" and "base" fetch methods. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13489 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13490 | ACL derivatives : |
| 13491 | path : exact string match |
| 13492 | path_beg : prefix match |
| 13493 | path_dir : subdir match |
| 13494 | path_dom : domain match |
| 13495 | path_end : suffix match |
| 13496 | path_len : length match |
| 13497 | path_reg : regex match |
| 13498 | path_sub : substring match |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13499 | |
Willy Tarreau | 49ad95c | 2015-01-19 15:06:26 +0100 | [diff] [blame] | 13500 | query : string |
| 13501 | This extracts the request's query string, which starts after the first |
| 13502 | question mark. If no question mark is present, this fetch returns nothing. If |
| 13503 | a question mark is present but nothing follows, it returns an empty string. |
| 13504 | This means it's possible to easily know whether a query string is present |
| 13505 | using the "found" matching method. This fetch is the completemnt of "path" |
| 13506 | which stops before the question mark. |
| 13507 | |
Willy Tarreau | eb27ec7 | 2015-02-20 13:55:29 +0100 | [diff] [blame] | 13508 | req.hdr_names([<delim>]) : string |
| 13509 | This builds a string made from the concatenation of all header names as they |
| 13510 | appear in the request when the rule is evaluated. The default delimiter is |
| 13511 | the comma (',') but it may be overridden as an optional argument <delim>. In |
| 13512 | this case, only the first character of <delim> is considered. |
| 13513 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13514 | req.ver : string |
| 13515 | req_ver : string (deprecated) |
| 13516 | Returns the version string from the HTTP request, for example "1.1". This can |
| 13517 | be useful for logs, but is mostly there for ACL. Some predefined ACL already |
| 13518 | check for versions 1.0 and 1.1. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13519 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13520 | ACL derivatives : |
| 13521 | req_ver : exact string match |
Willy Tarreau | 0e69854 | 2011-09-16 08:32:32 +0200 | [diff] [blame] | 13522 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13523 | res.comp : boolean |
| 13524 | Returns the boolean "true" value if the response has been compressed by |
| 13525 | HAProxy, otherwise returns boolean "false". This may be used to add |
| 13526 | information in the logs. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13527 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13528 | res.comp_algo : string |
| 13529 | Returns a string containing the name of the algorithm used if the response |
| 13530 | was compressed by HAProxy, for example : "deflate". This may be used to add |
| 13531 | some information in the logs. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13532 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13533 | res.cook([<name>]) : string |
| 13534 | scook([<name>]) : string (deprecated) |
| 13535 | This extracts the last occurrence of the cookie name <name> on a "Set-Cookie" |
| 13536 | header line from the response, and returns its value as string. If no name is |
| 13537 | specified, the first cookie value is returned. |
Willy Tarreau | 0ce3aa0 | 2012-04-25 18:46:33 +0200 | [diff] [blame] | 13538 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13539 | ACL derivatives : |
| 13540 | scook([<name>] : exact string match |
Willy Tarreau | 0ce3aa0 | 2012-04-25 18:46:33 +0200 | [diff] [blame] | 13541 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13542 | res.cook_cnt([<name>]) : integer |
| 13543 | scook_cnt([<name>]) : integer (deprecated) |
| 13544 | Returns an integer value representing the number of occurrences of the cookie |
| 13545 | <name> in the response, or all cookies if <name> is not specified. This is |
| 13546 | mostly useful when combined with ACLs to detect suspicious responses. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13547 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13548 | res.cook_val([<name>]) : integer |
| 13549 | scook_val([<name>]) : integer (deprecated) |
| 13550 | This extracts the last occurrence of the cookie name <name> on a "Set-Cookie" |
| 13551 | header line from the response, and converts its value to an integer which is |
| 13552 | returned. If no name is specified, the first cookie value is returned. |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13553 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13554 | res.fhdr([<name>[,<occ>]]) : string |
| 13555 | This extracts the last occurrence of header <name> in an HTTP response, or of |
| 13556 | the last header if no <name> is specified. Optionally, a specific occurrence |
| 13557 | might be specified as a position number. Positive values indicate a position |
| 13558 | from the first occurrence, with 1 being the first one. Negative values |
| 13559 | indicate positions relative to the last one, with -1 being the last one. It |
| 13560 | differs from res.hdr() in that any commas present in the value are returned |
| 13561 | and are not used as delimiters. If this is not desired, the res.hdr() fetch |
| 13562 | should be used instead. This is sometimes useful with headers such as Date or |
| 13563 | Expires. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13564 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13565 | res.fhdr_cnt([<name>]) : integer |
| 13566 | Returns an integer value representing the number of occurrences of response |
| 13567 | header field name <name>, or the total number of header fields if <name> is |
| 13568 | not specified. Contrary to its res.hdr_cnt() cousin, this function returns |
| 13569 | the number of full line headers and does not stop on commas. If this is not |
| 13570 | desired, the res.hdr_cnt() fetch should be used instead. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13571 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13572 | res.hdr([<name>[,<occ>]]) : string |
| 13573 | shdr([<name>[,<occ>]]) : string (deprecated) |
| 13574 | This extracts the last occurrence of header <name> in an HTTP response, or of |
| 13575 | the last header if no <name> is specified. Optionally, a specific occurrence |
| 13576 | might be specified as a position number. Positive values indicate a position |
| 13577 | from the first occurrence, with 1 being the first one. Negative values |
| 13578 | indicate positions relative to the last one, with -1 being the last one. This |
| 13579 | can be useful to learn some data into a stick-table. The function considers |
| 13580 | any comma as a delimiter for distinct values. If this is not desired, the |
| 13581 | res.fhdr() fetch should be used instead. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13582 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13583 | ACL derivatives : |
| 13584 | shdr([<name>[,<occ>]]) : exact string match |
| 13585 | shdr_beg([<name>[,<occ>]]) : prefix match |
| 13586 | shdr_dir([<name>[,<occ>]]) : subdir match |
| 13587 | shdr_dom([<name>[,<occ>]]) : domain match |
| 13588 | shdr_end([<name>[,<occ>]]) : suffix match |
| 13589 | shdr_len([<name>[,<occ>]]) : length match |
| 13590 | shdr_reg([<name>[,<occ>]]) : regex match |
| 13591 | shdr_sub([<name>[,<occ>]]) : substring match |
| 13592 | |
| 13593 | res.hdr_cnt([<name>]) : integer |
| 13594 | shdr_cnt([<name>]) : integer (deprecated) |
| 13595 | Returns an integer value representing the number of occurrences of response |
| 13596 | header field name <name>, or the total number of header fields if <name> is |
| 13597 | not specified. The function considers any comma as a delimiter for distinct |
| 13598 | values. If this is not desired, the res.fhdr_cnt() fetch should be used |
| 13599 | instead. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13600 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13601 | res.hdr_ip([<name>[,<occ>]]) : ip |
| 13602 | shdr_ip([<name>[,<occ>]]) : ip (deprecated) |
| 13603 | This extracts the last occurrence of header <name> in an HTTP response, |
| 13604 | convert it to an IPv4 or IPv6 address and returns this address. Optionally, a |
| 13605 | specific occurrence might be specified as a position number. Positive values |
| 13606 | indicate a position from the first occurrence, with 1 being the first one. |
| 13607 | Negative values indicate positions relative to the last one, with -1 being |
| 13608 | the last one. This can be useful to learn some data into a stick table. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 13609 | |
Willy Tarreau | eb27ec7 | 2015-02-20 13:55:29 +0100 | [diff] [blame] | 13610 | res.hdr_names([<delim>]) : string |
| 13611 | This builds a string made from the concatenation of all header names as they |
| 13612 | appear in the response when the rule is evaluated. The default delimiter is |
| 13613 | the comma (',') but it may be overridden as an optional argument <delim>. In |
| 13614 | this case, only the first character of <delim> is considered. |
| 13615 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13616 | res.hdr_val([<name>[,<occ>]]) : integer |
| 13617 | shdr_val([<name>[,<occ>]]) : integer (deprecated) |
| 13618 | This extracts the last occurrence of header <name> in an HTTP response, and |
| 13619 | converts it to an integer value. Optionally, a specific occurrence might be |
| 13620 | specified as a position number. Positive values indicate a position from the |
| 13621 | first occurrence, with 1 being the first one. Negative values indicate |
| 13622 | positions relative to the last one, with -1 being the last one. This can be |
| 13623 | useful to learn some data into a stick table. |
Alexandre Cassen | 5eb1a90 | 2007-11-29 15:43:32 +0100 | [diff] [blame] | 13624 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13625 | res.ver : string |
| 13626 | resp_ver : string (deprecated) |
| 13627 | Returns the version string from the HTTP response, for example "1.1". This |
| 13628 | can be useful for logs, but is mostly there for ACL. |
Willy Tarreau | 0e69854 | 2011-09-16 08:32:32 +0200 | [diff] [blame] | 13629 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13630 | ACL derivatives : |
| 13631 | resp_ver : exact string match |
Alexandre Cassen | 5eb1a90 | 2007-11-29 15:43:32 +0100 | [diff] [blame] | 13632 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13633 | set-cookie([<name>]) : string (deprecated) |
| 13634 | This extracts the last occurrence of the cookie name <name> on a "Set-Cookie" |
| 13635 | header line from the response and uses the corresponding value to match. This |
Willy Tarreau | 294d0f0 | 2015-08-10 19:40:12 +0200 | [diff] [blame] | 13636 | can be comparable to what "appsession" did with default options, but with |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13637 | support for multi-peer synchronization and state keeping across restarts. |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 13638 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13639 | This fetch function is deprecated and has been superseded by the "res.cook" |
| 13640 | fetch. This keyword will disappear soon. |
Krzysztof Piotr Oledzki | 6b35ce1 | 2010-02-01 23:35:44 +0100 | [diff] [blame] | 13641 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13642 | status : integer |
| 13643 | Returns an integer containing the HTTP status code in the HTTP response, for |
| 13644 | example, 302. It is mostly used within ACLs and integer ranges, for example, |
| 13645 | to remove any Location header if the response is not a 3xx. |
Willy Tarreau | 25c1ebc | 2012-04-25 16:21:44 +0200 | [diff] [blame] | 13646 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13647 | url : string |
| 13648 | This extracts the request's URL as presented in the request. A typical use is |
| 13649 | with prefetch-capable caches, and with portals which need to aggregate |
| 13650 | multiple information from databases and keep them in caches. With ACLs, using |
| 13651 | "path" is preferred over using "url", because clients may send a full URL as |
| 13652 | is normally done with proxies. The only real use is to match "*" which does |
| 13653 | not match in "path", and for which there is already a predefined ACL. See |
| 13654 | also "path" and "base". |
Willy Tarreau | 25c1ebc | 2012-04-25 16:21:44 +0200 | [diff] [blame] | 13655 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13656 | ACL derivatives : |
| 13657 | url : exact string match |
| 13658 | url_beg : prefix match |
| 13659 | url_dir : subdir match |
| 13660 | url_dom : domain match |
| 13661 | url_end : suffix match |
| 13662 | url_len : length match |
| 13663 | url_reg : regex match |
| 13664 | url_sub : substring match |
Willy Tarreau | 25c1ebc | 2012-04-25 16:21:44 +0200 | [diff] [blame] | 13665 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13666 | url_ip : ip |
| 13667 | This extracts the IP address from the request's URL when the host part is |
| 13668 | presented as an IP address. Its use is very limited. For instance, a |
| 13669 | monitoring system might use this field as an alternative for the source IP in |
| 13670 | order to test what path a given source address would follow, or to force an |
| 13671 | entry in a table for a given source address. With ACLs it can be used to |
| 13672 | restrict access to certain systems through a proxy, for example when combined |
| 13673 | with option "http_proxy". |
Willy Tarreau | 25c1ebc | 2012-04-25 16:21:44 +0200 | [diff] [blame] | 13674 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13675 | url_port : integer |
| 13676 | This extracts the port part from the request's URL. Note that if the port is |
| 13677 | not specified in the request, port 80 is assumed. With ACLs it can be used to |
| 13678 | restrict access to certain systems through a proxy, for example when combined |
| 13679 | with option "http_proxy". |
Willy Tarreau | 25c1ebc | 2012-04-25 16:21:44 +0200 | [diff] [blame] | 13680 | |
Willy Tarreau | 1ede1da | 2015-05-07 16:06:18 +0200 | [diff] [blame] | 13681 | urlp([<name>[,<delim>]]) : string |
| 13682 | url_param([<name>[,<delim>]]) : string |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13683 | This extracts the first occurrence of the parameter <name> in the query |
| 13684 | string, which begins after either '?' or <delim>, and which ends before '&', |
Willy Tarreau | 1ede1da | 2015-05-07 16:06:18 +0200 | [diff] [blame] | 13685 | ';' or <delim>. The parameter name is case-sensitive. If no name is given, |
| 13686 | any parameter will match, and the first one will be returned. The result is |
| 13687 | a string corresponding to the value of the parameter <name> as presented in |
| 13688 | the request (no URL decoding is performed). This can be used for session |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13689 | stickiness based on a client ID, to extract an application cookie passed as a |
| 13690 | URL parameter, or in ACLs to apply some checks. Note that the ACL version of |
Willy Tarreau | 1ede1da | 2015-05-07 16:06:18 +0200 | [diff] [blame] | 13691 | this fetch iterates over multiple parameters and will iteratively report all |
| 13692 | parameters values if no name is given |
Willy Tarreau | 25c1ebc | 2012-04-25 16:21:44 +0200 | [diff] [blame] | 13693 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13694 | ACL derivatives : |
| 13695 | urlp(<name>[,<delim>]) : exact string match |
| 13696 | urlp_beg(<name>[,<delim>]) : prefix match |
| 13697 | urlp_dir(<name>[,<delim>]) : subdir match |
| 13698 | urlp_dom(<name>[,<delim>]) : domain match |
| 13699 | urlp_end(<name>[,<delim>]) : suffix match |
| 13700 | urlp_len(<name>[,<delim>]) : length match |
| 13701 | urlp_reg(<name>[,<delim>]) : regex match |
| 13702 | urlp_sub(<name>[,<delim>]) : substring match |
Willy Tarreau | 25c1ebc | 2012-04-25 16:21:44 +0200 | [diff] [blame] | 13703 | |
Willy Tarreau | 25c1ebc | 2012-04-25 16:21:44 +0200 | [diff] [blame] | 13704 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13705 | Example : |
| 13706 | # match http://example.com/foo?PHPSESSIONID=some_id |
| 13707 | stick on urlp(PHPSESSIONID) |
| 13708 | # match http://example.com/foo;JSESSIONID=some_id |
| 13709 | stick on urlp(JSESSIONID,;) |
Willy Tarreau | 25c1ebc | 2012-04-25 16:21:44 +0200 | [diff] [blame] | 13710 | |
Willy Tarreau | 1ede1da | 2015-05-07 16:06:18 +0200 | [diff] [blame] | 13711 | urlp_val([<name>[,<delim>])] : integer |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13712 | See "urlp" above. This one extracts the URL parameter <name> in the request |
| 13713 | and converts it to an integer value. This can be used for session stickiness |
| 13714 | based on a user ID for example, or with ACLs to match a page number or price. |
Willy Tarreau | a9fddca | 2012-07-31 07:51:48 +0200 | [diff] [blame] | 13715 | |
Willy Tarreau | 198a744 | 2008-01-17 12:05:32 +0100 | [diff] [blame] | 13716 | |
Willy Tarreau | 74ca504 | 2013-06-11 23:12:07 +0200 | [diff] [blame] | 13717 | 7.4. Pre-defined ACLs |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13718 | --------------------- |
Willy Tarreau | ced2701 | 2008-01-17 20:35:34 +0100 | [diff] [blame] | 13719 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13720 | Some predefined ACLs are hard-coded so that they do not have to be declared in |
| 13721 | every frontend which needs them. They all have their names in upper case in |
Patrick Mézard | 2382ad6 | 2010-05-09 10:43:32 +0200 | [diff] [blame] | 13722 | order to avoid confusion. Their equivalence is provided below. |
Willy Tarreau | ced2701 | 2008-01-17 20:35:34 +0100 | [diff] [blame] | 13723 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13724 | ACL name Equivalent to Usage |
| 13725 | ---------------+-----------------------------+--------------------------------- |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13726 | FALSE always_false never match |
Willy Tarreau | 2492d5b | 2009-07-11 00:06:00 +0200 | [diff] [blame] | 13727 | HTTP req_proto_http match if protocol is valid HTTP |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13728 | HTTP_1.0 req_ver 1.0 match HTTP version 1.0 |
| 13729 | HTTP_1.1 req_ver 1.1 match HTTP version 1.1 |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13730 | HTTP_CONTENT hdr_val(content-length) gt 0 match an existing content-length |
| 13731 | HTTP_URL_ABS url_reg ^[^/:]*:// match absolute URL with scheme |
| 13732 | HTTP_URL_SLASH url_beg / match URL beginning with "/" |
| 13733 | HTTP_URL_STAR url * match URL equal to "*" |
| 13734 | LOCALHOST src 127.0.0.1/8 match connection from local host |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13735 | METH_CONNECT method CONNECT match HTTP CONNECT method |
| 13736 | METH_GET method GET HEAD match HTTP GET or HEAD method |
| 13737 | METH_HEAD method HEAD match HTTP HEAD method |
| 13738 | METH_OPTIONS method OPTIONS match HTTP OPTIONS method |
| 13739 | METH_POST method POST match HTTP POST method |
| 13740 | METH_TRACE method TRACE match HTTP TRACE method |
Emeric Brun | bede3d0 | 2009-06-30 17:54:00 +0200 | [diff] [blame] | 13741 | RDP_COOKIE req_rdp_cookie_cnt gt 0 match presence of an RDP cookie |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13742 | REQ_CONTENT req_len gt 0 match data in the request buffer |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 13743 | TRUE always_true always match |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13744 | WAIT_END wait_end wait for end of content analysis |
| 13745 | ---------------+-----------------------------+--------------------------------- |
Willy Tarreau | ced2701 | 2008-01-17 20:35:34 +0100 | [diff] [blame] | 13746 | |
Willy Tarreau | b937b7e | 2010-01-12 15:27:54 +0100 | [diff] [blame] | 13747 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13748 | 8. Logging |
| 13749 | ---------- |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 13750 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13751 | One of HAProxy's strong points certainly lies is its precise logs. It probably |
| 13752 | provides the finest level of information available for such a product, which is |
| 13753 | very important for troubleshooting complex environments. Standard information |
| 13754 | provided in logs include client ports, TCP/HTTP state timers, precise session |
| 13755 | state at termination and precise termination cause, information about decisions |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 13756 | to direct traffic to a server, and of course the ability to capture arbitrary |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13757 | headers. |
| 13758 | |
| 13759 | In order to improve administrators reactivity, it offers a great transparency |
| 13760 | about encountered problems, both internal and external, and it is possible to |
| 13761 | send logs to different sources at the same time with different level filters : |
| 13762 | |
| 13763 | - global process-level logs (system errors, start/stop, etc..) |
| 13764 | - per-instance system and internal errors (lack of resource, bugs, ...) |
| 13765 | - per-instance external troubles (servers up/down, max connections) |
| 13766 | - per-instance activity (client connections), either at the establishment or |
| 13767 | at the termination. |
Jim Freeman | 9e8714b | 2015-05-26 09:16:34 -0600 | [diff] [blame] | 13768 | - per-request control of log-level, eg: |
| 13769 | http-request set-log-level silent if sensitive_request |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13770 | |
| 13771 | The ability to distribute different levels of logs to different log servers |
| 13772 | allow several production teams to interact and to fix their problems as soon |
| 13773 | as possible. For example, the system team might monitor system-wide errors, |
| 13774 | while the application team might be monitoring the up/down for their servers in |
| 13775 | real time, and the security team might analyze the activity logs with one hour |
| 13776 | delay. |
| 13777 | |
| 13778 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13779 | 8.1. Log levels |
| 13780 | --------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13781 | |
Simon Horman | df791f5 | 2011-05-29 15:01:10 +0900 | [diff] [blame] | 13782 | TCP and HTTP connections can be logged with information such as the date, time, |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13783 | source IP address, destination address, connection duration, response times, |
Simon Horman | df791f5 | 2011-05-29 15:01:10 +0900 | [diff] [blame] | 13784 | HTTP request, HTTP return code, number of bytes transmitted, conditions |
| 13785 | in which the session ended, and even exchanged cookies values. For example |
| 13786 | track a particular user's problems. All messages may be sent to up to two |
| 13787 | syslog servers. Check the "log" keyword in section 4.2 for more information |
| 13788 | about log facilities. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13789 | |
| 13790 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13791 | 8.2. Log formats |
| 13792 | ---------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13793 | |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 13794 | HAProxy supports 5 log formats. Several fields are common between these formats |
Simon Horman | df791f5 | 2011-05-29 15:01:10 +0900 | [diff] [blame] | 13795 | and will be detailed in the following sections. A few of them may vary |
| 13796 | slightly with the configuration, due to indicators specific to certain |
| 13797 | options. The supported formats are as follows : |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13798 | |
| 13799 | - the default format, which is very basic and very rarely used. It only |
| 13800 | provides very basic information about the incoming connection at the moment |
| 13801 | it is accepted : source IP:port, destination IP:port, and frontend-name. |
| 13802 | This mode will eventually disappear so it will not be described to great |
| 13803 | extents. |
| 13804 | |
| 13805 | - the TCP format, which is more advanced. This format is enabled when "option |
| 13806 | tcplog" is set on the frontend. HAProxy will then usually wait for the |
| 13807 | connection to terminate before logging. This format provides much richer |
| 13808 | information, such as timers, connection counts, queue size, etc... This |
| 13809 | format is recommended for pure TCP proxies. |
| 13810 | |
| 13811 | - the HTTP format, which is the most advanced for HTTP proxying. This format |
| 13812 | is enabled when "option httplog" is set on the frontend. It provides the |
| 13813 | same information as the TCP format with some HTTP-specific fields such as |
| 13814 | the request, the status code, and captures of headers and cookies. This |
| 13815 | format is recommended for HTTP proxies. |
| 13816 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 13817 | - the CLF HTTP format, which is equivalent to the HTTP format, but with the |
| 13818 | fields arranged in the same order as the CLF format. In this mode, all |
| 13819 | timers, captures, flags, etc... appear one per field after the end of the |
| 13820 | common fields, in the same order they appear in the standard HTTP format. |
| 13821 | |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 13822 | - the custom log format, allows you to make your own log line. |
| 13823 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13824 | Next sections will go deeper into details for each of these formats. Format |
| 13825 | specification will be performed on a "field" basis. Unless stated otherwise, a |
| 13826 | field is a portion of text delimited by any number of spaces. Since syslog |
| 13827 | servers are susceptible of inserting fields at the beginning of a line, it is |
| 13828 | always assumed that the first field is the one containing the process name and |
| 13829 | identifier. |
| 13830 | |
| 13831 | Note : Since log lines may be quite long, the log examples in sections below |
| 13832 | might be broken into multiple lines. The example log lines will be |
| 13833 | prefixed with 3 closing angle brackets ('>>>') and each time a log is |
| 13834 | broken into multiple lines, each non-final line will end with a |
| 13835 | backslash ('\') and the next line will start indented by two characters. |
| 13836 | |
| 13837 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13838 | 8.2.1. Default log format |
| 13839 | ------------------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13840 | |
| 13841 | This format is used when no specific option is set. The log is emitted as soon |
| 13842 | as the connection is accepted. One should note that this currently is the only |
| 13843 | format which logs the request's destination IP and ports. |
| 13844 | |
| 13845 | Example : |
| 13846 | listen www |
| 13847 | mode http |
| 13848 | log global |
| 13849 | server srv1 127.0.0.1:8000 |
| 13850 | |
| 13851 | >>> Feb 6 12:12:09 localhost \ |
| 13852 | haproxy[14385]: Connect from 10.0.1.2:33312 to 10.0.3.31:8012 \ |
| 13853 | (www/HTTP) |
| 13854 | |
| 13855 | Field Format Extract from the example above |
| 13856 | 1 process_name '[' pid ']:' haproxy[14385]: |
| 13857 | 2 'Connect from' Connect from |
| 13858 | 3 source_ip ':' source_port 10.0.1.2:33312 |
| 13859 | 4 'to' to |
| 13860 | 5 destination_ip ':' destination_port 10.0.3.31:8012 |
| 13861 | 6 '(' frontend_name '/' mode ')' (www/HTTP) |
| 13862 | |
| 13863 | Detailed fields description : |
| 13864 | - "source_ip" is the IP address of the client which initiated the connection. |
| 13865 | - "source_port" is the TCP port of the client which initiated the connection. |
| 13866 | - "destination_ip" is the IP address the client connected to. |
| 13867 | - "destination_port" is the TCP port the client connected to. |
| 13868 | - "frontend_name" is the name of the frontend (or listener) which received |
| 13869 | and processed the connection. |
| 13870 | - "mode is the mode the frontend is operating (TCP or HTTP). |
| 13871 | |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 13872 | In case of a UNIX socket, the source and destination addresses are marked as |
| 13873 | "unix:" and the ports reflect the internal ID of the socket which accepted the |
| 13874 | connection (the same ID as reported in the stats). |
| 13875 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13876 | It is advised not to use this deprecated format for newer installations as it |
| 13877 | will eventually disappear. |
| 13878 | |
| 13879 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13880 | 8.2.2. TCP log format |
| 13881 | --------------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13882 | |
| 13883 | The TCP format is used when "option tcplog" is specified in the frontend, and |
| 13884 | is the recommended format for pure TCP proxies. It provides a lot of precious |
| 13885 | information for troubleshooting. Since this format includes timers and byte |
| 13886 | counts, the log is normally emitted at the end of the session. It can be |
| 13887 | emitted earlier if "option logasap" is specified, which makes sense in most |
| 13888 | environments with long sessions such as remote terminals. Sessions which match |
| 13889 | the "monitor" rules are never logged. It is also possible not to emit logs for |
| 13890 | sessions for which no data were exchanged between the client and the server, by |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 13891 | specifying "option dontlognull" in the frontend. Successful connections will |
| 13892 | not be logged if "option dontlog-normal" is specified in the frontend. A few |
| 13893 | fields may slightly vary depending on some configuration options, those are |
| 13894 | marked with a star ('*') after the field name below. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13895 | |
| 13896 | Example : |
| 13897 | frontend fnt |
| 13898 | mode tcp |
| 13899 | option tcplog |
| 13900 | log global |
| 13901 | default_backend bck |
| 13902 | |
| 13903 | backend bck |
| 13904 | server srv1 127.0.0.1:8000 |
| 13905 | |
| 13906 | >>> Feb 6 12:12:56 localhost \ |
| 13907 | haproxy[14387]: 10.0.1.2:33313 [06/Feb/2009:12:12:51.443] fnt \ |
| 13908 | bck/srv1 0/0/5007 212 -- 0/0/0/0/3 0/0 |
| 13909 | |
| 13910 | Field Format Extract from the example above |
| 13911 | 1 process_name '[' pid ']:' haproxy[14387]: |
| 13912 | 2 client_ip ':' client_port 10.0.1.2:33313 |
| 13913 | 3 '[' accept_date ']' [06/Feb/2009:12:12:51.443] |
| 13914 | 4 frontend_name fnt |
| 13915 | 5 backend_name '/' server_name bck/srv1 |
| 13916 | 6 Tw '/' Tc '/' Tt* 0/0/5007 |
| 13917 | 7 bytes_read* 212 |
| 13918 | 8 termination_state -- |
| 13919 | 9 actconn '/' feconn '/' beconn '/' srv_conn '/' retries* 0/0/0/0/3 |
| 13920 | 10 srv_queue '/' backend_queue 0/0 |
| 13921 | |
| 13922 | Detailed fields description : |
| 13923 | - "client_ip" is the IP address of the client which initiated the TCP |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 13924 | connection to haproxy. If the connection was accepted on a UNIX socket |
| 13925 | instead, the IP address would be replaced with the word "unix". Note that |
| 13926 | when the connection is accepted on a socket configured with "accept-proxy" |
| 13927 | and the PROXY protocol is correctly used, then the logs will reflect the |
| 13928 | forwarded connection's information. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13929 | |
| 13930 | - "client_port" is the TCP port of the client which initiated the connection. |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 13931 | If the connection was accepted on a UNIX socket instead, the port would be |
| 13932 | replaced with the ID of the accepting socket, which is also reported in the |
| 13933 | stats interface. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13934 | |
| 13935 | - "accept_date" is the exact date when the connection was received by haproxy |
| 13936 | (which might be very slightly different from the date observed on the |
| 13937 | network if there was some queuing in the system's backlog). This is usually |
| 13938 | the same date which may appear in any upstream firewall's log. |
| 13939 | |
| 13940 | - "frontend_name" is the name of the frontend (or listener) which received |
| 13941 | and processed the connection. |
| 13942 | |
| 13943 | - "backend_name" is the name of the backend (or listener) which was selected |
| 13944 | to manage the connection to the server. This will be the same as the |
| 13945 | frontend if no switching rule has been applied, which is common for TCP |
| 13946 | applications. |
| 13947 | |
| 13948 | - "server_name" is the name of the last server to which the connection was |
| 13949 | sent, which might differ from the first one if there were connection errors |
| 13950 | and a redispatch occurred. Note that this server belongs to the backend |
| 13951 | which processed the request. If the connection was aborted before reaching |
| 13952 | a server, "<NOSRV>" is indicated instead of a server name. |
| 13953 | |
| 13954 | - "Tw" is the total time in milliseconds spent waiting in the various queues. |
| 13955 | It can be "-1" if the connection was aborted before reaching the queue. |
| 13956 | See "Timers" below for more details. |
| 13957 | |
| 13958 | - "Tc" is the total time in milliseconds spent waiting for the connection to |
| 13959 | establish to the final server, including retries. It can be "-1" if the |
| 13960 | connection was aborted before a connection could be established. See |
| 13961 | "Timers" below for more details. |
| 13962 | |
| 13963 | - "Tt" is the total time in milliseconds elapsed between the accept and the |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 13964 | last close. It covers all possible processing. There is one exception, if |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13965 | "option logasap" was specified, then the time counting stops at the moment |
| 13966 | the log is emitted. In this case, a '+' sign is prepended before the value, |
| 13967 | indicating that the final one will be larger. See "Timers" below for more |
| 13968 | details. |
| 13969 | |
| 13970 | - "bytes_read" is the total number of bytes transmitted from the server to |
| 13971 | the client when the log is emitted. If "option logasap" is specified, the |
| 13972 | this value will be prefixed with a '+' sign indicating that the final one |
| 13973 | may be larger. Please note that this value is a 64-bit counter, so log |
| 13974 | analysis tools must be able to handle it without overflowing. |
| 13975 | |
| 13976 | - "termination_state" is the condition the session was in when the session |
| 13977 | ended. This indicates the session state, which side caused the end of |
| 13978 | session to happen, and for what reason (timeout, error, ...). The normal |
| 13979 | flags should be "--", indicating the session was closed by either end with |
| 13980 | no data remaining in buffers. See below "Session state at disconnection" |
| 13981 | for more details. |
| 13982 | |
| 13983 | - "actconn" is the total number of concurrent connections on the process when |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 13984 | the session was logged. It is useful to detect when some per-process system |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13985 | limits have been reached. For instance, if actconn is close to 512 when |
| 13986 | multiple connection errors occur, chances are high that the system limits |
| 13987 | the process to use a maximum of 1024 file descriptors and that all of them |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 13988 | are used. See section 3 "Global parameters" to find how to tune the system. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 13989 | |
| 13990 | - "feconn" is the total number of concurrent connections on the frontend when |
| 13991 | the session was logged. It is useful to estimate the amount of resource |
| 13992 | required to sustain high loads, and to detect when the frontend's "maxconn" |
| 13993 | has been reached. Most often when this value increases by huge jumps, it is |
| 13994 | because there is congestion on the backend servers, but sometimes it can be |
| 13995 | caused by a denial of service attack. |
| 13996 | |
| 13997 | - "beconn" is the total number of concurrent connections handled by the |
| 13998 | backend when the session was logged. It includes the total number of |
| 13999 | concurrent connections active on servers as well as the number of |
| 14000 | connections pending in queues. It is useful to estimate the amount of |
| 14001 | additional servers needed to support high loads for a given application. |
| 14002 | Most often when this value increases by huge jumps, it is because there is |
| 14003 | congestion on the backend servers, but sometimes it can be caused by a |
| 14004 | denial of service attack. |
| 14005 | |
| 14006 | - "srv_conn" is the total number of concurrent connections still active on |
| 14007 | the server when the session was logged. It can never exceed the server's |
| 14008 | configured "maxconn" parameter. If this value is very often close or equal |
| 14009 | to the server's "maxconn", it means that traffic regulation is involved a |
| 14010 | lot, meaning that either the server's maxconn value is too low, or that |
| 14011 | there aren't enough servers to process the load with an optimal response |
| 14012 | time. When only one of the server's "srv_conn" is high, it usually means |
| 14013 | that this server has some trouble causing the connections to take longer to |
| 14014 | be processed than on other servers. |
| 14015 | |
| 14016 | - "retries" is the number of connection retries experienced by this session |
| 14017 | when trying to connect to the server. It must normally be zero, unless a |
| 14018 | server is being stopped at the same moment the connection was attempted. |
| 14019 | Frequent retries generally indicate either a network problem between |
| 14020 | haproxy and the server, or a misconfigured system backlog on the server |
| 14021 | preventing new connections from being queued. This field may optionally be |
| 14022 | prefixed with a '+' sign, indicating that the session has experienced a |
| 14023 | redispatch after the maximal retry count has been reached on the initial |
| 14024 | server. In this case, the server name appearing in the log is the one the |
| 14025 | connection was redispatched to, and not the first one, though both may |
| 14026 | sometimes be the same in case of hashing for instance. So as a general rule |
| 14027 | of thumb, when a '+' is present in front of the retry count, this count |
| 14028 | should not be attributed to the logged server. |
| 14029 | |
| 14030 | - "srv_queue" is the total number of requests which were processed before |
| 14031 | this one in the server queue. It is zero when the request has not gone |
| 14032 | through the server queue. It makes it possible to estimate the approximate |
| 14033 | server's response time by dividing the time spent in queue by the number of |
| 14034 | requests in the queue. It is worth noting that if a session experiences a |
| 14035 | redispatch and passes through two server queues, their positions will be |
| 14036 | cumulated. A request should not pass through both the server queue and the |
| 14037 | backend queue unless a redispatch occurs. |
| 14038 | |
| 14039 | - "backend_queue" is the total number of requests which were processed before |
| 14040 | this one in the backend's global queue. It is zero when the request has not |
| 14041 | gone through the global queue. It makes it possible to estimate the average |
| 14042 | queue length, which easily translates into a number of missing servers when |
| 14043 | divided by a server's "maxconn" parameter. It is worth noting that if a |
| 14044 | session experiences a redispatch, it may pass twice in the backend's queue, |
| 14045 | and then both positions will be cumulated. A request should not pass |
| 14046 | through both the server queue and the backend queue unless a redispatch |
| 14047 | occurs. |
| 14048 | |
| 14049 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 14050 | 8.2.3. HTTP log format |
| 14051 | ---------------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14052 | |
| 14053 | The HTTP format is the most complete and the best suited for HTTP proxies. It |
| 14054 | is enabled by when "option httplog" is specified in the frontend. It provides |
| 14055 | the same level of information as the TCP format with additional features which |
| 14056 | are specific to the HTTP protocol. Just like the TCP format, the log is usually |
| 14057 | emitted at the end of the session, unless "option logasap" is specified, which |
| 14058 | generally only makes sense for download sites. A session which matches the |
| 14059 | "monitor" rules will never logged. It is also possible not to log sessions for |
| 14060 | which no data were sent by the client by specifying "option dontlognull" in the |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 14061 | frontend. Successful connections will not be logged if "option dontlog-normal" |
| 14062 | is specified in the frontend. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14063 | |
| 14064 | Most fields are shared with the TCP log, some being different. A few fields may |
| 14065 | slightly vary depending on some configuration options. Those ones are marked |
| 14066 | with a star ('*') after the field name below. |
| 14067 | |
| 14068 | Example : |
| 14069 | frontend http-in |
| 14070 | mode http |
| 14071 | option httplog |
| 14072 | log global |
| 14073 | default_backend bck |
| 14074 | |
| 14075 | backend static |
| 14076 | server srv1 127.0.0.1:8000 |
| 14077 | |
| 14078 | >>> Feb 6 12:14:14 localhost \ |
| 14079 | haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in \ |
| 14080 | static/srv1 10/0/30/69/109 200 2750 - - ---- 1/1/1/1/0 0/0 {1wt.eu} \ |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 14081 | {} "GET /index.html HTTP/1.1" |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14082 | |
| 14083 | Field Format Extract from the example above |
| 14084 | 1 process_name '[' pid ']:' haproxy[14389]: |
| 14085 | 2 client_ip ':' client_port 10.0.1.2:33317 |
| 14086 | 3 '[' accept_date ']' [06/Feb/2009:12:14:14.655] |
| 14087 | 4 frontend_name http-in |
| 14088 | 5 backend_name '/' server_name static/srv1 |
| 14089 | 6 Tq '/' Tw '/' Tc '/' Tr '/' Tt* 10/0/30/69/109 |
| 14090 | 7 status_code 200 |
| 14091 | 8 bytes_read* 2750 |
| 14092 | 9 captured_request_cookie - |
| 14093 | 10 captured_response_cookie - |
| 14094 | 11 termination_state ---- |
| 14095 | 12 actconn '/' feconn '/' beconn '/' srv_conn '/' retries* 1/1/1/1/0 |
| 14096 | 13 srv_queue '/' backend_queue 0/0 |
| 14097 | 14 '{' captured_request_headers* '}' {haproxy.1wt.eu} |
| 14098 | 15 '{' captured_response_headers* '}' {} |
| 14099 | 16 '"' http_request '"' "GET /index.html HTTP/1.1" |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 14100 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14101 | |
| 14102 | Detailed fields description : |
| 14103 | - "client_ip" is the IP address of the client which initiated the TCP |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 14104 | connection to haproxy. If the connection was accepted on a UNIX socket |
| 14105 | instead, the IP address would be replaced with the word "unix". Note that |
| 14106 | when the connection is accepted on a socket configured with "accept-proxy" |
| 14107 | and the PROXY protocol is correctly used, then the logs will reflect the |
| 14108 | forwarded connection's information. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14109 | |
| 14110 | - "client_port" is the TCP port of the client which initiated the connection. |
Willy Tarreau | ceb24bc | 2010-11-09 12:46:41 +0100 | [diff] [blame] | 14111 | If the connection was accepted on a UNIX socket instead, the port would be |
| 14112 | replaced with the ID of the accepting socket, which is also reported in the |
| 14113 | stats interface. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14114 | |
| 14115 | - "accept_date" is the exact date when the TCP connection was received by |
| 14116 | haproxy (which might be very slightly different from the date observed on |
| 14117 | the network if there was some queuing in the system's backlog). This is |
| 14118 | usually the same date which may appear in any upstream firewall's log. This |
| 14119 | does not depend on the fact that the client has sent the request or not. |
| 14120 | |
| 14121 | - "frontend_name" is the name of the frontend (or listener) which received |
| 14122 | and processed the connection. |
| 14123 | |
| 14124 | - "backend_name" is the name of the backend (or listener) which was selected |
| 14125 | to manage the connection to the server. This will be the same as the |
| 14126 | frontend if no switching rule has been applied. |
| 14127 | |
| 14128 | - "server_name" is the name of the last server to which the connection was |
| 14129 | sent, which might differ from the first one if there were connection errors |
| 14130 | and a redispatch occurred. Note that this server belongs to the backend |
| 14131 | which processed the request. If the request was aborted before reaching a |
| 14132 | server, "<NOSRV>" is indicated instead of a server name. If the request was |
| 14133 | intercepted by the stats subsystem, "<STATS>" is indicated instead. |
| 14134 | |
| 14135 | - "Tq" is the total time in milliseconds spent waiting for the client to send |
| 14136 | a full HTTP request, not counting data. It can be "-1" if the connection |
| 14137 | was aborted before a complete request could be received. It should always |
| 14138 | be very small because a request generally fits in one single packet. Large |
| 14139 | times here generally indicate network trouble between the client and |
| 14140 | haproxy. See "Timers" below for more details. |
| 14141 | |
| 14142 | - "Tw" is the total time in milliseconds spent waiting in the various queues. |
| 14143 | It can be "-1" if the connection was aborted before reaching the queue. |
| 14144 | See "Timers" below for more details. |
| 14145 | |
| 14146 | - "Tc" is the total time in milliseconds spent waiting for the connection to |
| 14147 | establish to the final server, including retries. It can be "-1" if the |
| 14148 | request was aborted before a connection could be established. See "Timers" |
| 14149 | below for more details. |
| 14150 | |
| 14151 | - "Tr" is the total time in milliseconds spent waiting for the server to send |
| 14152 | a full HTTP response, not counting data. It can be "-1" if the request was |
| 14153 | aborted before a complete response could be received. It generally matches |
| 14154 | the server's processing time for the request, though it may be altered by |
| 14155 | the amount of data sent by the client to the server. Large times here on |
| 14156 | "GET" requests generally indicate an overloaded server. See "Timers" below |
| 14157 | for more details. |
| 14158 | |
| 14159 | - "Tt" is the total time in milliseconds elapsed between the accept and the |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 14160 | last close. It covers all possible processing. There is one exception, if |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14161 | "option logasap" was specified, then the time counting stops at the moment |
| 14162 | the log is emitted. In this case, a '+' sign is prepended before the value, |
| 14163 | indicating that the final one will be larger. See "Timers" below for more |
| 14164 | details. |
| 14165 | |
| 14166 | - "status_code" is the HTTP status code returned to the client. This status |
| 14167 | is generally set by the server, but it might also be set by haproxy when |
| 14168 | the server cannot be reached or when its response is blocked by haproxy. |
| 14169 | |
| 14170 | - "bytes_read" is the total number of bytes transmitted to the client when |
| 14171 | the log is emitted. This does include HTTP headers. If "option logasap" is |
| 14172 | specified, the this value will be prefixed with a '+' sign indicating that |
| 14173 | the final one may be larger. Please note that this value is a 64-bit |
| 14174 | counter, so log analysis tools must be able to handle it without |
| 14175 | overflowing. |
| 14176 | |
| 14177 | - "captured_request_cookie" is an optional "name=value" entry indicating that |
| 14178 | the client had this cookie in the request. The cookie name and its maximum |
| 14179 | length are defined by the "capture cookie" statement in the frontend |
| 14180 | configuration. The field is a single dash ('-') when the option is not |
| 14181 | set. Only one cookie may be captured, it is generally used to track session |
| 14182 | ID exchanges between a client and a server to detect session crossing |
| 14183 | between clients due to application bugs. For more details, please consult |
| 14184 | the section "Capturing HTTP headers and cookies" below. |
| 14185 | |
| 14186 | - "captured_response_cookie" is an optional "name=value" entry indicating |
| 14187 | that the server has returned a cookie with its response. The cookie name |
| 14188 | and its maximum length are defined by the "capture cookie" statement in the |
| 14189 | frontend configuration. The field is a single dash ('-') when the option is |
| 14190 | not set. Only one cookie may be captured, it is generally used to track |
| 14191 | session ID exchanges between a client and a server to detect session |
| 14192 | crossing between clients due to application bugs. For more details, please |
| 14193 | consult the section "Capturing HTTP headers and cookies" below. |
| 14194 | |
| 14195 | - "termination_state" is the condition the session was in when the session |
| 14196 | ended. This indicates the session state, which side caused the end of |
| 14197 | session to happen, for what reason (timeout, error, ...), just like in TCP |
| 14198 | logs, and information about persistence operations on cookies in the last |
| 14199 | two characters. The normal flags should begin with "--", indicating the |
| 14200 | session was closed by either end with no data remaining in buffers. See |
| 14201 | below "Session state at disconnection" for more details. |
| 14202 | |
| 14203 | - "actconn" is the total number of concurrent connections on the process when |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 14204 | the session was logged. It is useful to detect when some per-process system |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14205 | limits have been reached. For instance, if actconn is close to 512 or 1024 |
| 14206 | when multiple connection errors occur, chances are high that the system |
| 14207 | limits the process to use a maximum of 1024 file descriptors and that all |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 14208 | of them are used. See section 3 "Global parameters" to find how to tune the |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14209 | system. |
| 14210 | |
| 14211 | - "feconn" is the total number of concurrent connections on the frontend when |
| 14212 | the session was logged. It is useful to estimate the amount of resource |
| 14213 | required to sustain high loads, and to detect when the frontend's "maxconn" |
| 14214 | has been reached. Most often when this value increases by huge jumps, it is |
| 14215 | because there is congestion on the backend servers, but sometimes it can be |
| 14216 | caused by a denial of service attack. |
| 14217 | |
| 14218 | - "beconn" is the total number of concurrent connections handled by the |
| 14219 | backend when the session was logged. It includes the total number of |
| 14220 | concurrent connections active on servers as well as the number of |
| 14221 | connections pending in queues. It is useful to estimate the amount of |
| 14222 | additional servers needed to support high loads for a given application. |
| 14223 | Most often when this value increases by huge jumps, it is because there is |
| 14224 | congestion on the backend servers, but sometimes it can be caused by a |
| 14225 | denial of service attack. |
| 14226 | |
| 14227 | - "srv_conn" is the total number of concurrent connections still active on |
| 14228 | the server when the session was logged. It can never exceed the server's |
| 14229 | configured "maxconn" parameter. If this value is very often close or equal |
| 14230 | to the server's "maxconn", it means that traffic regulation is involved a |
| 14231 | lot, meaning that either the server's maxconn value is too low, or that |
| 14232 | there aren't enough servers to process the load with an optimal response |
| 14233 | time. When only one of the server's "srv_conn" is high, it usually means |
| 14234 | that this server has some trouble causing the requests to take longer to be |
| 14235 | processed than on other servers. |
| 14236 | |
| 14237 | - "retries" is the number of connection retries experienced by this session |
| 14238 | when trying to connect to the server. It must normally be zero, unless a |
| 14239 | server is being stopped at the same moment the connection was attempted. |
| 14240 | Frequent retries generally indicate either a network problem between |
| 14241 | haproxy and the server, or a misconfigured system backlog on the server |
| 14242 | preventing new connections from being queued. This field may optionally be |
| 14243 | prefixed with a '+' sign, indicating that the session has experienced a |
| 14244 | redispatch after the maximal retry count has been reached on the initial |
| 14245 | server. In this case, the server name appearing in the log is the one the |
| 14246 | connection was redispatched to, and not the first one, though both may |
| 14247 | sometimes be the same in case of hashing for instance. So as a general rule |
| 14248 | of thumb, when a '+' is present in front of the retry count, this count |
| 14249 | should not be attributed to the logged server. |
| 14250 | |
| 14251 | - "srv_queue" is the total number of requests which were processed before |
| 14252 | this one in the server queue. It is zero when the request has not gone |
| 14253 | through the server queue. It makes it possible to estimate the approximate |
| 14254 | server's response time by dividing the time spent in queue by the number of |
| 14255 | requests in the queue. It is worth noting that if a session experiences a |
| 14256 | redispatch and passes through two server queues, their positions will be |
| 14257 | cumulated. A request should not pass through both the server queue and the |
| 14258 | backend queue unless a redispatch occurs. |
| 14259 | |
| 14260 | - "backend_queue" is the total number of requests which were processed before |
| 14261 | this one in the backend's global queue. It is zero when the request has not |
| 14262 | gone through the global queue. It makes it possible to estimate the average |
| 14263 | queue length, which easily translates into a number of missing servers when |
| 14264 | divided by a server's "maxconn" parameter. It is worth noting that if a |
| 14265 | session experiences a redispatch, it may pass twice in the backend's queue, |
| 14266 | and then both positions will be cumulated. A request should not pass |
| 14267 | through both the server queue and the backend queue unless a redispatch |
| 14268 | occurs. |
| 14269 | |
| 14270 | - "captured_request_headers" is a list of headers captured in the request due |
| 14271 | to the presence of the "capture request header" statement in the frontend. |
| 14272 | Multiple headers can be captured, they will be delimited by a vertical bar |
| 14273 | ('|'). When no capture is enabled, the braces do not appear, causing a |
| 14274 | shift of remaining fields. It is important to note that this field may |
| 14275 | contain spaces, and that using it requires a smarter log parser than when |
| 14276 | it's not used. Please consult the section "Capturing HTTP headers and |
| 14277 | cookies" below for more details. |
| 14278 | |
| 14279 | - "captured_response_headers" is a list of headers captured in the response |
| 14280 | due to the presence of the "capture response header" statement in the |
| 14281 | frontend. Multiple headers can be captured, they will be delimited by a |
| 14282 | vertical bar ('|'). When no capture is enabled, the braces do not appear, |
| 14283 | causing a shift of remaining fields. It is important to note that this |
| 14284 | field may contain spaces, and that using it requires a smarter log parser |
| 14285 | than when it's not used. Please consult the section "Capturing HTTP headers |
| 14286 | and cookies" below for more details. |
| 14287 | |
| 14288 | - "http_request" is the complete HTTP request line, including the method, |
| 14289 | request and HTTP version string. Non-printable characters are encoded (see |
| 14290 | below the section "Non-printable characters"). This is always the last |
| 14291 | field, and it is always delimited by quotes and is the only one which can |
| 14292 | contain quotes. If new fields are added to the log format, they will be |
| 14293 | added before this field. This field might be truncated if the request is |
| 14294 | huge and does not fit in the standard syslog buffer (1024 characters). This |
| 14295 | is the reason why this field must always remain the last one. |
| 14296 | |
| 14297 | |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 14298 | 8.2.4. Custom log format |
| 14299 | ------------------------ |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14300 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14301 | The directive log-format allows you to customize the logs in http mode and tcp |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14302 | mode. It takes a string as argument. |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14303 | |
| 14304 | HAproxy understands some log format variables. % precedes log format variables. |
| 14305 | Variables can take arguments using braces ('{}'), and multiple arguments are |
| 14306 | separated by commas within the braces. Flags may be added or removed by |
| 14307 | prefixing them with a '+' or '-' sign. |
| 14308 | |
| 14309 | Special variable "%o" may be used to propagate its flags to all other |
| 14310 | variables on the same format string. This is particularly handy with quoted |
| 14311 | string formats ("Q"). |
| 14312 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 14313 | If a variable is named between square brackets ('[' .. ']') then it is used |
Willy Tarreau | be722a2 | 2014-06-13 16:31:59 +0200 | [diff] [blame] | 14314 | as a sample expression rule (see section 7.3). This it useful to add some |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 14315 | less common information such as the client's SSL certificate's DN, or to log |
| 14316 | the key that would be used to store an entry into a stick table. |
| 14317 | |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14318 | Note: spaces must be escaped. A space character is considered as a separator. |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 14319 | In order to emit a verbatim '%', it must be preceded by another '%' resulting |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 14320 | in '%%'. HAProxy will automatically merge consecutive separators. |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14321 | |
| 14322 | Flags are : |
| 14323 | * Q: quote a string |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 14324 | * X: hexadecimal representation (IPs, Ports, %Ts, %rt, %pid) |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14325 | |
| 14326 | Example: |
| 14327 | |
| 14328 | log-format %T\ %t\ Some\ Text |
| 14329 | log-format %{+Q}o\ %t\ %s\ %{-Q}r |
| 14330 | |
| 14331 | At the moment, the default HTTP format is defined this way : |
| 14332 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14333 | log-format %ci:%cp\ [%t]\ %ft\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %ST\ %B\ %CC\ \ |
| 14334 | %CS\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ %hr\ %hs\ %{+Q}r |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14335 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14336 | the default CLF format is defined this way : |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14337 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14338 | log-format %{+Q}o\ %{-Q}ci\ -\ -\ [%T]\ %r\ %ST\ %B\ \"\"\ \"\"\ %cp\ \ |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 14339 | %ms\ %ft\ %b\ %s\ \%Tq\ %Tw\ %Tc\ %Tr\ %Tt\ %tsc\ %ac\ %fc\ \ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14340 | %bc\ %sc\ %rc\ %sq\ %bq\ %CC\ %CS\ \%hrl\ %hsl |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14341 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14342 | and the default TCP format is defined this way : |
| 14343 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14344 | log-format %ci:%cp\ [%t]\ %ft\ %b/%s\ %Tw/%Tc/%Tt\ %B\ %ts\ \ |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14345 | %ac/%fc/%bc/%sc/%rc\ %sq/%bq |
| 14346 | |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14347 | Please refer to the table below for currently defined variables : |
| 14348 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14349 | +---+------+-----------------------------------------------+-------------+ |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 14350 | | R | var | field name (8.2.2 and 8.2.3 for description) | type | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14351 | +---+------+-----------------------------------------------+-------------+ |
| 14352 | | | %o | special variable, apply flags on all next var | | |
| 14353 | +---+------+-----------------------------------------------+-------------+ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14354 | | | %B | bytes_read (from server to client) | numeric | |
| 14355 | | H | %CC | captured_request_cookie | string | |
| 14356 | | H | %CS | captured_response_cookie | string | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 14357 | | | %H | hostname | string | |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 14358 | | H | %HM | HTTP method (ex: POST) | string | |
| 14359 | | H | %HP | HTTP request URI without query string (path) | string | |
Andrew Hayworth | e63ac87 | 2015-07-31 16:14:16 +0000 | [diff] [blame] | 14360 | | H | %HQ | HTTP request URI query string (ex: ?bar=baz) | string | |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 14361 | | H | %HU | HTTP request URI (ex: /foo?bar=baz) | string | |
| 14362 | | H | %HV | HTTP version (ex: HTTP/1.0) | string | |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 14363 | | | %ID | unique-id | string | |
Willy Tarreau | 4bf9963 | 2014-06-13 12:21:40 +0200 | [diff] [blame] | 14364 | | | %ST | status_code | numeric | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 14365 | | | %T | gmt_date_time | date | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14366 | | | %Tc | Tc | numeric | |
Yuxans Yao | 4e25b01 | 2012-10-19 10:36:09 +0800 | [diff] [blame] | 14367 | | | %Tl | local_date_time | date | |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 14368 | | H | %Tq | Tq | numeric | |
| 14369 | | H | %Tr | Tr | numeric | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 14370 | | | %Ts | timestamp | numeric | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14371 | | | %Tt | Tt | numeric | |
| 14372 | | | %Tw | Tw | numeric | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14373 | | | %U | bytes_uploaded (from client to server) | numeric | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14374 | | | %ac | actconn | numeric | |
| 14375 | | | %b | backend_name | string | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14376 | | | %bc | beconn (backend concurrent connections) | numeric | |
| 14377 | | | %bi | backend_source_ip (connecting address) | IP | |
| 14378 | | | %bp | backend_source_port (connecting address) | numeric | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14379 | | | %bq | backend_queue | numeric | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14380 | | | %ci | client_ip (accepted address) | IP | |
| 14381 | | | %cp | client_port (accepted address) | numeric | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14382 | | | %f | frontend_name | string | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14383 | | | %fc | feconn (frontend concurrent connections) | numeric | |
| 14384 | | | %fi | frontend_ip (accepting address) | IP | |
| 14385 | | | %fp | frontend_port (accepting address) | numeric | |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 14386 | | | %ft | frontend_name_transport ('~' suffix for SSL) | string | |
Willy Tarreau | 7346acb | 2014-08-28 15:03:15 +0200 | [diff] [blame] | 14387 | | | %lc | frontend_log_counter | numeric | |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 14388 | | | %hr | captured_request_headers default style | string | |
| 14389 | | | %hrl | captured_request_headers CLF style | string list | |
| 14390 | | | %hs | captured_response_headers default style | string | |
| 14391 | | | %hsl | captured_response_headers CLF style | string list | |
Willy Tarreau | 812c88e | 2015-08-09 10:56:35 +0200 | [diff] [blame] | 14392 | | | %ms | accept date milliseconds (left-padded with 0) | numeric | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 14393 | | | %pid | PID | numeric | |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 14394 | | H | %r | http_request | string | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14395 | | | %rc | retries | numeric | |
Willy Tarreau | 1f0da24 | 2014-01-25 11:01:50 +0100 | [diff] [blame] | 14396 | | | %rt | request_counter (HTTP req or TCP session) | numeric | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14397 | | | %s | server_name | string | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14398 | | | %sc | srv_conn (server concurrent connections) | numeric | |
| 14399 | | | %si | server_IP (target address) | IP | |
| 14400 | | | %sp | server_port (target address) | numeric | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14401 | | | %sq | srv_queue | numeric | |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 14402 | | S | %sslc| ssl_ciphers (ex: AES-SHA) | string | |
| 14403 | | S | %sslv| ssl_version (ex: TLSv1) | string | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 14404 | | | %t | date_time (with millisecond resolution) | date | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14405 | | | %ts | termination_state | string | |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 14406 | | H | %tsc | termination_state with cookie status | string | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 14407 | +---+------+-----------------------------------------------+-------------+ |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14408 | |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 14409 | R = Restrictions : H = mode http only ; S = SSL only |
William Lallemand | 4894040 | 2012-01-30 16:47:22 +0100 | [diff] [blame] | 14410 | |
Willy Tarreau | 5f51e1a | 2012-12-03 18:40:10 +0100 | [diff] [blame] | 14411 | |
| 14412 | 8.2.5. Error log format |
| 14413 | ----------------------- |
| 14414 | |
| 14415 | When an incoming connection fails due to an SSL handshake or an invalid PROXY |
| 14416 | protocol header, haproxy will log the event using a shorter, fixed line format. |
| 14417 | By default, logs are emitted at the LOG_INFO level, unless the option |
| 14418 | "log-separate-errors" is set in the backend, in which case the LOG_ERR level |
| 14419 | will be used. Connections on which no data are exchanged (eg: probes) are not |
| 14420 | logged if the "dontlognull" option is set. |
| 14421 | |
| 14422 | The format looks like this : |
| 14423 | |
| 14424 | >>> Dec 3 18:27:14 localhost \ |
| 14425 | haproxy[6103]: 127.0.0.1:56059 [03/Dec/2012:17:35:10.380] frt/f1: \ |
| 14426 | Connection error during SSL handshake |
| 14427 | |
| 14428 | Field Format Extract from the example above |
| 14429 | 1 process_name '[' pid ']:' haproxy[6103]: |
| 14430 | 2 client_ip ':' client_port 127.0.0.1:56059 |
| 14431 | 3 '[' accept_date ']' [03/Dec/2012:17:35:10.380] |
| 14432 | 4 frontend_name "/" bind_name ":" frt/f1: |
| 14433 | 5 message Connection error during SSL handshake |
| 14434 | |
| 14435 | These fields just provide minimal information to help debugging connection |
| 14436 | failures. |
| 14437 | |
| 14438 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 14439 | 8.3. Advanced logging options |
| 14440 | ----------------------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14441 | |
| 14442 | Some advanced logging options are often looked for but are not easy to find out |
| 14443 | just by looking at the various options. Here is an entry point for the few |
| 14444 | options which can enable better logging. Please refer to the keywords reference |
| 14445 | for more information about their usage. |
| 14446 | |
| 14447 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 14448 | 8.3.1. Disabling logging of external tests |
| 14449 | ------------------------------------------ |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14450 | |
| 14451 | It is quite common to have some monitoring tools perform health checks on |
| 14452 | haproxy. Sometimes it will be a layer 3 load-balancer such as LVS or any |
| 14453 | commercial load-balancer, and sometimes it will simply be a more complete |
| 14454 | monitoring system such as Nagios. When the tests are very frequent, users often |
| 14455 | ask how to disable logging for those checks. There are three possibilities : |
| 14456 | |
| 14457 | - if connections come from everywhere and are just TCP probes, it is often |
| 14458 | desired to simply disable logging of connections without data exchange, by |
| 14459 | setting "option dontlognull" in the frontend. It also disables logging of |
| 14460 | port scans, which may or may not be desired. |
| 14461 | |
| 14462 | - if the connection come from a known source network, use "monitor-net" to |
| 14463 | declare this network as monitoring only. Any host in this network will then |
| 14464 | only be able to perform health checks, and their requests will not be |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 14465 | logged. This is generally appropriate to designate a list of equipment |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14466 | such as other load-balancers. |
| 14467 | |
| 14468 | - if the tests are performed on a known URI, use "monitor-uri" to declare |
| 14469 | this URI as dedicated to monitoring. Any host sending this request will |
| 14470 | only get the result of a health-check, and the request will not be logged. |
| 14471 | |
| 14472 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 14473 | 8.3.2. Logging before waiting for the session to terminate |
| 14474 | ---------------------------------------------------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14475 | |
| 14476 | The problem with logging at end of connection is that you have no clue about |
| 14477 | what is happening during very long sessions, such as remote terminal sessions |
| 14478 | or large file downloads. This problem can be worked around by specifying |
| 14479 | "option logasap" in the frontend. Haproxy will then log as soon as possible, |
| 14480 | just before data transfer begins. This means that in case of TCP, it will still |
| 14481 | log the connection status to the server, and in case of HTTP, it will log just |
| 14482 | after processing the server headers. In this case, the number of bytes reported |
| 14483 | is the number of header bytes sent to the client. In order to avoid confusion |
| 14484 | with normal logs, the total time field and the number of bytes are prefixed |
| 14485 | with a '+' sign which means that real numbers are certainly larger. |
| 14486 | |
| 14487 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 14488 | 8.3.3. Raising log level upon errors |
| 14489 | ------------------------------------ |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 14490 | |
| 14491 | Sometimes it is more convenient to separate normal traffic from errors logs, |
| 14492 | for instance in order to ease error monitoring from log files. When the option |
| 14493 | "log-separate-errors" is used, connections which experience errors, timeouts, |
| 14494 | retries, redispatches or HTTP status codes 5xx will see their syslog level |
| 14495 | raised from "info" to "err". This will help a syslog daemon store the log in |
| 14496 | a separate file. It is very important to keep the errors in the normal traffic |
| 14497 | file too, so that log ordering is not altered. You should also be careful if |
| 14498 | you already have configured your syslog daemon to store all logs higher than |
| 14499 | "notice" in an "admin" file, because the "err" level is higher than "notice". |
| 14500 | |
| 14501 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 14502 | 8.3.4. Disabling logging of successful connections |
| 14503 | -------------------------------------------------- |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 14504 | |
| 14505 | Although this may sound strange at first, some large sites have to deal with |
| 14506 | multiple thousands of logs per second and are experiencing difficulties keeping |
| 14507 | them intact for a long time or detecting errors within them. If the option |
| 14508 | "dontlog-normal" is set on the frontend, all normal connections will not be |
| 14509 | logged. In this regard, a normal connection is defined as one without any |
| 14510 | error, timeout, retry nor redispatch. In HTTP, the status code is checked too, |
| 14511 | and a response with a status 5xx is not considered normal and will be logged |
| 14512 | too. Of course, doing is is really discouraged as it will remove most of the |
| 14513 | useful information from the logs. Do this only if you have no other |
| 14514 | alternative. |
| 14515 | |
| 14516 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 14517 | 8.4. Timing events |
| 14518 | ------------------ |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14519 | |
| 14520 | Timers provide a great help in troubleshooting network problems. All values are |
| 14521 | reported in milliseconds (ms). These timers should be used in conjunction with |
| 14522 | the session termination flags. In TCP mode with "option tcplog" set on the |
| 14523 | frontend, 3 control points are reported under the form "Tw/Tc/Tt", and in HTTP |
| 14524 | mode, 5 control points are reported under the form "Tq/Tw/Tc/Tr/Tt" : |
| 14525 | |
| 14526 | - Tq: total time to get the client request (HTTP mode only). It's the time |
| 14527 | elapsed between the moment the client connection was accepted and the |
| 14528 | moment the proxy received the last HTTP header. The value "-1" indicates |
| 14529 | that the end of headers (empty line) has never been seen. This happens when |
| 14530 | the client closes prematurely or times out. |
| 14531 | |
| 14532 | - Tw: total time spent in the queues waiting for a connection slot. It |
| 14533 | accounts for backend queue as well as the server queues, and depends on the |
| 14534 | queue size, and the time needed for the server to complete previous |
| 14535 | requests. The value "-1" means that the request was killed before reaching |
| 14536 | the queue, which is generally what happens with invalid or denied requests. |
| 14537 | |
| 14538 | - Tc: total time to establish the TCP connection to the server. It's the time |
| 14539 | elapsed between the moment the proxy sent the connection request, and the |
| 14540 | moment it was acknowledged by the server, or between the TCP SYN packet and |
| 14541 | the matching SYN/ACK packet in return. The value "-1" means that the |
| 14542 | connection never established. |
| 14543 | |
| 14544 | - Tr: server response time (HTTP mode only). It's the time elapsed between |
| 14545 | the moment the TCP connection was established to the server and the moment |
| 14546 | the server sent its complete response headers. It purely shows its request |
| 14547 | processing time, without the network overhead due to the data transmission. |
| 14548 | It is worth noting that when the client has data to send to the server, for |
| 14549 | instance during a POST request, the time already runs, and this can distort |
| 14550 | apparent response time. For this reason, it's generally wise not to trust |
| 14551 | too much this field for POST requests initiated from clients behind an |
| 14552 | untrusted network. A value of "-1" here means that the last the response |
| 14553 | header (empty line) was never seen, most likely because the server timeout |
| 14554 | stroke before the server managed to process the request. |
| 14555 | |
| 14556 | - Tt: total session duration time, between the moment the proxy accepted it |
| 14557 | and the moment both ends were closed. The exception is when the "logasap" |
| 14558 | option is specified. In this case, it only equals (Tq+Tw+Tc+Tr), and is |
| 14559 | prefixed with a '+' sign. From this field, we can deduce "Td", the data |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 14560 | transmission time, by subtracting other timers when valid : |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14561 | |
| 14562 | Td = Tt - (Tq + Tw + Tc + Tr) |
| 14563 | |
| 14564 | Timers with "-1" values have to be excluded from this equation. In TCP |
| 14565 | mode, "Tq" and "Tr" have to be excluded too. Note that "Tt" can never be |
| 14566 | negative. |
| 14567 | |
| 14568 | These timers provide precious indications on trouble causes. Since the TCP |
| 14569 | protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure |
| 14570 | that timers close to multiples of 3s are nearly always related to lost packets |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 14571 | due to network problems (wires, negotiation, congestion). Moreover, if "Tt" is |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14572 | close to a timeout value specified in the configuration, it often means that a |
| 14573 | session has been aborted on timeout. |
| 14574 | |
| 14575 | Most common cases : |
| 14576 | |
| 14577 | - If "Tq" is close to 3000, a packet has probably been lost between the |
| 14578 | client and the proxy. This is very rare on local networks but might happen |
| 14579 | when clients are on far remote networks and send large requests. It may |
| 14580 | happen that values larger than usual appear here without any network cause. |
| 14581 | Sometimes, during an attack or just after a resource starvation has ended, |
| 14582 | haproxy may accept thousands of connections in a few milliseconds. The time |
| 14583 | spent accepting these connections will inevitably slightly delay processing |
| 14584 | of other connections, and it can happen that request times in the order of |
| 14585 | a few tens of milliseconds are measured after a few thousands of new |
Patrick Mezard | 105faca | 2010-06-12 17:02:46 +0200 | [diff] [blame] | 14586 | connections have been accepted at once. Setting "option http-server-close" |
| 14587 | may display larger request times since "Tq" also measures the time spent |
| 14588 | waiting for additional requests. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14589 | |
| 14590 | - If "Tc" is close to 3000, a packet has probably been lost between the |
| 14591 | server and the proxy during the server connection phase. This value should |
| 14592 | always be very low, such as 1 ms on local networks and less than a few tens |
| 14593 | of ms on remote networks. |
| 14594 | |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 14595 | - If "Tr" is nearly always lower than 3000 except some rare values which seem |
| 14596 | to be the average majored by 3000, there are probably some packets lost |
| 14597 | between the proxy and the server. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14598 | |
| 14599 | - If "Tt" is large even for small byte counts, it generally is because |
| 14600 | neither the client nor the server decides to close the connection, for |
| 14601 | instance because both have agreed on a keep-alive connection mode. In order |
| 14602 | to solve this issue, it will be needed to specify "option httpclose" on |
| 14603 | either the frontend or the backend. If the problem persists, it means that |
| 14604 | the server ignores the "close" connection mode and expects the client to |
| 14605 | close. Then it will be required to use "option forceclose". Having the |
| 14606 | smallest possible 'Tt' is important when connection regulation is used with |
| 14607 | the "maxconn" option on the servers, since no new connection will be sent |
| 14608 | to the server until another one is released. |
| 14609 | |
| 14610 | Other noticeable HTTP log cases ('xx' means any value to be ignored) : |
| 14611 | |
| 14612 | Tq/Tw/Tc/Tr/+Tt The "option logasap" is present on the frontend and the log |
| 14613 | was emitted before the data phase. All the timers are valid |
| 14614 | except "Tt" which is shorter than reality. |
| 14615 | |
| 14616 | -1/xx/xx/xx/Tt The client was not able to send a complete request in time |
| 14617 | or it aborted too early. Check the session termination flags |
| 14618 | then "timeout http-request" and "timeout client" settings. |
| 14619 | |
| 14620 | Tq/-1/xx/xx/Tt It was not possible to process the request, maybe because |
| 14621 | servers were out of order, because the request was invalid |
| 14622 | or forbidden by ACL rules. Check the session termination |
| 14623 | flags. |
| 14624 | |
| 14625 | Tq/Tw/-1/xx/Tt The connection could not establish on the server. Either it |
| 14626 | actively refused it or it timed out after Tt-(Tq+Tw) ms. |
| 14627 | Check the session termination flags, then check the |
| 14628 | "timeout connect" setting. Note that the tarpit action might |
| 14629 | return similar-looking patterns, with "Tw" equal to the time |
| 14630 | the client connection was maintained open. |
| 14631 | |
| 14632 | Tq/Tw/Tc/-1/Tt The server has accepted the connection but did not return |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 14633 | a complete response in time, or it closed its connection |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14634 | unexpectedly after Tt-(Tq+Tw+Tc) ms. Check the session |
| 14635 | termination flags, then check the "timeout server" setting. |
| 14636 | |
| 14637 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 14638 | 8.5. Session state at disconnection |
| 14639 | ----------------------------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14640 | |
| 14641 | TCP and HTTP logs provide a session termination indicator in the |
| 14642 | "termination_state" field, just before the number of active connections. It is |
| 14643 | 2-characters long in TCP mode, and is extended to 4 characters in HTTP mode, |
| 14644 | each of which has a special meaning : |
| 14645 | |
| 14646 | - On the first character, a code reporting the first event which caused the |
| 14647 | session to terminate : |
| 14648 | |
| 14649 | C : the TCP session was unexpectedly aborted by the client. |
| 14650 | |
| 14651 | S : the TCP session was unexpectedly aborted by the server, or the |
| 14652 | server explicitly refused it. |
| 14653 | |
| 14654 | P : the session was prematurely aborted by the proxy, because of a |
| 14655 | connection limit enforcement, because a DENY filter was matched, |
| 14656 | because of a security check which detected and blocked a dangerous |
| 14657 | error in server response which might have caused information leak |
Willy Tarreau | 570f221 | 2013-06-10 16:42:09 +0200 | [diff] [blame] | 14658 | (eg: cacheable cookie). |
| 14659 | |
| 14660 | L : the session was locally processed by haproxy and was not passed to |
| 14661 | a server. This is what happens for stats and redirects. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14662 | |
| 14663 | R : a resource on the proxy has been exhausted (memory, sockets, source |
| 14664 | ports, ...). Usually, this appears during the connection phase, and |
| 14665 | system logs should contain a copy of the precise error. If this |
| 14666 | happens, it must be considered as a very serious anomaly which |
| 14667 | should be fixed as soon as possible by any means. |
| 14668 | |
| 14669 | I : an internal error was identified by the proxy during a self-check. |
| 14670 | This should NEVER happen, and you are encouraged to report any log |
| 14671 | containing this, because this would almost certainly be a bug. It |
| 14672 | would be wise to preventively restart the process after such an |
| 14673 | event too, in case it would be caused by memory corruption. |
| 14674 | |
Simon Horman | 752dc4a | 2011-06-21 14:34:59 +0900 | [diff] [blame] | 14675 | D : the session was killed by haproxy because the server was detected |
| 14676 | as down and was configured to kill all connections when going down. |
| 14677 | |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 14678 | U : the session was killed by haproxy on this backup server because an |
| 14679 | active server was detected as up and was configured to kill all |
| 14680 | backup connections when going up. |
| 14681 | |
Willy Tarreau | a2a64e9 | 2011-09-07 23:01:56 +0200 | [diff] [blame] | 14682 | K : the session was actively killed by an admin operating on haproxy. |
| 14683 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14684 | c : the client-side timeout expired while waiting for the client to |
| 14685 | send or receive data. |
| 14686 | |
| 14687 | s : the server-side timeout expired while waiting for the server to |
| 14688 | send or receive data. |
| 14689 | |
| 14690 | - : normal session completion, both the client and the server closed |
| 14691 | with nothing left in the buffers. |
| 14692 | |
| 14693 | - on the second character, the TCP or HTTP session state when it was closed : |
| 14694 | |
Willy Tarreau | f7b30a9 | 2010-12-06 22:59:17 +0100 | [diff] [blame] | 14695 | R : the proxy was waiting for a complete, valid REQUEST from the client |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14696 | (HTTP mode only). Nothing was sent to any server. |
| 14697 | |
| 14698 | Q : the proxy was waiting in the QUEUE for a connection slot. This can |
| 14699 | only happen when servers have a 'maxconn' parameter set. It can |
| 14700 | also happen in the global queue after a redispatch consecutive to |
| 14701 | a failed attempt to connect to a dying server. If no redispatch is |
| 14702 | reported, then no connection attempt was made to any server. |
| 14703 | |
| 14704 | C : the proxy was waiting for the CONNECTION to establish on the |
| 14705 | server. The server might at most have noticed a connection attempt. |
| 14706 | |
| 14707 | H : the proxy was waiting for complete, valid response HEADERS from the |
| 14708 | server (HTTP only). |
| 14709 | |
| 14710 | D : the session was in the DATA phase. |
| 14711 | |
| 14712 | L : the proxy was still transmitting LAST data to the client while the |
| 14713 | server had already finished. This one is very rare as it can only |
| 14714 | happen when the client dies while receiving the last packets. |
| 14715 | |
| 14716 | T : the request was tarpitted. It has been held open with the client |
| 14717 | during the whole "timeout tarpit" duration or until the client |
| 14718 | closed, both of which will be reported in the "Tw" timer. |
| 14719 | |
| 14720 | - : normal session completion after end of data transfer. |
| 14721 | |
| 14722 | - the third character tells whether the persistence cookie was provided by |
| 14723 | the client (only in HTTP mode) : |
| 14724 | |
| 14725 | N : the client provided NO cookie. This is usually the case for new |
| 14726 | visitors, so counting the number of occurrences of this flag in the |
| 14727 | logs generally indicate a valid trend for the site frequentation. |
| 14728 | |
| 14729 | I : the client provided an INVALID cookie matching no known server. |
| 14730 | This might be caused by a recent configuration change, mixed |
Cyril Bonté | a8e7bbc | 2010-04-25 22:29:29 +0200 | [diff] [blame] | 14731 | cookies between HTTP/HTTPS sites, persistence conditionally |
| 14732 | ignored, or an attack. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14733 | |
| 14734 | D : the client provided a cookie designating a server which was DOWN, |
| 14735 | so either "option persist" was used and the client was sent to |
| 14736 | this server, or it was not set and the client was redispatched to |
| 14737 | another server. |
| 14738 | |
Willy Tarreau | 996a92c | 2010-10-13 19:30:47 +0200 | [diff] [blame] | 14739 | V : the client provided a VALID cookie, and was sent to the associated |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14740 | server. |
| 14741 | |
Willy Tarreau | 996a92c | 2010-10-13 19:30:47 +0200 | [diff] [blame] | 14742 | E : the client provided a valid cookie, but with a last date which was |
| 14743 | older than what is allowed by the "maxidle" cookie parameter, so |
| 14744 | the cookie is consider EXPIRED and is ignored. The request will be |
| 14745 | redispatched just as if there was no cookie. |
| 14746 | |
| 14747 | O : the client provided a valid cookie, but with a first date which was |
| 14748 | older than what is allowed by the "maxlife" cookie parameter, so |
| 14749 | the cookie is consider too OLD and is ignored. The request will be |
| 14750 | redispatched just as if there was no cookie. |
| 14751 | |
Willy Tarreau | c89ccb6 | 2012-04-05 21:18:22 +0200 | [diff] [blame] | 14752 | U : a cookie was present but was not used to select the server because |
| 14753 | some other server selection mechanism was used instead (typically a |
| 14754 | "use-server" rule). |
| 14755 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14756 | - : does not apply (no cookie set in configuration). |
| 14757 | |
| 14758 | - the last character reports what operations were performed on the persistence |
| 14759 | cookie returned by the server (only in HTTP mode) : |
| 14760 | |
| 14761 | N : NO cookie was provided by the server, and none was inserted either. |
| 14762 | |
| 14763 | I : no cookie was provided by the server, and the proxy INSERTED one. |
| 14764 | Note that in "cookie insert" mode, if the server provides a cookie, |
| 14765 | it will still be overwritten and reported as "I" here. |
| 14766 | |
Willy Tarreau | 996a92c | 2010-10-13 19:30:47 +0200 | [diff] [blame] | 14767 | U : the proxy UPDATED the last date in the cookie that was presented by |
| 14768 | the client. This can only happen in insert mode with "maxidle". It |
Jarno Huuskonen | 0e82b92 | 2014-04-12 18:22:19 +0300 | [diff] [blame] | 14769 | happens every time there is activity at a different date than the |
Willy Tarreau | 996a92c | 2010-10-13 19:30:47 +0200 | [diff] [blame] | 14770 | date indicated in the cookie. If any other change happens, such as |
| 14771 | a redispatch, then the cookie will be marked as inserted instead. |
| 14772 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14773 | P : a cookie was PROVIDED by the server and transmitted as-is. |
| 14774 | |
| 14775 | R : the cookie provided by the server was REWRITTEN by the proxy, which |
| 14776 | happens in "cookie rewrite" or "cookie prefix" modes. |
| 14777 | |
| 14778 | D : the cookie provided by the server was DELETED by the proxy. |
| 14779 | |
| 14780 | - : does not apply (no cookie set in configuration). |
| 14781 | |
Willy Tarreau | 996a92c | 2010-10-13 19:30:47 +0200 | [diff] [blame] | 14782 | The combination of the two first flags gives a lot of information about what |
| 14783 | was happening when the session terminated, and why it did terminate. It can be |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14784 | helpful to detect server saturation, network troubles, local system resource |
| 14785 | starvation, attacks, etc... |
| 14786 | |
| 14787 | The most common termination flags combinations are indicated below. They are |
| 14788 | alphabetically sorted, with the lowercase set just after the upper case for |
| 14789 | easier finding and understanding. |
| 14790 | |
| 14791 | Flags Reason |
| 14792 | |
| 14793 | -- Normal termination. |
| 14794 | |
| 14795 | CC The client aborted before the connection could be established to the |
| 14796 | server. This can happen when haproxy tries to connect to a recently |
| 14797 | dead (or unchecked) server, and the client aborts while haproxy is |
| 14798 | waiting for the server to respond or for "timeout connect" to expire. |
| 14799 | |
| 14800 | CD The client unexpectedly aborted during data transfer. This can be |
| 14801 | caused by a browser crash, by an intermediate equipment between the |
| 14802 | client and haproxy which decided to actively break the connection, |
| 14803 | by network routing issues between the client and haproxy, or by a |
| 14804 | keep-alive session between the server and the client terminated first |
| 14805 | by the client. |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 14806 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14807 | cD The client did not send nor acknowledge any data for as long as the |
| 14808 | "timeout client" delay. This is often caused by network failures on |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 14809 | the client side, or the client simply leaving the net uncleanly. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14810 | |
| 14811 | CH The client aborted while waiting for the server to start responding. |
| 14812 | It might be the server taking too long to respond or the client |
| 14813 | clicking the 'Stop' button too fast. |
| 14814 | |
| 14815 | cH The "timeout client" stroke while waiting for client data during a |
| 14816 | POST request. This is sometimes caused by too large TCP MSS values |
| 14817 | for PPPoE networks which cannot transport full-sized packets. It can |
| 14818 | also happen when client timeout is smaller than server timeout and |
| 14819 | the server takes too long to respond. |
| 14820 | |
| 14821 | CQ The client aborted while its session was queued, waiting for a server |
| 14822 | with enough empty slots to accept it. It might be that either all the |
| 14823 | servers were saturated or that the assigned server was taking too |
| 14824 | long a time to respond. |
| 14825 | |
| 14826 | CR The client aborted before sending a full HTTP request. Most likely |
| 14827 | the request was typed by hand using a telnet client, and aborted |
| 14828 | too early. The HTTP status code is likely a 400 here. Sometimes this |
| 14829 | might also be caused by an IDS killing the connection between haproxy |
Willy Tarreau | 0f228a0 | 2015-05-01 15:37:53 +0200 | [diff] [blame] | 14830 | and the client. "option http-ignore-probes" can be used to ignore |
| 14831 | connections without any data transfer. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14832 | |
| 14833 | cR The "timeout http-request" stroke before the client sent a full HTTP |
| 14834 | request. This is sometimes caused by too large TCP MSS values on the |
| 14835 | client side for PPPoE networks which cannot transport full-sized |
| 14836 | packets, or by clients sending requests by hand and not typing fast |
| 14837 | enough, or forgetting to enter the empty line at the end of the |
Willy Tarreau | 2705a61 | 2014-05-23 17:38:34 +0200 | [diff] [blame] | 14838 | request. The HTTP status code is likely a 408 here. Note: recently, |
Willy Tarreau | 0f228a0 | 2015-05-01 15:37:53 +0200 | [diff] [blame] | 14839 | some browsers started to implement a "pre-connect" feature consisting |
| 14840 | in speculatively connecting to some recently visited web sites just |
| 14841 | in case the user would like to visit them. This results in many |
| 14842 | connections being established to web sites, which end up in 408 |
| 14843 | Request Timeout if the timeout strikes first, or 400 Bad Request when |
| 14844 | the browser decides to close them first. These ones pollute the log |
| 14845 | and feed the error counters. Some versions of some browsers have even |
| 14846 | been reported to display the error code. It is possible to work |
| 14847 | around the undesirable effects of this behaviour by adding "option |
| 14848 | http-ignore-probes" in the frontend, resulting in connections with |
| 14849 | zero data transfer to be totally ignored. This will definitely hide |
| 14850 | the errors of people experiencing connectivity issues though. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14851 | |
| 14852 | CT The client aborted while its session was tarpitted. It is important to |
| 14853 | check if this happens on valid requests, in order to be sure that no |
Willy Tarreau | 55165fe | 2009-05-10 12:02:55 +0200 | [diff] [blame] | 14854 | wrong tarpit rules have been written. If a lot of them happen, it |
| 14855 | might make sense to lower the "timeout tarpit" value to something |
| 14856 | closer to the average reported "Tw" timer, in order not to consume |
| 14857 | resources for just a few attackers. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14858 | |
Willy Tarreau | 570f221 | 2013-06-10 16:42:09 +0200 | [diff] [blame] | 14859 | LR The request was intercepted and locally handled by haproxy. Generally |
| 14860 | it means that this was a redirect or a stats request. |
| 14861 | |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 14862 | SC The server or an equipment between it and haproxy explicitly refused |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14863 | the TCP connection (the proxy received a TCP RST or an ICMP message |
| 14864 | in return). Under some circumstances, it can also be the network |
| 14865 | stack telling the proxy that the server is unreachable (eg: no route, |
| 14866 | or no ARP response on local network). When this happens in HTTP mode, |
| 14867 | the status code is likely a 502 or 503 here. |
| 14868 | |
| 14869 | sC The "timeout connect" stroke before a connection to the server could |
| 14870 | complete. When this happens in HTTP mode, the status code is likely a |
| 14871 | 503 or 504 here. |
| 14872 | |
| 14873 | SD The connection to the server died with an error during the data |
| 14874 | transfer. This usually means that haproxy has received an RST from |
| 14875 | the server or an ICMP message from an intermediate equipment while |
| 14876 | exchanging data with the server. This can be caused by a server crash |
| 14877 | or by a network issue on an intermediate equipment. |
| 14878 | |
| 14879 | sD The server did not send nor acknowledge any data for as long as the |
| 14880 | "timeout server" setting during the data phase. This is often caused |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 14881 | by too short timeouts on L4 equipments before the server (firewalls, |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14882 | load-balancers, ...), as well as keep-alive sessions maintained |
| 14883 | between the client and the server expiring first on haproxy. |
| 14884 | |
| 14885 | SH The server aborted before sending its full HTTP response headers, or |
| 14886 | it crashed while processing the request. Since a server aborting at |
| 14887 | this moment is very rare, it would be wise to inspect its logs to |
| 14888 | control whether it crashed and why. The logged request may indicate a |
| 14889 | small set of faulty requests, demonstrating bugs in the application. |
| 14890 | Sometimes this might also be caused by an IDS killing the connection |
| 14891 | between haproxy and the server. |
| 14892 | |
| 14893 | sH The "timeout server" stroke before the server could return its |
| 14894 | response headers. This is the most common anomaly, indicating too |
| 14895 | long transactions, probably caused by server or database saturation. |
| 14896 | The immediate workaround consists in increasing the "timeout server" |
| 14897 | setting, but it is important to keep in mind that the user experience |
| 14898 | will suffer from these long response times. The only long term |
| 14899 | solution is to fix the application. |
| 14900 | |
| 14901 | sQ The session spent too much time in queue and has been expired. See |
| 14902 | the "timeout queue" and "timeout connect" settings to find out how to |
| 14903 | fix this if it happens too often. If it often happens massively in |
| 14904 | short periods, it may indicate general problems on the affected |
| 14905 | servers due to I/O or database congestion, or saturation caused by |
| 14906 | external attacks. |
| 14907 | |
| 14908 | PC The proxy refused to establish a connection to the server because the |
| 14909 | process' socket limit has been reached while attempting to connect. |
Cyril Bonté | dc4d903 | 2012-04-08 21:57:39 +0200 | [diff] [blame] | 14910 | The global "maxconn" parameter may be increased in the configuration |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14911 | so that it does not happen anymore. This status is very rare and |
| 14912 | might happen when the global "ulimit-n" parameter is forced by hand. |
| 14913 | |
Willy Tarreau | ed2fd2d | 2010-12-29 11:23:27 +0100 | [diff] [blame] | 14914 | PD The proxy blocked an incorrectly formatted chunked encoded message in |
| 14915 | a request or a response, after the server has emitted its headers. In |
| 14916 | most cases, this will indicate an invalid message from the server to |
Willy Tarreau | f3a3e13 | 2013-08-31 08:16:26 +0200 | [diff] [blame] | 14917 | the client. Haproxy supports chunk sizes of up to 2GB - 1 (2147483647 |
| 14918 | bytes). Any larger size will be considered as an error. |
Willy Tarreau | ed2fd2d | 2010-12-29 11:23:27 +0100 | [diff] [blame] | 14919 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14920 | PH The proxy blocked the server's response, because it was invalid, |
| 14921 | incomplete, dangerous (cache control), or matched a security filter. |
| 14922 | In any case, an HTTP 502 error is sent to the client. One possible |
| 14923 | cause for this error is an invalid syntax in an HTTP header name |
Willy Tarreau | ed2fd2d | 2010-12-29 11:23:27 +0100 | [diff] [blame] | 14924 | containing unauthorized characters. It is also possible but quite |
| 14925 | rare, that the proxy blocked a chunked-encoding request from the |
| 14926 | client due to an invalid syntax, before the server responded. In this |
| 14927 | case, an HTTP 400 error is sent to the client and reported in the |
| 14928 | logs. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14929 | |
| 14930 | PR The proxy blocked the client's HTTP request, either because of an |
| 14931 | invalid HTTP syntax, in which case it returned an HTTP 400 error to |
| 14932 | the client, or because a deny filter matched, in which case it |
| 14933 | returned an HTTP 403 error. |
| 14934 | |
| 14935 | PT The proxy blocked the client's request and has tarpitted its |
| 14936 | connection before returning it a 500 server error. Nothing was sent |
| 14937 | to the server. The connection was maintained open for as long as |
| 14938 | reported by the "Tw" timer field. |
| 14939 | |
| 14940 | RC A local resource has been exhausted (memory, sockets, source ports) |
| 14941 | preventing the connection to the server from establishing. The error |
| 14942 | logs will tell precisely what was missing. This is very rare and can |
| 14943 | only be solved by proper system tuning. |
| 14944 | |
Willy Tarreau | 996a92c | 2010-10-13 19:30:47 +0200 | [diff] [blame] | 14945 | The combination of the two last flags gives a lot of information about how |
| 14946 | persistence was handled by the client, the server and by haproxy. This is very |
| 14947 | important to troubleshoot disconnections, when users complain they have to |
| 14948 | re-authenticate. The commonly encountered flags are : |
| 14949 | |
| 14950 | -- Persistence cookie is not enabled. |
| 14951 | |
| 14952 | NN No cookie was provided by the client, none was inserted in the |
| 14953 | response. For instance, this can be in insert mode with "postonly" |
| 14954 | set on a GET request. |
| 14955 | |
| 14956 | II A cookie designating an invalid server was provided by the client, |
| 14957 | a valid one was inserted in the response. This typically happens when |
Jamie Gloudon | aaa2100 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 14958 | a "server" entry is removed from the configuration, since its cookie |
Willy Tarreau | 996a92c | 2010-10-13 19:30:47 +0200 | [diff] [blame] | 14959 | value can be presented by a client when no other server knows it. |
| 14960 | |
| 14961 | NI No cookie was provided by the client, one was inserted in the |
| 14962 | response. This typically happens for first requests from every user |
| 14963 | in "insert" mode, which makes it an easy way to count real users. |
| 14964 | |
| 14965 | VN A cookie was provided by the client, none was inserted in the |
| 14966 | response. This happens for most responses for which the client has |
| 14967 | already got a cookie. |
| 14968 | |
| 14969 | VU A cookie was provided by the client, with a last visit date which is |
| 14970 | not completely up-to-date, so an updated cookie was provided in |
| 14971 | response. This can also happen if there was no date at all, or if |
| 14972 | there was a date but the "maxidle" parameter was not set, so that the |
| 14973 | cookie can be switched to unlimited time. |
| 14974 | |
| 14975 | EI A cookie was provided by the client, with a last visit date which is |
| 14976 | too old for the "maxidle" parameter, so the cookie was ignored and a |
| 14977 | new cookie was inserted in the response. |
| 14978 | |
| 14979 | OI A cookie was provided by the client, with a first visit date which is |
| 14980 | too old for the "maxlife" parameter, so the cookie was ignored and a |
| 14981 | new cookie was inserted in the response. |
| 14982 | |
| 14983 | DI The server designated by the cookie was down, a new server was |
| 14984 | selected and a new cookie was emitted in the response. |
| 14985 | |
| 14986 | VI The server designated by the cookie was not marked dead but could not |
| 14987 | be reached. A redispatch happened and selected another one, which was |
| 14988 | then advertised in the response. |
| 14989 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14990 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 14991 | 8.6. Non-printable characters |
| 14992 | ----------------------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 14993 | |
| 14994 | In order not to cause trouble to log analysis tools or terminals during log |
| 14995 | consulting, non-printable characters are not sent as-is into log files, but are |
| 14996 | converted to the two-digits hexadecimal representation of their ASCII code, |
| 14997 | prefixed by the character '#'. The only characters that can be logged without |
| 14998 | being escaped are comprised between 32 and 126 (inclusive). Obviously, the |
| 14999 | escape character '#' itself is also encoded to avoid any ambiguity ("#23"). It |
| 15000 | is the same for the character '"' which becomes "#22", as well as '{', '|' and |
| 15001 | '}' when logging headers. |
| 15002 | |
| 15003 | Note that the space character (' ') is not encoded in headers, which can cause |
| 15004 | issues for tools relying on space count to locate fields. A typical header |
| 15005 | containing spaces is "User-Agent". |
| 15006 | |
| 15007 | Last, it has been observed that some syslog daemons such as syslog-ng escape |
| 15008 | the quote ('"') with a backslash ('\'). The reverse operation can safely be |
| 15009 | performed since no quote may appear anywhere else in the logs. |
| 15010 | |
| 15011 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 15012 | 8.7. Capturing HTTP cookies |
| 15013 | --------------------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15014 | |
| 15015 | Cookie capture simplifies the tracking a complete user session. This can be |
| 15016 | achieved using the "capture cookie" statement in the frontend. Please refer to |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 15017 | section 4.2 for more details. Only one cookie can be captured, and the same |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15018 | cookie will simultaneously be checked in the request ("Cookie:" header) and in |
| 15019 | the response ("Set-Cookie:" header). The respective values will be reported in |
| 15020 | the HTTP logs at the "captured_request_cookie" and "captured_response_cookie" |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 15021 | locations (see section 8.2.3 about HTTP log format). When either cookie is |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15022 | not seen, a dash ('-') replaces the value. This way, it's easy to detect when a |
| 15023 | user switches to a new session for example, because the server will reassign it |
| 15024 | a new cookie. It is also possible to detect if a server unexpectedly sets a |
| 15025 | wrong cookie to a client, leading to session crossing. |
| 15026 | |
| 15027 | Examples : |
| 15028 | # capture the first cookie whose name starts with "ASPSESSION" |
| 15029 | capture cookie ASPSESSION len 32 |
| 15030 | |
| 15031 | # capture the first cookie whose name is exactly "vgnvisitor" |
| 15032 | capture cookie vgnvisitor= len 32 |
| 15033 | |
| 15034 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 15035 | 8.8. Capturing HTTP headers |
| 15036 | --------------------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15037 | |
| 15038 | Header captures are useful to track unique request identifiers set by an upper |
| 15039 | proxy, virtual host names, user-agents, POST content-length, referrers, etc. In |
| 15040 | the response, one can search for information about the response length, how the |
| 15041 | server asked the cache to behave, or an object location during a redirection. |
| 15042 | |
| 15043 | Header captures are performed using the "capture request header" and "capture |
| 15044 | response header" statements in the frontend. Please consult their definition in |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 15045 | section 4.2 for more details. |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15046 | |
| 15047 | It is possible to include both request headers and response headers at the same |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 15048 | time. Non-existent headers are logged as empty strings, and if one header |
| 15049 | appears more than once, only its last occurrence will be logged. Request headers |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15050 | are grouped within braces '{' and '}' in the same order as they were declared, |
| 15051 | and delimited with a vertical bar '|' without any space. Response headers |
| 15052 | follow the same representation, but are displayed after a space following the |
| 15053 | request headers block. These blocks are displayed just before the HTTP request |
| 15054 | in the logs. |
| 15055 | |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 15056 | As a special case, it is possible to specify an HTTP header capture in a TCP |
| 15057 | frontend. The purpose is to enable logging of headers which will be parsed in |
| 15058 | an HTTP backend if the request is then switched to this HTTP backend. |
| 15059 | |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15060 | Example : |
| 15061 | # This instance chains to the outgoing proxy |
| 15062 | listen proxy-out |
| 15063 | mode http |
| 15064 | option httplog |
| 15065 | option logasap |
| 15066 | log global |
| 15067 | server cache1 192.168.1.1:3128 |
| 15068 | |
| 15069 | # log the name of the virtual server |
| 15070 | capture request header Host len 20 |
| 15071 | |
| 15072 | # log the amount of data uploaded during a POST |
| 15073 | capture request header Content-Length len 10 |
| 15074 | |
| 15075 | # log the beginning of the referrer |
| 15076 | capture request header Referer len 20 |
| 15077 | |
| 15078 | # server name (useful for outgoing proxies only) |
| 15079 | capture response header Server len 20 |
| 15080 | |
| 15081 | # logging the content-length is useful with "option logasap" |
| 15082 | capture response header Content-Length len 10 |
| 15083 | |
| 15084 | # log the expected cache behaviour on the response |
| 15085 | capture response header Cache-Control len 8 |
| 15086 | |
| 15087 | # the Via header will report the next proxy's name |
| 15088 | capture response header Via len 20 |
| 15089 | |
| 15090 | # log the URL location during a redirection |
| 15091 | capture response header Location len 20 |
| 15092 | |
| 15093 | >>> Aug 9 20:26:09 localhost \ |
| 15094 | haproxy[2022]: 127.0.0.1:34014 [09/Aug/2004:20:26:09] proxy-out \ |
| 15095 | proxy-out/cache1 0/0/0/162/+162 200 +350 - - ---- 0/0/0/0/0 0/0 \ |
| 15096 | {fr.adserver.yahoo.co||http://fr.f416.mail.} {|864|private||} \ |
| 15097 | "GET http://fr.adserver.yahoo.com/" |
| 15098 | |
| 15099 | >>> Aug 9 20:30:46 localhost \ |
| 15100 | haproxy[2022]: 127.0.0.1:34020 [09/Aug/2004:20:30:46] proxy-out \ |
| 15101 | proxy-out/cache1 0/0/0/182/+182 200 +279 - - ---- 0/0/0/0/0 0/0 \ |
| 15102 | {w.ods.org||} {Formilux/0.1.8|3495|||} \ |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 15103 | "GET http://trafic.1wt.eu/ HTTP/1.1" |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15104 | |
| 15105 | >>> Aug 9 20:30:46 localhost \ |
| 15106 | haproxy[2022]: 127.0.0.1:34028 [09/Aug/2004:20:30:46] proxy-out \ |
| 15107 | proxy-out/cache1 0/0/2/126/+128 301 +223 - - ---- 0/0/0/0/0 0/0 \ |
| 15108 | {www.sytadin.equipement.gouv.fr||http://trafic.1wt.eu/} \ |
| 15109 | {Apache|230|||http://www.sytadin.} \ |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 15110 | "GET http://www.sytadin.equipement.gouv.fr/ HTTP/1.1" |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15111 | |
| 15112 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 15113 | 8.9. Examples of logs |
| 15114 | --------------------- |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15115 | |
| 15116 | These are real-world examples of logs accompanied with an explanation. Some of |
| 15117 | them have been made up by hand. The syslog part has been removed for better |
| 15118 | reading. Their sole purpose is to explain how to decipher them. |
| 15119 | |
| 15120 | >>> haproxy[674]: 127.0.0.1:33318 [15/Oct/2003:08:31:57.130] px-http \ |
| 15121 | px-http/srv1 6559/0/7/147/6723 200 243 - - ---- 5/3/3/1/0 0/0 \ |
| 15122 | "HEAD / HTTP/1.0" |
| 15123 | |
| 15124 | => long request (6.5s) entered by hand through 'telnet'. The server replied |
| 15125 | in 147 ms, and the session ended normally ('----') |
| 15126 | |
| 15127 | >>> haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57.149] px-http \ |
| 15128 | px-http/srv1 6559/1230/7/147/6870 200 243 - - ---- 324/239/239/99/0 \ |
| 15129 | 0/9 "HEAD / HTTP/1.0" |
| 15130 | |
| 15131 | => Idem, but the request was queued in the global queue behind 9 other |
| 15132 | requests, and waited there for 1230 ms. |
| 15133 | |
| 15134 | >>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17.654] px-http \ |
| 15135 | px-http/srv1 9/0/7/14/+30 200 +243 - - ---- 3/3/3/1/0 0/0 \ |
| 15136 | "GET /image.iso HTTP/1.0" |
| 15137 | |
| 15138 | => request for a long data transfer. The "logasap" option was specified, so |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 15139 | the log was produced just before transferring data. The server replied in |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15140 | 14 ms, 243 bytes of headers were sent to the client, and total time from |
| 15141 | accept to first data byte is 30 ms. |
| 15142 | |
| 15143 | >>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17.925] px-http \ |
| 15144 | px-http/srv1 9/0/7/14/30 502 243 - - PH-- 3/2/2/0/0 0/0 \ |
| 15145 | "GET /cgi-bin/bug.cgi? HTTP/1.0" |
| 15146 | |
| 15147 | => the proxy blocked a server response either because of an "rspdeny" or |
| 15148 | "rspideny" filter, or because the response was improperly formatted and |
Willy Tarreau | 3c92c5f | 2011-08-28 09:45:47 +0200 | [diff] [blame] | 15149 | not HTTP-compliant, or because it blocked sensitive information which |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15150 | risked being cached. In this case, the response is replaced with a "502 |
| 15151 | bad gateway". The flags ("PH--") tell us that it was haproxy who decided |
| 15152 | to return the 502 and not the server. |
| 15153 | |
| 15154 | >>> haproxy[18113]: 127.0.0.1:34548 [15/Oct/2003:15:18:55.798] px-http \ |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 15155 | px-http/<NOSRV> -1/-1/-1/-1/8490 -1 0 - - CR-- 2/2/2/0/0 0/0 "" |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15156 | |
| 15157 | => the client never completed its request and aborted itself ("C---") after |
| 15158 | 8.5s, while the proxy was waiting for the request headers ("-R--"). |
| 15159 | Nothing was sent to any server. |
| 15160 | |
| 15161 | >>> haproxy[18113]: 127.0.0.1:34549 [15/Oct/2003:15:19:06.103] px-http \ |
| 15162 | px-http/<NOSRV> -1/-1/-1/-1/50001 408 0 - - cR-- 2/2/2/0/0 0/0 "" |
| 15163 | |
| 15164 | => The client never completed its request, which was aborted by the |
| 15165 | time-out ("c---") after 50s, while the proxy was waiting for the request |
| 15166 | headers ("-R--"). Nothing was sent to any server, but the proxy could |
| 15167 | send a 408 return code to the client. |
| 15168 | |
| 15169 | >>> haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28.312] px-tcp \ |
| 15170 | px-tcp/srv1 0/0/5007 0 cD 0/0/0/0/0 0/0 |
| 15171 | |
| 15172 | => This log was produced with "option tcplog". The client timed out after |
| 15173 | 5 seconds ("c----"). |
| 15174 | |
| 15175 | >>> haproxy[18989]: 10.0.0.1:34552 [15/Oct/2003:15:26:31.462] px-http \ |
| 15176 | px-http/srv1 3183/-1/-1/-1/11215 503 0 - - SC-- 205/202/202/115/3 \ |
Willy Tarreau | d72758d | 2010-01-12 10:42:19 +0100 | [diff] [blame] | 15177 | 0/0 "HEAD / HTTP/1.0" |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15178 | |
| 15179 | => The request took 3s to complete (probably a network problem), and the |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 15180 | connection to the server failed ('SC--') after 4 attempts of 2 seconds |
Willy Tarreau | cc6c891 | 2009-02-22 10:53:55 +0100 | [diff] [blame] | 15181 | (config says 'retries 3'), and no redispatch (otherwise we would have |
| 15182 | seen "/+3"). Status code 503 was returned to the client. There were 115 |
| 15183 | connections on this server, 202 connections on this proxy, and 205 on |
| 15184 | the global process. It is possible that the server refused the |
| 15185 | connection because of too many already established. |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 15186 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 15187 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 15188 | 9. Statistics and monitoring |
| 15189 | ---------------------------- |
| 15190 | |
| 15191 | It is possible to query HAProxy about its status. The most commonly used |
| 15192 | mechanism is the HTTP statistics page. This page also exposes an alternative |
| 15193 | CSV output format for monitoring tools. The same format is provided on the |
| 15194 | Unix socket. |
| 15195 | |
| 15196 | |
| 15197 | 9.1. CSV format |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 15198 | --------------- |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 15199 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 15200 | The statistics may be consulted either from the unix socket or from the HTTP |
Willy Tarreau | a3310dc | 2014-06-16 15:43:21 +0200 | [diff] [blame] | 15201 | page. Both means provide a CSV format whose fields follow. The first line |
| 15202 | begins with a sharp ('#') and has one word per comma-delimited field which |
| 15203 | represents the title of the column. All other lines starting at the second one |
| 15204 | use a classical CSV format using a comma as the delimiter, and the double quote |
| 15205 | ('"') as an optional text delimiter, but only if the enclosed text is ambiguous |
| 15206 | (if it contains a quote or a comma). The double-quote character ('"') in the |
| 15207 | text is doubled ('""'), which is the format that most tools recognize. Please |
| 15208 | do not insert any column before these ones in order not to break tools which |
| 15209 | use hard-coded column positions. |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 15210 | |
James Westby | ebe62d6 | 2014-07-08 10:14:57 -0400 | [diff] [blame] | 15211 | In brackets after each field name are the types which may have a value for |
| 15212 | that field. The types are L (Listeners), F (Frontends), B (Backends), and |
| 15213 | S (Servers). |
| 15214 | |
| 15215 | 0. pxname [LFBS]: proxy name |
| 15216 | 1. svname [LFBS]: service name (FRONTEND for frontend, BACKEND for backend, |
| 15217 | any name for server/listener) |
| 15218 | 2. qcur [..BS]: current queued requests. For the backend this reports the |
| 15219 | number queued without a server assigned. |
| 15220 | 3. qmax [..BS]: max value of qcur |
| 15221 | 4. scur [LFBS]: current sessions |
| 15222 | 5. smax [LFBS]: max sessions |
| 15223 | 6. slim [LFBS]: configured session limit |
| 15224 | 7. stot [LFBS]: cumulative number of connections |
| 15225 | 8. bin [LFBS]: bytes in |
| 15226 | 9. bout [LFBS]: bytes out |
| 15227 | 10. dreq [LFB.]: requests denied because of security concerns. |
| 15228 | - For tcp this is because of a matched tcp-request content rule. |
| 15229 | - For http this is because of a matched http-request or tarpit rule. |
| 15230 | 11. dresp [LFBS]: responses denied because of security concerns. |
| 15231 | - For http this is because of a matched http-request rule, or |
| 15232 | "option checkcache". |
| 15233 | 12. ereq [LF..]: request errors. Some of the possible causes are: |
| 15234 | - early termination from the client, before the request has been sent. |
| 15235 | - read error from the client |
| 15236 | - client timeout |
| 15237 | - client closed connection |
| 15238 | - various bad requests from the client. |
| 15239 | - request was tarpitted. |
| 15240 | 13. econ [..BS]: number of requests that encountered an error trying to |
| 15241 | connect to a backend server. The backend stat is the sum of the stat |
| 15242 | for all servers of that backend, plus any connection errors not |
| 15243 | associated with a particular server (such as the backend having no |
| 15244 | active servers). |
| 15245 | 14. eresp [..BS]: response errors. srv_abrt will be counted here also. |
| 15246 | Some other errors are: |
| 15247 | - write error on the client socket (won't be counted for the server stat) |
| 15248 | - failure applying filters to the response. |
| 15249 | 15. wretr [..BS]: number of times a connection to a server was retried. |
| 15250 | 16. wredis [..BS]: number of times a request was redispatched to another |
| 15251 | server. The server value counts the number of times that server was |
| 15252 | switched away from. |
| 15253 | 17. status [LFBS]: status (UP/DOWN/NOLB/MAINT/MAINT(via)...) |
Pavlos Parissis | 1f673c7 | 2015-05-02 20:30:44 +0200 | [diff] [blame] | 15254 | 18. weight [..BS]: total weight (backend), server weight (server) |
| 15255 | 19. act [..BS]: number of active servers (backend), server is active (server) |
| 15256 | 20. bck [..BS]: number of backup servers (backend), server is backup (server) |
James Westby | ebe62d6 | 2014-07-08 10:14:57 -0400 | [diff] [blame] | 15257 | 21. chkfail [...S]: number of failed checks. (Only counts checks failed when |
| 15258 | the server is up.) |
| 15259 | 22. chkdown [..BS]: number of UP->DOWN transitions. The backend counter counts |
| 15260 | transitions to the whole backend being down, rather than the sum of the |
| 15261 | counters for each server. |
| 15262 | 23. lastchg [..BS]: number of seconds since the last UP<->DOWN transition |
| 15263 | 24. downtime [..BS]: total downtime (in seconds). The value for the backend |
| 15264 | is the downtime for the whole backend, not the sum of the server downtime. |
| 15265 | 25. qlimit [...S]: configured maxqueue for the server, or nothing in the |
| 15266 | value is 0 (default, meaning no limit) |
| 15267 | 26. pid [LFBS]: process id (0 for first instance, 1 for second, ...) |
| 15268 | 27. iid [LFBS]: unique proxy id |
| 15269 | 28. sid [L..S]: server id (unique inside a proxy) |
| 15270 | 29. throttle [...S]: current throttle percentage for the server, when |
| 15271 | slowstart is active, or no value if not in slowstart. |
| 15272 | 30. lbtot [..BS]: total number of times a server was selected, either for new |
| 15273 | sessions, or when re-dispatching. The server counter is the number |
| 15274 | of times that server was selected. |
| 15275 | 31. tracked [...S]: id of proxy/server if tracking is enabled. |
| 15276 | 32. type [LFBS]: (0=frontend, 1=backend, 2=server, 3=socket/listener) |
| 15277 | 33. rate [.FBS]: number of sessions per second over last elapsed second |
| 15278 | 34. rate_lim [.F..]: configured limit on new sessions per second |
| 15279 | 35. rate_max [.FBS]: max number of new sessions per second |
| 15280 | 36. check_status [...S]: status of last health check, one of: |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 15281 | UNK -> unknown |
| 15282 | INI -> initializing |
| 15283 | SOCKERR -> socket error |
| 15284 | L4OK -> check passed on layer 4, no upper layers testing enabled |
Jason Harvey | 8310480 | 2015-04-16 11:13:21 -0800 | [diff] [blame] | 15285 | L4TOUT -> layer 1-4 timeout |
Cyril Bonté | f0c6061 | 2010-02-06 14:44:47 +0100 | [diff] [blame] | 15286 | L4CON -> layer 1-4 connection problem, for example |
| 15287 | "Connection refused" (tcp rst) or "No route to host" (icmp) |
| 15288 | L6OK -> check passed on layer 6 |
| 15289 | L6TOUT -> layer 6 (SSL) timeout |
| 15290 | L6RSP -> layer 6 invalid response - protocol error |
| 15291 | L7OK -> check passed on layer 7 |
| 15292 | L7OKC -> check conditionally passed on layer 7, for example 404 with |
| 15293 | disable-on-404 |
| 15294 | L7TOUT -> layer 7 (HTTP/SMTP) timeout |
| 15295 | L7RSP -> layer 7 invalid response - protocol error |
| 15296 | L7STS -> layer 7 response error, for example HTTP 5xx |
James Westby | ebe62d6 | 2014-07-08 10:14:57 -0400 | [diff] [blame] | 15297 | 37. check_code [...S]: layer5-7 code, if available |
| 15298 | 38. check_duration [...S]: time in ms took to finish last health check |
| 15299 | 39. hrsp_1xx [.FBS]: http responses with 1xx code |
| 15300 | 40. hrsp_2xx [.FBS]: http responses with 2xx code |
| 15301 | 41. hrsp_3xx [.FBS]: http responses with 3xx code |
| 15302 | 42. hrsp_4xx [.FBS]: http responses with 4xx code |
| 15303 | 43. hrsp_5xx [.FBS]: http responses with 5xx code |
| 15304 | 44. hrsp_other [.FBS]: http responses with other codes (protocol error) |
| 15305 | 45. hanafail [...S]: failed health checks details |
| 15306 | 46. req_rate [.F..]: HTTP requests per second over last elapsed second |
| 15307 | 47. req_rate_max [.F..]: max number of HTTP requests per second observed |
| 15308 | 48. req_tot [.F..]: total number of HTTP requests received |
| 15309 | 49. cli_abrt [..BS]: number of data transfers aborted by the client |
| 15310 | 50. srv_abrt [..BS]: number of data transfers aborted by the server |
| 15311 | (inc. in eresp) |
| 15312 | 51. comp_in [.FB.]: number of HTTP response bytes fed to the compressor |
| 15313 | 52. comp_out [.FB.]: number of HTTP response bytes emitted by the compressor |
| 15314 | 53. comp_byp [.FB.]: number of bytes that bypassed the HTTP compressor |
| 15315 | (CPU/BW limit) |
| 15316 | 54. comp_rsp [.FB.]: number of HTTP responses that were compressed |
| 15317 | 55. lastsess [..BS]: number of seconds since last session assigned to |
| 15318 | server/backend |
| 15319 | 56. last_chk [...S]: last health check contents or textual error |
| 15320 | 57. last_agt [...S]: last agent check contents or textual error |
| 15321 | 58. qtime [..BS]: the average queue time in ms over the 1024 last requests |
| 15322 | 59. ctime [..BS]: the average connect time in ms over the 1024 last requests |
| 15323 | 60. rtime [..BS]: the average response time in ms over the 1024 last requests |
| 15324 | (0 for TCP) |
| 15325 | 61. ttime [..BS]: the average total session time in ms over the 1024 last |
| 15326 | requests |
Willy Tarreau | 844e3c5 | 2008-01-11 16:28:18 +0100 | [diff] [blame] | 15327 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 15328 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 15329 | 9.2. Unix Socket commands |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 15330 | ------------------------- |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 15331 | |
Willy Tarreau | 468f493 | 2013-08-01 16:50:16 +0200 | [diff] [blame] | 15332 | The stats socket is not enabled by default. In order to enable it, it is |
| 15333 | necessary to add one line in the global section of the haproxy configuration. |
| 15334 | A second line is recommended to set a larger timeout, always appreciated when |
| 15335 | issuing commands by hand : |
| 15336 | |
| 15337 | global |
| 15338 | stats socket /var/run/haproxy.sock mode 600 level admin |
| 15339 | stats timeout 2m |
| 15340 | |
| 15341 | It is also possible to add multiple instances of the stats socket by repeating |
| 15342 | the line, and make them listen to a TCP port instead of a UNIX socket. This is |
| 15343 | never done by default because this is dangerous, but can be handy in some |
| 15344 | situations : |
| 15345 | |
| 15346 | global |
| 15347 | stats socket /var/run/haproxy.sock mode 600 level admin |
| 15348 | stats socket ipv4@192.168.0.1:9999 level admin |
| 15349 | stats timeout 2m |
| 15350 | |
| 15351 | To access the socket, an external utility such as "socat" is required. Socat is a |
| 15352 | swiss-army knife to connect anything to anything. We use it to connect terminals |
| 15353 | to the socket, or a couple of stdin/stdout pipes to it for scripts. The two main |
| 15354 | syntaxes we'll use are the following : |
| 15355 | |
| 15356 | # socat /var/run/haproxy.sock stdio |
| 15357 | # socat /var/run/haproxy.sock readline |
| 15358 | |
| 15359 | The first one is used with scripts. It is possible to send the output of a |
| 15360 | script to haproxy, and pass haproxy's output to another script. That's useful |
| 15361 | for retrieving counters or attack traces for example. |
| 15362 | |
| 15363 | The second one is only useful for issuing commands by hand. It has the benefit |
| 15364 | that the terminal is handled by the readline library which supports line |
| 15365 | editing and history, which is very convenient when issuing repeated commands |
| 15366 | (eg: watch a counter). |
| 15367 | |
| 15368 | The socket supports two operation modes : |
| 15369 | - interactive |
| 15370 | - non-interactive |
| 15371 | |
| 15372 | The non-interactive mode is the default when socat connects to the socket. In |
| 15373 | this mode, a single line may be sent. It is processed as a whole, responses are |
| 15374 | sent back, and the connection closes after the end of the response. This is the |
| 15375 | mode that scripts and monitoring tools use. It is possible to send multiple |
| 15376 | commands in this mode, they need to be delimited by a semi-colon (';'). For |
| 15377 | example : |
| 15378 | |
| 15379 | # echo "show info;show stat;show table" | socat /var/run/haproxy stdio |
| 15380 | |
| 15381 | The interactive mode displays a prompt ('>') and waits for commands to be |
| 15382 | entered on the line, then processes them, and displays the prompt again to wait |
| 15383 | for a new command. This mode is entered via the "prompt" command which must be |
| 15384 | sent on the first line in non-interactive mode. The mode is a flip switch, if |
| 15385 | "prompt" is sent in interactive mode, it is disabled and the connection closes |
| 15386 | after processing the last command of the same line. |
| 15387 | |
| 15388 | For this reason, when debugging by hand, it's quite common to start with the |
| 15389 | "prompt" command : |
| 15390 | |
| 15391 | # socat /var/run/haproxy readline |
| 15392 | prompt |
| 15393 | > show info |
| 15394 | ... |
| 15395 | > |
| 15396 | |
| 15397 | Since multiple commands may be issued at once, haproxy uses the empty line as a |
| 15398 | delimiter to mark an end of output for each command, and takes care of ensuring |
| 15399 | that no command can emit an empty line on output. A script can thus easily |
| 15400 | parse the output even when multiple commands were pipelined on a single line. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 15401 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 15402 | It is important to understand that when multiple haproxy processes are started |
| 15403 | on the same sockets, any process may pick up the request and will output its |
| 15404 | own stats. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 15405 | |
Willy Tarreau | 468f493 | 2013-08-01 16:50:16 +0200 | [diff] [blame] | 15406 | The list of commands currently supported on the stats socket is provided below. |
| 15407 | If an unknown command is sent, haproxy displays the usage message which reminds |
| 15408 | all supported commands. Some commands support a more complex syntax, generally |
| 15409 | it will explain what part of the command is invalid when this happens. |
| 15410 | |
Thierry FOURNIER | d32079e | 2014-01-29 20:02:04 +0100 | [diff] [blame] | 15411 | add acl <acl> <pattern> |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 15412 | Add an entry into the acl <acl>. <acl> is the #<id> or the <file> returned by |
| 15413 | "show acl". This command does not verify if the entry already exists. This |
| 15414 | command cannot be used if the reference <acl> is a file also used with a map. |
| 15415 | In this case, you must use the command "add map" in place of "add acl". |
Thierry FOURNIER | d32079e | 2014-01-29 20:02:04 +0100 | [diff] [blame] | 15416 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 15417 | add map <map> <key> <value> |
| 15418 | Add an entry into the map <map> to associate the value <value> to the key |
| 15419 | <key>. This command does not verify if the entry already exists. It is |
Thierry FOURNIER | d32079e | 2014-01-29 20:02:04 +0100 | [diff] [blame] | 15420 | mainly used to fill a map after a clear operation. Note that if the reference |
| 15421 | <map> is a file and is shared with a map, this map will contain also a new |
| 15422 | pattern entry. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 15423 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 15424 | clear counters |
| 15425 | Clear the max values of the statistics counters in each proxy (frontend & |
| 15426 | backend) and in each server. The cumulated counters are not affected. This |
| 15427 | can be used to get clean counters after an incident, without having to |
| 15428 | restart nor to clear traffic counters. This command is restricted and can |
| 15429 | only be issued on sockets configured for levels "operator" or "admin". |
| 15430 | |
| 15431 | clear counters all |
| 15432 | Clear all statistics counters in each proxy (frontend & backend) and in each |
| 15433 | server. This has the same effect as restarting. This command is restricted |
| 15434 | and can only be issued on sockets configured for level "admin". |
| 15435 | |
Thierry FOURNIER | d32079e | 2014-01-29 20:02:04 +0100 | [diff] [blame] | 15436 | clear acl <acl> |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 15437 | Remove all entries from the acl <acl>. <acl> is the #<id> or the <file> |
| 15438 | returned by "show acl". Note that if the reference <acl> is a file and is |
| 15439 | shared with a map, this map will be also cleared. |
Thierry FOURNIER | d32079e | 2014-01-29 20:02:04 +0100 | [diff] [blame] | 15440 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 15441 | clear map <map> |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 15442 | Remove all entries from the map <map>. <map> is the #<id> or the <file> |
| 15443 | returned by "show map". Note that if the reference <map> is a file and is |
| 15444 | shared with a acl, this acl will be also cleared. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 15445 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 15446 | clear table <table> [ data.<type> <operator> <value> ] | [ key <key> ] |
| 15447 | Remove entries from the stick-table <table>. |
| 15448 | |
| 15449 | This is typically used to unblock some users complaining they have been |
| 15450 | abusively denied access to a service, but this can also be used to clear some |
| 15451 | stickiness entries matching a server that is going to be replaced (see "show |
| 15452 | table" below for details). Note that sometimes, removal of an entry will be |
| 15453 | refused because it is currently tracked by a session. Retrying a few seconds |
| 15454 | later after the session ends is usual enough. |
| 15455 | |
| 15456 | In the case where no options arguments are given all entries will be removed. |
| 15457 | |
| 15458 | When the "data." form is used entries matching a filter applied using the |
| 15459 | stored data (see "stick-table" in section 4.2) are removed. A stored data |
| 15460 | type must be specified in <type>, and this data type must be stored in the |
| 15461 | table otherwise an error is reported. The data is compared according to |
| 15462 | <operator> with the 64-bit integer <value>. Operators are the same as with |
| 15463 | the ACLs : |
| 15464 | |
| 15465 | - eq : match entries whose data is equal to this value |
| 15466 | - ne : match entries whose data is not equal to this value |
| 15467 | - le : match entries whose data is less than or equal to this value |
| 15468 | - ge : match entries whose data is greater than or equal to this value |
| 15469 | - lt : match entries whose data is less than this value |
| 15470 | - gt : match entries whose data is greater than this value |
| 15471 | |
| 15472 | When the key form is used the entry <key> is removed. The key must be of the |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 15473 | same type as the table, which currently is limited to IPv4, IPv6, integer and |
| 15474 | string. |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 15475 | |
| 15476 | Example : |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 15477 | $ echo "show table http_proxy" | socat stdio /tmp/sock1 |
Emeric Brun | 7c6b82e | 2010-09-24 16:34:28 +0200 | [diff] [blame] | 15478 | >>> # table: http_proxy, type: ip, size:204800, used:2 |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 15479 | >>> 0x80e6a4c: key=127.0.0.1 use=0 exp=3594729 gpc0=0 conn_rate(30000)=1 \ |
| 15480 | bytes_out_rate(60000)=187 |
| 15481 | >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \ |
| 15482 | bytes_out_rate(60000)=191 |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 15483 | |
| 15484 | $ echo "clear table http_proxy key 127.0.0.1" | socat stdio /tmp/sock1 |
| 15485 | |
| 15486 | $ echo "show table http_proxy" | socat stdio /tmp/sock1 |
Emeric Brun | 7c6b82e | 2010-09-24 16:34:28 +0200 | [diff] [blame] | 15487 | >>> # table: http_proxy, type: ip, size:204800, used:1 |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 15488 | >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \ |
| 15489 | bytes_out_rate(60000)=191 |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 15490 | $ echo "clear table http_proxy data.gpc0 eq 1" | socat stdio /tmp/sock1 |
| 15491 | $ echo "show table http_proxy" | socat stdio /tmp/sock1 |
| 15492 | >>> # table: http_proxy, type: ip, size:204800, used:1 |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 15493 | |
Thierry FOURNIER | d32079e | 2014-01-29 20:02:04 +0100 | [diff] [blame] | 15494 | del acl <acl> [<key>|#<ref>] |
| 15495 | Delete all the acl entries from the acl <acl> corresponding to the key <key>. |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 15496 | <acl> is the #<id> or the <file> returned by "show acl". If the <ref> is used, |
| 15497 | this command delete only the listed reference. The reference can be found with |
| 15498 | listing the content of the acl. Note that if the reference <acl> is a file and |
| 15499 | is shared with a map, the entry will be also deleted in the map. |
Thierry FOURNIER | d32079e | 2014-01-29 20:02:04 +0100 | [diff] [blame] | 15500 | |
| 15501 | del map <map> [<key>|#<ref>] |
Thierry FOURNIER | 0b90f31 | 2014-01-29 20:40:18 +0100 | [diff] [blame] | 15502 | Delete all the map entries from the map <map> corresponding to the key <key>. |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 15503 | <map> is the #<id> or the <file> returned by "show map". If the <ref> is used, |
| 15504 | this command delete only the listed reference. The reference can be found with |
| 15505 | listing the content of the map. Note that if the reference <map> is a file and |
| 15506 | is shared with a acl, the entry will be also deleted in the map. |
Thierry FOURNIER | 0b90f31 | 2014-01-29 20:40:18 +0100 | [diff] [blame] | 15507 | |
| 15508 | disable agent <backend>/<server> |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 15509 | Mark the auxiliary agent check as temporarily stopped. |
| 15510 | |
| 15511 | In the case where an agent check is being run as a auxiliary check, due |
| 15512 | to the agent-check parameter of a server directive, new checks are only |
| 15513 | initialised when the agent is in the enabled. Thus, disable agent will |
| 15514 | prevent any new agent checks from begin initiated until the agent |
| 15515 | re-enabled using enable agent. |
| 15516 | |
| 15517 | When an agent is disabled the processing of an auxiliary agent check that |
| 15518 | was initiated while the agent was set as enabled is as follows: All |
| 15519 | results that would alter the weight, specifically "drain" or a weight |
| 15520 | returned by the agent, are ignored. The processing of agent check is |
| 15521 | otherwise unchanged. |
| 15522 | |
| 15523 | The motivation for this feature is to allow the weight changing effects |
| 15524 | of the agent checks to be paused to allow the weight of a server to be |
| 15525 | configured using set weight without being overridden by the agent. |
| 15526 | |
| 15527 | This command is restricted and can only be issued on sockets configured for |
| 15528 | level "admin". |
| 15529 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 15530 | disable frontend <frontend> |
| 15531 | Mark the frontend as temporarily stopped. This corresponds to the mode which |
| 15532 | is used during a soft restart : the frontend releases the port but can be |
| 15533 | enabled again if needed. This should be used with care as some non-Linux OSes |
| 15534 | are unable to enable it back. This is intended to be used in environments |
| 15535 | where stopping a proxy is not even imaginable but a misconfigured proxy must |
| 15536 | be fixed. That way it's possible to release the port and bind it into another |
| 15537 | process to restore operations. The frontend will appear with status "STOP" |
| 15538 | on the stats page. |
| 15539 | |
| 15540 | The frontend may be specified either by its name or by its numeric ID, |
| 15541 | prefixed with a sharp ('#'). |
| 15542 | |
| 15543 | This command is restricted and can only be issued on sockets configured for |
| 15544 | level "admin". |
| 15545 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 15546 | disable health <backend>/<server> |
| 15547 | Mark the primary health check as temporarily stopped. This will disable |
| 15548 | sending of health checks, and the last health check result will be ignored. |
| 15549 | The server will be in unchecked state and considered UP unless an auxiliary |
| 15550 | agent check forces it down. |
| 15551 | |
| 15552 | This command is restricted and can only be issued on sockets configured for |
| 15553 | level "admin". |
| 15554 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 15555 | disable server <backend>/<server> |
| 15556 | Mark the server DOWN for maintenance. In this mode, no more checks will be |
| 15557 | performed on the server until it leaves maintenance. |
| 15558 | If the server is tracked by other servers, those servers will be set to DOWN |
| 15559 | during the maintenance. |
| 15560 | |
| 15561 | In the statistics page, a server DOWN for maintenance will appear with a |
| 15562 | "MAINT" status, its tracking servers with the "MAINT(via)" one. |
| 15563 | |
| 15564 | Both the backend and the server may be specified either by their name or by |
Willy Tarreau | f5f3192 | 2011-08-02 11:32:07 +0200 | [diff] [blame] | 15565 | their numeric ID, prefixed with a sharp ('#'). |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 15566 | |
| 15567 | This command is restricted and can only be issued on sockets configured for |
| 15568 | level "admin". |
| 15569 | |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 15570 | enable agent <backend>/<server> |
| 15571 | Resume auxiliary agent check that was temporarily stopped. |
| 15572 | |
| 15573 | See "disable agent" for details of the effect of temporarily starting |
| 15574 | and stopping an auxiliary agent. |
| 15575 | |
| 15576 | This command is restricted and can only be issued on sockets configured for |
| 15577 | level "admin". |
| 15578 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 15579 | enable frontend <frontend> |
| 15580 | Resume a frontend which was temporarily stopped. It is possible that some of |
| 15581 | the listening ports won't be able to bind anymore (eg: if another process |
| 15582 | took them since the 'disable frontend' operation). If this happens, an error |
| 15583 | is displayed. Some operating systems might not be able to resume a frontend |
| 15584 | which was disabled. |
| 15585 | |
| 15586 | The frontend may be specified either by its name or by its numeric ID, |
| 15587 | prefixed with a sharp ('#'). |
| 15588 | |
| 15589 | This command is restricted and can only be issued on sockets configured for |
| 15590 | level "admin". |
| 15591 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 15592 | enable health <backend>/<server> |
| 15593 | Resume a primary health check that was temporarily stopped. This will enable |
| 15594 | sending of health checks again. Please see "disable health" for details. |
| 15595 | |
| 15596 | This command is restricted and can only be issued on sockets configured for |
| 15597 | level "admin". |
| 15598 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 15599 | enable server <backend>/<server> |
| 15600 | If the server was previously marked as DOWN for maintenance, this marks the |
| 15601 | server UP and checks are re-enabled. |
| 15602 | |
| 15603 | Both the backend and the server may be specified either by their name or by |
Willy Tarreau | f5f3192 | 2011-08-02 11:32:07 +0200 | [diff] [blame] | 15604 | their numeric ID, prefixed with a sharp ('#'). |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 15605 | |
| 15606 | This command is restricted and can only be issued on sockets configured for |
| 15607 | level "admin". |
| 15608 | |
Thierry FOURNIER | 5b16df7 | 2014-02-26 18:07:38 +0100 | [diff] [blame] | 15609 | get map <map> <value> |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 15610 | get acl <acl> <value> |
| 15611 | Lookup the value <value> in the map <map> or in the ACL <acl>. <map> or <acl> |
| 15612 | are the #<id> or the <file> returned by "show map" or "show acl". This command |
| 15613 | returns all the matching patterns associated with this map. This is useful for |
| 15614 | debugging maps and ACLs. The output format is composed by one line par |
| 15615 | matching type. Each line is composed by space-delimited series of words. |
Thierry FOURNIER | 5b16df7 | 2014-02-26 18:07:38 +0100 | [diff] [blame] | 15616 | |
| 15617 | The first two words are: |
| 15618 | |
| 15619 | <match method>: The match method applied. It can be "found", "bool", |
| 15620 | "int", "ip", "bin", "len", "str", "beg", "sub", "dir", |
| 15621 | "dom", "end" or "reg". |
| 15622 | |
| 15623 | <match result>: The result. Can be "match" or "no-match". |
| 15624 | |
| 15625 | The following words are returned only if the pattern matches an entry. |
| 15626 | |
| 15627 | <index type>: "tree" or "list". The internal lookup algorithm. |
| 15628 | |
| 15629 | <case>: "case-insensitive" or "case-sensitive". The |
| 15630 | interpretation of the case. |
| 15631 | |
| 15632 | <entry matched>: match="<entry>". Return the matched pattern. It is |
| 15633 | useful with regular expressions. |
| 15634 | |
| 15635 | The two last word are used to show the returned value and its type. With the |
| 15636 | "acl" case, the pattern doesn't exist. |
| 15637 | |
| 15638 | return=nothing: No return because there are no "map". |
| 15639 | return="<value>": The value returned in the string format. |
| 15640 | return=cannot-display: The value cannot be converted as string. |
| 15641 | |
| 15642 | type="<type>": The type of the returned sample. |
| 15643 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 15644 | get weight <backend>/<server> |
| 15645 | Report the current weight and the initial weight of server <server> in |
| 15646 | backend <backend> or an error if either doesn't exist. The initial weight is |
| 15647 | the one that appears in the configuration file. Both are normally equal |
| 15648 | unless the current weight has been changed. Both the backend and the server |
| 15649 | may be specified either by their name or by their numeric ID, prefixed with a |
Willy Tarreau | f5f3192 | 2011-08-02 11:32:07 +0200 | [diff] [blame] | 15650 | sharp ('#'). |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 15651 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 15652 | help |
| 15653 | Print the list of known keywords and their basic usage. The same help screen |
| 15654 | is also displayed for unknown commands. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 15655 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 15656 | prompt |
| 15657 | Toggle the prompt at the beginning of the line and enter or leave interactive |
| 15658 | mode. In interactive mode, the connection is not closed after a command |
| 15659 | completes. Instead, the prompt will appear again, indicating the user that |
| 15660 | the interpreter is waiting for a new command. The prompt consists in a right |
| 15661 | angle bracket followed by a space "> ". This mode is particularly convenient |
| 15662 | when one wants to periodically check information such as stats or errors. |
| 15663 | It is also a good idea to enter interactive mode before issuing a "help" |
| 15664 | command. |
| 15665 | |
| 15666 | quit |
| 15667 | Close the connection when in interactive mode. |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 15668 | |
Thierry FOURNIER | d32079e | 2014-01-29 20:02:04 +0100 | [diff] [blame] | 15669 | set map <map> [<key>|#<ref>] <value> |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 15670 | Modify the value corresponding to each key <key> in a map <map>. <map> is the |
| 15671 | #<id> or <file> returned by "show map". If the <ref> is used in place of |
| 15672 | <key>, only the entry pointed by <ref> is changed. The new value is <value>. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 15673 | |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 15674 | set maxconn frontend <frontend> <value> |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 15675 | Dynamically change the specified frontend's maxconn setting. Any positive |
| 15676 | value is allowed including zero, but setting values larger than the global |
| 15677 | maxconn does not make much sense. If the limit is increased and connections |
| 15678 | were pending, they will immediately be accepted. If it is lowered to a value |
| 15679 | below the current number of connections, new connections acceptation will be |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 15680 | delayed until the threshold is reached. The frontend might be specified by |
| 15681 | either its name or its numeric ID prefixed with a sharp ('#'). |
| 15682 | |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 15683 | set maxconn global <maxconn> |
| 15684 | Dynamically change the global maxconn setting within the range defined by the |
| 15685 | initial global maxconn setting. If it is increased and connections were |
| 15686 | pending, they will immediately be accepted. If it is lowered to a value below |
| 15687 | the current number of connections, new connections acceptation will be |
| 15688 | delayed until the threshold is reached. A value of zero restores the initial |
| 15689 | setting. |
| 15690 | |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 15691 | set rate-limit connections global <value> |
| 15692 | Change the process-wide connection rate limit, which is set by the global |
| 15693 | 'maxconnrate' setting. A value of zero disables the limitation. This limit |
| 15694 | applies to all frontends and the change has an immediate effect. The value |
| 15695 | is passed in number of connections per second. |
| 15696 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 15697 | set rate-limit http-compression global <value> |
| 15698 | Change the maximum input compression rate, which is set by the global |
| 15699 | 'maxcomprate' setting. A value of zero disables the limitation. The value is |
William Lallemand | 096f554 | 2012-11-19 17:26:05 +0100 | [diff] [blame] | 15700 | passed in number of kilobytes per second. The value is available in the "show |
| 15701 | info" on the line "CompressBpsRateLim" in bytes. |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 15702 | |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 15703 | set rate-limit sessions global <value> |
| 15704 | Change the process-wide session rate limit, which is set by the global |
| 15705 | 'maxsessrate' setting. A value of zero disables the limitation. This limit |
| 15706 | applies to all frontends and the change has an immediate effect. The value |
| 15707 | is passed in number of sessions per second. |
| 15708 | |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 15709 | set rate-limit ssl-sessions global <value> |
| 15710 | Change the process-wide SSL session rate limit, which is set by the global |
| 15711 | 'maxsslrate' setting. A value of zero disables the limitation. This limit |
| 15712 | applies to all frontends and the change has an immediate effect. The value |
| 15713 | is passed in number of sessions per second sent to the SSL stack. It applies |
| 15714 | before the handshake in order to protect the stack against handshake abuses. |
| 15715 | |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 15716 | set server <backend>/<server> addr <ip4 or ip6 address> |
| 15717 | Replace the current IP address of a server by the one provided. |
| 15718 | |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 15719 | set server <backend>/<server> agent [ up | down ] |
| 15720 | Force a server's agent to a new state. This can be useful to immediately |
| 15721 | switch a server's state regardless of some slow agent checks for example. |
| 15722 | Note that the change is propagated to tracking servers if any. |
| 15723 | |
| 15724 | set server <backend>/<server> health [ up | stopping | down ] |
| 15725 | Force a server's health to a new state. This can be useful to immediately |
| 15726 | switch a server's state regardless of some slow health checks for example. |
| 15727 | Note that the change is propagated to tracking servers if any. |
| 15728 | |
| 15729 | set server <backend>/<server> state [ ready | drain | maint ] |
| 15730 | Force a server's administrative state to a new state. This can be useful to |
| 15731 | disable load balancing and/or any traffic to a server. Setting the state to |
| 15732 | "ready" puts the server in normal mode, and the command is the equivalent of |
| 15733 | the "enable server" command. Setting the state to "maint" disables any traffic |
| 15734 | to the server as well as any health checks. This is the equivalent of the |
| 15735 | "disable server" command. Setting the mode to "drain" only removes the server |
| 15736 | from load balancing but still allows it to be checked and to accept new |
| 15737 | persistent connections. Changes are propagated to tracking servers if any. |
| 15738 | |
| 15739 | set server <backend>/<server> weight <weight>[%] |
| 15740 | Change a server's weight to the value passed in argument. This is the exact |
| 15741 | equivalent of the "set weight" command below. |
| 15742 | |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 15743 | set ssl ocsp-response <response> |
| 15744 | This command is used to update an OCSP Response for a certificate (see "crt" |
| 15745 | on "bind" lines). Same controls are performed as during the initial loading of |
| 15746 | the response. The <response> must be passed as a base64 encoded string of the |
| 15747 | DER encoded response from the OCSP server. |
| 15748 | |
| 15749 | Example: |
| 15750 | openssl ocsp -issuer issuer.pem -cert server.pem \ |
| 15751 | -host ocsp.issuer.com:80 -respout resp.der |
| 15752 | echo "set ssl ocsp-response $(base64 -w 10000 resp.der)" | \ |
| 15753 | socat stdio /var/run/haproxy.stat |
| 15754 | |
Nenad Merdanovic | c6985f0 | 2015-05-09 08:46:02 +0200 | [diff] [blame] | 15755 | set ssl tls-key <id> <tlskey> |
| 15756 | Set the next TLS key for the <id> listener to <tlskey>. This key becomes the |
| 15757 | ultimate key, while the penultimate one is used for encryption (others just |
| 15758 | decrypt). The oldest TLS key present is overwritten. <id> is either a numeric |
| 15759 | #<id> or <file> returned by "show tls-keys". <tlskey> is a base64 encoded 48 |
| 15760 | bit TLS ticket key (ex. openssl rand -base64 48). |
| 15761 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 15762 | set table <table> key <key> [data.<data_type> <value>]* |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 15763 | Create or update a stick-table entry in the table. If the key is not present, |
| 15764 | an entry is inserted. See stick-table in section 4.2 to find all possible |
| 15765 | values for <data_type>. The most likely use consists in dynamically entering |
| 15766 | entries for source IP addresses, with a flag in gpc0 to dynamically block an |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 15767 | IP address or affect its quality of service. It is possible to pass multiple |
| 15768 | data_types in a single call. |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 15769 | |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 15770 | set timeout cli <delay> |
| 15771 | Change the CLI interface timeout for current connection. This can be useful |
| 15772 | during long debugging sessions where the user needs to constantly inspect |
| 15773 | some indicators without being disconnected. The delay is passed in seconds. |
| 15774 | |
| 15775 | set weight <backend>/<server> <weight>[%] |
| 15776 | Change a server's weight to the value passed in argument. If the value ends |
| 15777 | with the '%' sign, then the new weight will be relative to the initially |
Simon Horman | 58b5d29 | 2013-02-12 10:45:52 +0900 | [diff] [blame] | 15778 | configured weight. Absolute weights are permitted between 0 and 256. |
| 15779 | Relative weights must be positive with the resulting absolute weight is |
| 15780 | capped at 256. Servers which are part of a farm running a static |
| 15781 | load-balancing algorithm have stricter limitations because the weight |
| 15782 | cannot change once set. Thus for these servers, the only accepted values |
| 15783 | are 0 and 100% (or 0 and the initial weight). Changes take effect |
| 15784 | immediately, though certain LB algorithms require a certain amount of |
| 15785 | requests to consider changes. A typical usage of this command is to |
| 15786 | disable a server during an update by setting its weight to zero, then to |
| 15787 | enable it again after the update by setting it back to 100%. This command |
| 15788 | is restricted and can only be issued on sockets configured for level |
| 15789 | "admin". Both the backend and the server may be specified either by their |
| 15790 | name or by their numeric ID, prefixed with a sharp ('#'). |
Willy Tarreau | d63335a | 2010-02-26 12:56:52 +0100 | [diff] [blame] | 15791 | |
Willy Tarreau | e0c8a1a | 2009-03-04 16:33:10 +0100 | [diff] [blame] | 15792 | show errors [<iid>] |
| 15793 | Dump last known request and response errors collected by frontends and |
| 15794 | backends. If <iid> is specified, the limit the dump to errors concerning |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 15795 | either frontend or backend whose ID is <iid>. This command is restricted |
| 15796 | and can only be issued on sockets configured for levels "operator" or |
| 15797 | "admin". |
Willy Tarreau | e0c8a1a | 2009-03-04 16:33:10 +0100 | [diff] [blame] | 15798 | |
| 15799 | The errors which may be collected are the last request and response errors |
| 15800 | caused by protocol violations, often due to invalid characters in header |
| 15801 | names. The report precisely indicates what exact character violated the |
| 15802 | protocol. Other important information such as the exact date the error was |
| 15803 | detected, frontend and backend names, the server name (when known), the |
| 15804 | internal session ID and the source address which has initiated the session |
| 15805 | are reported too. |
| 15806 | |
| 15807 | All characters are returned, and non-printable characters are encoded. The |
| 15808 | most common ones (\t = 9, \n = 10, \r = 13 and \e = 27) are encoded as one |
| 15809 | letter following a backslash. The backslash itself is encoded as '\\' to |
| 15810 | avoid confusion. Other non-printable characters are encoded '\xNN' where |
| 15811 | NN is the two-digits hexadecimal representation of the character's ASCII |
| 15812 | code. |
| 15813 | |
| 15814 | Lines are prefixed with the position of their first character, starting at 0 |
| 15815 | for the beginning of the buffer. At most one input line is printed per line, |
| 15816 | and large lines will be broken into multiple consecutive output lines so that |
| 15817 | the output never goes beyond 79 characters wide. It is easy to detect if a |
| 15818 | line was broken, because it will not end with '\n' and the next line's offset |
| 15819 | will be followed by a '+' sign, indicating it is a continuation of previous |
| 15820 | line. |
| 15821 | |
| 15822 | Example : |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 15823 | $ echo "show errors" | socat stdio /tmp/sock1 |
| 15824 | >>> [04/Mar/2009:15:46:56.081] backend http-in (#2) : invalid response |
Willy Tarreau | e0c8a1a | 2009-03-04 16:33:10 +0100 | [diff] [blame] | 15825 | src 127.0.0.1, session #54, frontend fe-eth0 (#1), server s2 (#1) |
| 15826 | response length 213 bytes, error at position 23: |
| 15827 | |
| 15828 | 00000 HTTP/1.0 200 OK\r\n |
| 15829 | 00017 header/bizarre:blah\r\n |
| 15830 | 00038 Location: blah\r\n |
| 15831 | 00054 Long-line: this is a very long line which should b |
| 15832 | 00104+ e broken into multiple lines on the output buffer, |
| 15833 | 00154+ otherwise it would be too large to print in a ter |
| 15834 | 00204+ minal\r\n |
| 15835 | 00211 \r\n |
| 15836 | |
Willy Tarreau | c57f0e2 | 2009-05-10 13:12:33 +0200 | [diff] [blame] | 15837 | In the example above, we see that the backend "http-in" which has internal |
Willy Tarreau | e0c8a1a | 2009-03-04 16:33:10 +0100 | [diff] [blame] | 15838 | ID 2 has blocked an invalid response from its server s2 which has internal |
| 15839 | ID 1. The request was on session 54 initiated by source 127.0.0.1 and |
| 15840 | received by frontend fe-eth0 whose ID is 1. The total response length was |
| 15841 | 213 bytes when the error was detected, and the error was at byte 23. This |
| 15842 | is the slash ('/') in header name "header/bizarre", which is not a valid |
| 15843 | HTTP character for a header name. |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 15844 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 15845 | show backend |
| 15846 | Dump the list of backends available in the running process |
| 15847 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 15848 | show info |
| 15849 | Dump info about haproxy status on current process. |
| 15850 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 15851 | show map [<map>] |
| 15852 | Dump info about map converters. Without argument, the list of all available |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 15853 | maps is returned. If a <map> is specified, its contents are dumped. <map> is |
| 15854 | the #<id> or <file>. The first column is a unique identifier. It can be used |
| 15855 | as reference for the operation "del map" and "set map". The second column is |
| 15856 | the pattern and the third column is the sample if available. The data returned |
| 15857 | are not directly a list of available maps, but are the list of all patterns |
| 15858 | composing any map. Many of these patterns can be shared with ACL. |
Thierry FOURNIER | d32079e | 2014-01-29 20:02:04 +0100 | [diff] [blame] | 15859 | |
| 15860 | show acl [<acl>] |
| 15861 | Dump info about acl converters. Without argument, the list of all available |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 15862 | acls is returned. If a <acl> is specified, its contents are dumped. <acl> if |
| 15863 | the #<id> or <file>. The dump format is the same than the map even for the |
| 15864 | sample value. The data returned are not a list of available ACL, but are the |
| 15865 | list of all patterns composing any ACL. Many of these patterns can be shared |
| 15866 | with maps. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 15867 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 15868 | show pools |
| 15869 | Dump the status of internal memory pools. This is useful to track memory |
| 15870 | usage when suspecting a memory leak for example. It does exactly the same |
| 15871 | as the SIGQUIT when running in foreground except that it does not flush |
| 15872 | the pools. |
| 15873 | |
Baptiste Assmann | 6f9225a | 2015-05-08 19:35:08 +0200 | [diff] [blame] | 15874 | show servers state [<backend>] |
| 15875 | Dump the state of the servers found in the running configuration. A backend |
| 15876 | name or identifier may be provided to limit the output to this backend only. |
| 15877 | |
| 15878 | The dump has the following format: |
| 15879 | - first line contains the format version (1 in this specification); |
| 15880 | - second line contains the column headers, prefixed by a sharp ('#'); |
| 15881 | - third line and next ones contain data; |
| 15882 | - each line starting by a sharp ('#') is considered as a comment. |
| 15883 | |
| 15884 | Since multiple versions of the ouptput may co-exist, below is the list of |
| 15885 | fields and their order per file format version : |
| 15886 | 1: |
| 15887 | be_id: Backend unique id. |
| 15888 | be_name: Backend label. |
| 15889 | srv_id: Server unique id (in the backend). |
| 15890 | srv_name: Server label. |
| 15891 | srv_addr: Server IP address. |
| 15892 | srv_op_state: Server operational state (UP/DOWN/...). |
| 15893 | In source code: SRV_ST_*. |
| 15894 | srv_admin_state: Server administrative state (MAINT/DRAIN/...). |
| 15895 | In source code: SRV_ADMF_*. |
| 15896 | srv_uweight: User visible server's weight. |
| 15897 | srv_iweight: Server's initial weight. |
| 15898 | srv_time_since_last_change: Time since last operational change. |
| 15899 | srv_check_status: Last health check status. |
| 15900 | srv_check_result: Last check result (FAILED/PASSED/...). |
| 15901 | In source code: CHK_RES_*. |
| 15902 | srv_check_health: Checks rise / fall current counter. |
| 15903 | srv_check_state: State of the check (ENABLED/PAUSED/...). |
| 15904 | In source code: CHK_ST_*. |
| 15905 | srv_agent_state: State of the agent check (ENABLED/PAUSED/...). |
| 15906 | In source code: CHK_ST_*. |
| 15907 | bk_f_forced_id: Flag to know if the backend ID is forced by |
| 15908 | configuration. |
| 15909 | srv_f_forced_id: Flag to know if the server's ID is forced by |
| 15910 | configuration. |
| 15911 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 15912 | show sess |
| 15913 | Dump all known sessions. Avoid doing this on slow connections as this can |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 15914 | be huge. This command is restricted and can only be issued on sockets |
| 15915 | configured for levels "operator" or "admin". |
| 15916 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 15917 | show sess <id> |
| 15918 | Display a lot of internal information about the specified session identifier. |
| 15919 | This identifier is the first field at the beginning of the lines in the dumps |
| 15920 | of "show sess" (it corresponds to the session pointer). Those information are |
| 15921 | useless to most users but may be used by haproxy developers to troubleshoot a |
| 15922 | complex bug. The output format is intentionally not documented so that it can |
Olivier | ce31e6e | 2014-09-05 18:49:10 +0200 | [diff] [blame] | 15923 | freely evolve depending on demands. You may find a description of all fields |
| 15924 | returned in src/dumpstats.c |
| 15925 | |
| 15926 | The special id "all" dumps the states of all sessions, which must be avoided |
| 15927 | as much as possible as it is highly CPU intensive and can take a lot of time. |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 15928 | |
| 15929 | show stat [<iid> <type> <sid>] |
| 15930 | Dump statistics in the CSV format. By passing <id>, <type> and <sid>, it is |
| 15931 | possible to dump only selected items : |
| 15932 | - <iid> is a proxy ID, -1 to dump everything |
| 15933 | - <type> selects the type of dumpable objects : 1 for frontends, 2 for |
| 15934 | backends, 4 for servers, -1 for everything. These values can be ORed, |
| 15935 | for example: |
| 15936 | 1 + 2 = 3 -> frontend + backend. |
| 15937 | 1 + 2 + 4 = 7 -> frontend + backend + server. |
| 15938 | - <sid> is a server ID, -1 to dump everything from the selected proxy. |
| 15939 | |
| 15940 | Example : |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 15941 | $ echo "show info;show stat" | socat stdio unix-connect:/tmp/sock1 |
| 15942 | >>> Name: HAProxy |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 15943 | Version: 1.4-dev2-49 |
| 15944 | Release_date: 2009/09/23 |
| 15945 | Nbproc: 1 |
| 15946 | Process_num: 1 |
| 15947 | (...) |
| 15948 | |
| 15949 | # pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq, (...) |
| 15950 | stats,FRONTEND,,,0,0,1000,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,1,0, (...) |
| 15951 | stats,BACKEND,0,0,0,0,1000,0,0,0,0,0,,0,0,0,0,UP,0,0,0,,0,250,(...) |
| 15952 | (...) |
| 15953 | www1,BACKEND,0,0,0,0,1000,0,0,0,0,0,,0,0,0,0,UP,1,1,0,,0,250, (...) |
| 15954 | |
| 15955 | $ |
| 15956 | |
| 15957 | Here, two commands have been issued at once. That way it's easy to find |
| 15958 | which process the stats apply to in multi-process mode. Notice the empty |
| 15959 | line after the information output which marks the end of the first block. |
| 15960 | A similar empty line appears at the end of the second block (stats) so that |
Krzysztof Piotr Oledzki | f864533 | 2009-12-13 21:55:50 +0100 | [diff] [blame] | 15961 | the reader knows the output has not been truncated. |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 15962 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 15963 | show stat resolvers <resolvers section id> |
| 15964 | Dump statistics for the given resolvers section. |
| 15965 | For each name server, the following counters are reported: |
| 15966 | sent: number of DNS requests sent to this server |
| 15967 | valid: number of DNS valid responses received from this server |
| 15968 | update: number of DNS responses used to update the server's IP address |
| 15969 | cname: number of CNAME responses |
| 15970 | cname_error: CNAME errors encountered with this server |
| 15971 | any_err: number of empty response (IE: server does not support ANY type) |
| 15972 | nx: non existent domain response received from this server |
| 15973 | timeout: how many time this server did not answer in time |
| 15974 | refused: number of requests refused by this server |
| 15975 | other: any other DNS errors |
| 15976 | invalid: invalid DNS response (from a protocol point of view) |
| 15977 | too_big: too big response |
| 15978 | outdated: number of response arrived too late (after an other name server) |
| 15979 | |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 15980 | show table |
| 15981 | Dump general information on all known stick-tables. Their name is returned |
| 15982 | (the name of the proxy which holds them), their type (currently zero, always |
| 15983 | IP), their size in maximum possible number of entries, and the number of |
| 15984 | entries currently in use. |
| 15985 | |
| 15986 | Example : |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 15987 | $ echo "show table" | socat stdio /tmp/sock1 |
Simon Horman | 64b28d0 | 2011-08-13 08:03:50 +0900 | [diff] [blame] | 15988 | >>> # table: front_pub, type: ip, size:204800, used:171454 |
| 15989 | >>> # table: back_rdp, type: ip, size:204800, used:0 |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 15990 | |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 15991 | show table <name> [ data.<type> <operator> <value> ] | [ key <key> ] |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 15992 | Dump contents of stick-table <name>. In this mode, a first line of generic |
| 15993 | information about the table is reported as with "show table", then all |
| 15994 | entries are dumped. Since this can be quite heavy, it is possible to specify |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 15995 | a filter in order to specify what entries to display. |
| 15996 | |
| 15997 | When the "data." form is used the filter applies to the stored data (see |
| 15998 | "stick-table" in section 4.2). A stored data type must be specified |
| 15999 | in <type>, and this data type must be stored in the table otherwise an |
| 16000 | error is reported. The data is compared according to <operator> with the |
| 16001 | 64-bit integer <value>. Operators are the same as with the ACLs : |
| 16002 | |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 16003 | - eq : match entries whose data is equal to this value |
| 16004 | - ne : match entries whose data is not equal to this value |
| 16005 | - le : match entries whose data is less than or equal to this value |
| 16006 | - ge : match entries whose data is greater than or equal to this value |
| 16007 | - lt : match entries whose data is less than this value |
| 16008 | - gt : match entries whose data is greater than this value |
| 16009 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 16010 | |
| 16011 | When the key form is used the entry <key> is shown. The key must be of the |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 16012 | same type as the table, which currently is limited to IPv4, IPv6, integer, |
| 16013 | and string. |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 16014 | |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 16015 | Example : |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 16016 | $ echo "show table http_proxy" | socat stdio /tmp/sock1 |
Simon Horman | 64b28d0 | 2011-08-13 08:03:50 +0900 | [diff] [blame] | 16017 | >>> # table: http_proxy, type: ip, size:204800, used:2 |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 16018 | >>> 0x80e6a4c: key=127.0.0.1 use=0 exp=3594729 gpc0=0 conn_rate(30000)=1 \ |
| 16019 | bytes_out_rate(60000)=187 |
| 16020 | >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \ |
| 16021 | bytes_out_rate(60000)=191 |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 16022 | |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 16023 | $ echo "show table http_proxy data.gpc0 gt 0" | socat stdio /tmp/sock1 |
Simon Horman | 64b28d0 | 2011-08-13 08:03:50 +0900 | [diff] [blame] | 16024 | >>> # table: http_proxy, type: ip, size:204800, used:2 |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 16025 | >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \ |
| 16026 | bytes_out_rate(60000)=191 |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 16027 | |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 16028 | $ echo "show table http_proxy data.conn_rate gt 5" | \ |
| 16029 | socat stdio /tmp/sock1 |
Simon Horman | 64b28d0 | 2011-08-13 08:03:50 +0900 | [diff] [blame] | 16030 | >>> # table: http_proxy, type: ip, size:204800, used:2 |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 16031 | >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \ |
| 16032 | bytes_out_rate(60000)=191 |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 16033 | |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 16034 | $ echo "show table http_proxy key 127.0.0.2" | \ |
| 16035 | socat stdio /tmp/sock1 |
Simon Horman | 64b28d0 | 2011-08-13 08:03:50 +0900 | [diff] [blame] | 16036 | >>> # table: http_proxy, type: ip, size:204800, used:2 |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 16037 | >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \ |
| 16038 | bytes_out_rate(60000)=191 |
| 16039 | |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 16040 | When the data criterion applies to a dynamic value dependent on time such as |
| 16041 | a bytes rate, the value is dynamically computed during the evaluation of the |
| 16042 | entry in order to decide whether it has to be dumped or not. This means that |
| 16043 | such a filter could match for some time then not match anymore because as |
| 16044 | time goes, the average event rate drops. |
| 16045 | |
| 16046 | It is possible to use this to extract lists of IP addresses abusing the |
| 16047 | service, in order to monitor them or even blacklist them in a firewall. |
| 16048 | Example : |
Willy Tarreau | 62a36c4 | 2010-08-17 15:53:10 +0200 | [diff] [blame] | 16049 | $ echo "show table http_proxy data.gpc0 gt 0" \ |
| 16050 | | socat stdio /tmp/sock1 \ |
Willy Tarreau | 88bc4ec | 2010-08-01 07:58:48 +0200 | [diff] [blame] | 16051 | | fgrep 'key=' | cut -d' ' -f2 | cut -d= -f2 > abusers-ip.txt |
| 16052 | ( or | awk '/key/{ print a[split($2,a,"=")]; }' ) |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 16053 | |
Nenad Merdanovic | c6985f0 | 2015-05-09 08:46:02 +0200 | [diff] [blame] | 16054 | show tls-keys |
| 16055 | Dump all loaded TLS ticket keys. The TLS ticket key reference ID and the |
| 16056 | file from which the keys have been loaded is shown. Both of those can be |
| 16057 | used to update the TLS keys using "set ssl tls-key". |
| 16058 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 16059 | shutdown frontend <frontend> |
| 16060 | Completely delete the specified frontend. All the ports it was bound to will |
| 16061 | be released. It will not be possible to enable the frontend anymore after |
| 16062 | this operation. This is intended to be used in environments where stopping a |
| 16063 | proxy is not even imaginable but a misconfigured proxy must be fixed. That |
| 16064 | way it's possible to release the port and bind it into another process to |
| 16065 | restore operations. The frontend will not appear at all on the stats page |
| 16066 | once it is terminated. |
| 16067 | |
| 16068 | The frontend may be specified either by its name or by its numeric ID, |
| 16069 | prefixed with a sharp ('#'). |
| 16070 | |
| 16071 | This command is restricted and can only be issued on sockets configured for |
| 16072 | level "admin". |
| 16073 | |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 16074 | shutdown session <id> |
| 16075 | Immediately terminate the session matching the specified session identifier. |
| 16076 | This identifier is the first field at the beginning of the lines in the dumps |
| 16077 | of "show sess" (it corresponds to the session pointer). This can be used to |
| 16078 | terminate a long-running session without waiting for a timeout or when an |
| 16079 | endless transfer is ongoing. Such terminated sessions are reported with a 'K' |
| 16080 | flag in the logs. |
| 16081 | |
Cyril Bonté | e63a1eb | 2014-07-12 18:22:42 +0200 | [diff] [blame] | 16082 | shutdown sessions server <backend>/<server> |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 16083 | Immediately terminate all the sessions attached to the specified server. This |
| 16084 | can be used to terminate long-running sessions after a server is put into |
| 16085 | maintenance mode, for instance. Such terminated sessions are reported with a |
| 16086 | 'K' flag in the logs. |
| 16087 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 16088 | /* |
| 16089 | * Local variables: |
| 16090 | * fill-column: 79 |
| 16091 | * End: |
| 16092 | */ |