willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1 | |
| 2 | H A - P r o x y |
| 3 | --------------- |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 4 | version 1.1.25 |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 5 | willy tarreau |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 6 | 2003/10/15 |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 7 | |
| 8 | ============ |
| 9 | | Abstract | |
| 10 | ============ |
| 11 | |
| 12 | HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high |
| 13 | availability environments. Indeed, it can : |
| 14 | - route HTTP requests depending on statically assigned cookies ; |
| 15 | - spread the load among several servers while assuring server persistence |
| 16 | through the use of HTTP cookies ; |
| 17 | - switch to backup servers in the event a main one fails ; |
| 18 | - accept connections to special ports dedicated to service monitoring ; |
| 19 | - stop accepting connections without breaking existing ones ; |
| 20 | - add/modify/delete HTTP headers both ways ; |
| 21 | - block requests matching a particular pattern ; |
| 22 | |
| 23 | It needs very little resource. Its event-driven architecture allows it to easily |
| 24 | handle thousands of simultaneous connections on hundreds of instances without |
| 25 | risking the system's stability. |
| 26 | |
| 27 | ==================== |
| 28 | | Start parameters | |
| 29 | ==================== |
| 30 | |
| 31 | There are only a few command line options : |
| 32 | |
| 33 | -f <configuration file> |
| 34 | -n <high limit for the total number of simultaneous connections> |
| 35 | -N <high limit for the per-proxy number of simultaneous connections> |
| 36 | -d starts in foregreound with debugging mode enabled |
| 37 | -D starts in daemon mode |
| 38 | -s shows statistics (only if compiled in) |
| 39 | -l shows even more statistics (implies '-s') |
| 40 | |
| 41 | |
| 42 | The maximal number of connections per proxy is used as the default parameter for |
| 43 | each instance for which the 'maxconn' paramter is not set in the 'listen' section. |
| 44 | |
| 45 | The maximal number of total connections limits the number of connections used by |
| 46 | the whole process if the 'maxconn' parameter is not set in the 'global' section. |
| 47 | |
| 48 | The debugging mode has the same effect as the 'debug' option in the 'global' |
| 49 | section. When the proxy runs in this mode, it dumps every connections, |
| 50 | disconnections, timestamps, and HTTP headers to stdout. This should NEVER |
| 51 | be used in an init script since it will prevent the system from starting up. |
| 52 | |
| 53 | Statistics are only available if compiled in with the 'STATTIME' option. It's |
| 54 | only used during code optimization phases. |
| 55 | |
| 56 | ====================== |
| 57 | | Configuration file | |
| 58 | ====================== |
| 59 | |
| 60 | Structure |
| 61 | ========= |
| 62 | |
| 63 | The configuration file parser ignores empty lines, spaces, tabs. Anything |
| 64 | between a sharp ('#') not following a backslash ('\'), and the end of a line |
| 65 | constitutes a comment and is ignored too. |
| 66 | |
| 67 | The configuration file is segmented in sections. A section begins whenever |
| 68 | one of these 3 keywords are encountered : |
| 69 | |
| 70 | - 'global' |
| 71 | - 'listen' |
| 72 | - 'defaults' |
| 73 | |
| 74 | Every parameter refer to the section beginning at the last one of these 3 |
| 75 | keywords. |
| 76 | |
| 77 | |
| 78 | 1) Global parameters |
| 79 | ==================== |
| 80 | |
| 81 | Global parameters affect the whole process behaviour. They are all set in the |
| 82 | 'global' section. There may be several 'global' sections if needed, but their |
| 83 | parameters will only be merged. Allowed parameters in 'global' section include |
| 84 | the following ones : |
| 85 | |
| 86 | - log <address> <facility> [max_level] |
| 87 | - maxconn <number> |
| 88 | - uid <user id> |
| 89 | - gid <group id> |
| 90 | - chroot <directory> |
| 91 | - nbproc <number> |
| 92 | - daemon |
| 93 | - debug |
| 94 | - quiet |
| 95 | |
| 96 | 1.1) Event logging |
| 97 | ------------------ |
| 98 | Most events are logged : start, stop, servers going up and down, connections and |
| 99 | errors. Each event generates a syslog message which can be sent to up to 2 |
| 100 | servers. The syntax is : |
| 101 | |
| 102 | log <ip_address> <facility> [max_level] |
| 103 | |
| 104 | Connections are logged at level "info". Services initialization and servers |
| 105 | going up are logged at level "notice", termination signals are logged at |
| 106 | "warning", and definitive service termination, as well as loss of servers are |
| 107 | logged at level "alert". The optional parameter <max_level> specifies above |
| 108 | what level messages should be sent. Level can take one of these 8 values : |
| 109 | |
| 110 | emerg, alert, crit, err, warning, notice, info, debug |
| 111 | |
| 112 | For backwards compatibility with versions 1.1.16 and earlier, the default level |
| 113 | value is "debug" if not specified. |
| 114 | |
| 115 | Permitted facilities are : |
| 116 | kern, user, mail, daemon, auth, syslog, lpr, news, |
| 117 | uucp, cron, auth2, ftp, ntp, audit, alert, cron2, |
| 118 | local0, local1, local2, local3, local4, local5, local6, local7 |
| 119 | |
| 120 | According to RFC3164, messages are truncated to 1024 bytes before being emitted. |
| 121 | |
| 122 | Example : |
| 123 | --------- |
| 124 | global |
| 125 | log 192.168.2.200 local3 |
| 126 | log 127.0.0.1 local4 notice |
| 127 | |
| 128 | 1.2) limiting the number of connections |
| 129 | --------------------------------------- |
| 130 | It is possible and recommended to limit the global number of per-process |
| 131 | connections. Since one connection includes both a client and a server, it |
| 132 | means that the max number of TCP sessions will be about the double of this |
| 133 | number. It's important to understand this when trying to find best values |
| 134 | for 'ulimit -n' before starting the proxy. To anticipate the number of |
| 135 | sockets needed, all these parameters must be counted : |
| 136 | |
| 137 | - 1 socket per incoming connection |
| 138 | - 1 socket per outgoing connection |
| 139 | - 1 socket per address/port/proxy tuple. |
| 140 | - 1 socket per server being health-checked |
| 141 | - 1 socket for all logs |
| 142 | |
| 143 | In simple configurations where each proxy only listens one one address/port, |
| 144 | set the limit of file descriptors (ulimit -n) to |
| 145 | (2 * maxconn + nbproxies + nbservers + 1). In a future release, haproxy may |
| 146 | be able to set this value itself. |
| 147 | |
| 148 | 1.3) Drop of priviledges |
| 149 | ------------------------ |
| 150 | In order to reduce the risk and consequences of attacks, in the event where a |
| 151 | yet non-identified vulnerability would be successfully exploited, it's possible |
| 152 | to lower the process priviledges and even isolate it in a riskless directory. |
| 153 | |
| 154 | In the 'global' section, the 'uid' parameter sets a numerical user identifier |
| 155 | which the process will switch to after binding its listening sockets. The value |
| 156 | '0', which normally represents the super-user, here indicates that the UID must |
| 157 | not change during startup. It's the default behaviour. The 'gid' parameter does |
| 158 | the same for the group identifier. It's particularly advised against use of |
| 159 | generic accounts such as 'nobody' because it has the same consequences as using |
| 160 | 'root' if other services use them. |
| 161 | |
| 162 | The 'chroot' parameter makes the process isolate itself in an empty directory |
| 163 | just before switching its UID. This type of isolation (chroot) can sometimes |
| 164 | be worked around on certain OS (Linux, Solaris), provided that the attacker |
| 165 | has gained 'root' priviledges and has the ability to use or create a directory. |
| 166 | For this reason, it's capital to use a dedicated directory and not to share one |
| 167 | between several services of different nature. To make isolation more resistant, |
| 168 | it's recommended to use an empty directory without any right, and to change the |
| 169 | UID of the process so that it cannot do anything there. |
| 170 | |
| 171 | Note: in the event where such a vulnerability would be exploited, it's most |
| 172 | likely that first attempts would kill the process due to 'Segmentation Fault', |
| 173 | 'Bus Error' or 'Illegal Instruction' signals. Eventhough it's true that |
| 174 | isolating the server reduces the risks of intrusion, it's sometimes useful to |
| 175 | find why a process dies, via the analysis of a 'core' file, although very rare |
| 176 | (the last bug of this sort was fixed in 1.1.9). For security reasons, most |
| 177 | systems disable the generation of core file when a process changes its UID. So |
| 178 | the two workarounds are either to start the process from a restricted user |
| 179 | account, which will not be able to chroot itself, or start it as root and not |
| 180 | change the UID. In both cases the core will be either in the start or the chroot |
| 181 | directories. Do not forget to allow core dumps prior to start the process : |
| 182 | |
| 183 | # ulimit -c unlimited |
| 184 | |
| 185 | Example : |
| 186 | --------- |
| 187 | |
| 188 | global |
| 189 | uid 30000 |
| 190 | gid 30000 |
| 191 | chroot /var/chroot/haproxy |
| 192 | |
| 193 | 1.4) Startup modes |
| 194 | ------------------ |
| 195 | The service can start in several different : |
| 196 | - foreground / background |
| 197 | - quiet / normal / debug |
| 198 | |
| 199 | The default mode is normal, foreground, which means that the program doesn't |
| 200 | return once started. NEVER EVER use this mode in a system startup script, or |
| 201 | the system won't boot. It needs to be started in background, so that it |
| 202 | returns immediately after forking. That's accomplished by the 'daemon' option |
| 203 | in the 'global' section, which is the equivalent of the '-D' command line |
| 204 | argument. |
| 205 | |
| 206 | Moreover, certain alert messages are still sent to the standard output even |
| 207 | in 'daemon' mode. To make them disappear, simply add the 'quiet' option in the |
| 208 | 'global' section. This option has no command-line equivalent. |
| 209 | |
| 210 | Last, the 'debug' mode, enabled with the 'debug' option in the 'global' section, |
| 211 | and which is equivalent of the '-d' option, allows deep TCP/HTTP analysis, with |
| 212 | timestamped display of each connection, disconnection, and HTTP headers for both |
| 213 | ways. This mode is incompatible with 'daemon' and 'quiet' modes for obvious |
| 214 | reasons. |
| 215 | |
| 216 | 1.5) Increasing the overall processing power |
| 217 | -------------------------------------------- |
| 218 | On multi-processor systems, it may seem to be a shame to use only one processor, |
| 219 | eventhough the load needed to saturate a recent processor are far above common |
| 220 | usage. Anyway, for very specific needs, the proxy can start several processes |
| 221 | between which the operating system will spread the incoming connections. The |
| 222 | number of processes is controlled by the 'nbproc' parameter in the 'global' |
| 223 | section. It defaults to 1, and obviously works only in 'daemon' mode. |
| 224 | |
| 225 | Example : |
| 226 | --------- |
| 227 | |
| 228 | global |
| 229 | daemon |
| 230 | quiet |
| 231 | nbproc 2 |
| 232 | |
| 233 | |
| 234 | 2) Declaration of a listening service |
| 235 | ===================================== |
| 236 | |
| 237 | Service sections start with the 'listen' keyword : |
| 238 | |
| 239 | listen <instance_name> [ <IP_address>:<port_range>[,...] ] |
| 240 | |
| 241 | - <instance_name> is the name of the instance. This name will be reported in |
| 242 | logs, so it is good to have it reflect the proxied service. No unicity test |
| 243 | is done on this name, and it's not mandatory for it to be unique, but highly |
| 244 | recommended. |
| 245 | |
| 246 | - <IP_address> is the IP address the proxy binds to. Empty address, '*' and |
| 247 | '0.0.0.0' all mean that the proxy listens to all valid addresses on the |
| 248 | system. |
| 249 | |
| 250 | - <port_range> is either a unique port, or a port range for which the proxy will |
| 251 | accept connections for the IP address specified above. This range can be : |
| 252 | - a numerical port (ex: '80') |
| 253 | - a dash-delimited ports range explicitly stating the lower and upper bounds |
| 254 | (ex: '2000-2100') which are included in the range. |
| 255 | |
| 256 | Particular care must be taken against port ranges, because every <addr:port> |
| 257 | couple consumes one socket (=a file descriptor), so it's easy to eat lots of |
| 258 | descriptors with a simple range. The <addr:port> couple must be used only once |
| 259 | among all instances running on a same system. Please note that attaching to |
| 260 | ports lower than 1024 need particular priviledges to start the program, which |
| 261 | are independant of the 'uid' parameter. |
| 262 | |
| 263 | - the <IP_address>:<port_range> couple may be repeated indefinitely to require |
| 264 | the proxy to listen to other addresses and/or ports. To achieve this, simply |
| 265 | separate them with a coma. |
| 266 | |
| 267 | Examples : |
| 268 | --------- |
| 269 | listen http_proxy :80 |
| 270 | listen x11_proxy 127.0.0.1:6000-6009 |
| 271 | listen smtp_proxy 127.0.0.1:25,127.0.0.1:587 |
| 272 | listen ldap_proxy :389,:663 |
| 273 | |
| 274 | In the event that all addresses do not fit line width, it's preferable to |
| 275 | detach secondary addresses on other lines with the 'bind' keyword. If this |
| 276 | keyword is used, it's not even necessary to specify the first address on the |
| 277 | 'listen' line, which sometimes makes multiple configuration handling easier : |
| 278 | |
| 279 | bind [ <IP_address>:<port_range>[,...] ] |
| 280 | |
| 281 | Examples : |
| 282 | ---------- |
| 283 | listen http_proxy |
| 284 | bind :80,:443 |
| 285 | bind 10.0.0.1:10080,10.0.0.1:10443 |
| 286 | |
| 287 | 2.1) Inhibiting a service |
| 288 | ------------------------- |
| 289 | A service may be disabled for maintenance reasons, without needing to comment |
| 290 | out the whole section, simply by specifying the 'disabled' keyword in the |
| 291 | section to be disabled : |
| 292 | |
| 293 | listen smtp_proxy 0.0.0.0:25 |
| 294 | disabled |
| 295 | |
| 296 | Note: the 'enabled' keyword allows to enable a service which has been disabled |
| 297 | previously by a default configuration. |
| 298 | |
| 299 | 2.2) Modes of operation |
| 300 | ----------------------- |
| 301 | A service can work in 3 different distinct modes : |
| 302 | - TCP |
| 303 | - HTTP |
| 304 | - monitoring |
| 305 | |
| 306 | TCP mode |
| 307 | -------- |
| 308 | In this mode, the service relays TCP connections as soon as they're established, |
| 309 | towards one or several servers. No processing is done on the stream. It's only |
| 310 | an association of source(addr:port) -> destination(addr:port). To use this mode, |
| 311 | you must specify 'mode tcp' in the 'listen' section. This is the default mode. |
| 312 | |
| 313 | Example : |
| 314 | --------- |
| 315 | listen smtp_proxy 0.0.0.0:25 |
| 316 | mode tcp |
| 317 | |
| 318 | HTTP mode |
| 319 | --------- |
| 320 | In this mode, the service relays TCP connections towards one or several servers, |
| 321 | when it has enough informations to decide, which normally means that all HTTP |
| 322 | headers have been read. Some of them may be scanned for a cookie or a pattern |
| 323 | matching a regex. To use this mode, specify 'mode http' in the 'listen' section. |
| 324 | |
| 325 | Example : |
| 326 | --------- |
| 327 | listen http_proxy 0.0.0.0:80 |
| 328 | mode http |
| 329 | |
| 330 | Health-checking mode |
| 331 | -------------------- |
| 332 | This mode provides a way for external components to check the proxy's health. |
| 333 | It is meant to be used with intelligent load-balancers which can use send/expect |
| 334 | scripts to check for all of their servers' availability. This one simply accepts |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 335 | the connection, returns the word 'OK' and closes it. If the 'option httpchk' is |
| 336 | set, then the reply will be 'HTTP/1.0 200 OK' with no data, so that it can be |
| 337 | tested from a tool which supports HTTP health-checks. To enable it, simply |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 338 | specify 'health' as the working mode : |
| 339 | |
| 340 | Example : |
| 341 | --------- |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 342 | # simple response : 'OK' |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 343 | listen health_check 0.0.0.0:60000 |
| 344 | mode health |
| 345 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 346 | # HTTP response : 'HTTP/1.0 200 OK' |
| 347 | listen http_health_check 0.0.0.0:60001 |
| 348 | mode health |
| 349 | option httpchk |
| 350 | |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 351 | |
| 352 | 2.3) Limiting the number of simultaneous connections |
| 353 | ---------------------------------------------------- |
| 354 | The 'maxconn' parameter allows a proxy to refuse connections above a certain |
| 355 | amount of simultaneous ones. When the limit is reached, it simply stops |
| 356 | listening, but the system may still be accepting them because of the back log |
| 357 | queue. These connections will be processed further when other ones have freed |
| 358 | some slots. This provides a serialization effect which helps very fragile |
| 359 | servers resist to high loads. Se further for system limitations. |
| 360 | |
| 361 | Example : |
| 362 | --------- |
| 363 | listen tiny_server 0.0.0.0:80 |
| 364 | maxconn 10 |
| 365 | |
| 366 | |
| 367 | 2.4) Soft stop |
| 368 | -------------- |
| 369 | It is possible to stop services without breaking existing connections by the |
| 370 | sending of the SIG_USR1 signal to the process. All services are then put into |
| 371 | soft-stop state, which means that they will refuse to accept new connections, |
| 372 | except for those which have a non-zero value in the 'grace' parameter, in which |
| 373 | case they will still accept connections for the specified amount of time, in |
| 374 | milliseconds. This allows to tell a load-balancer that the service is failing, |
| 375 | while still doing the job during the time it needs to detect it. |
| 376 | |
| 377 | Note: active connections are never killed. In the worst case, the user will have |
| 378 | to wait for all of them to close or to time-out, or simply kill the process |
| 379 | normally (SIG_TERM). The default 'grace' value is '0'. |
| 380 | |
| 381 | Example : |
| 382 | --------- |
| 383 | # enter soft stop after 'killall -USR1 haproxy' |
| 384 | # the service will still run 10 seconds after the signal |
| 385 | listen http_proxy 0.0.0.0:80 |
| 386 | mode http |
| 387 | grace 10000 |
| 388 | |
| 389 | # this port is dedicated to a load-balancer, and must fail immediately |
| 390 | listen health_check 0.0.0.0:60000 |
| 391 | mode health |
| 392 | grace 0 |
| 393 | |
| 394 | |
| 395 | 2.5) Connections expiration time |
| 396 | -------------------------------- |
| 397 | It is possible (and recommended) to configure several time-outs on TCP |
| 398 | connections. Three independant timers are adjustable with values specified |
| 399 | in milliseconds. A session will be terminated if either one of these timers |
| 400 | expire. |
| 401 | |
| 402 | - the time we accept to wait for data from the client, or for the client to |
| 403 | accept data : 'clitimeout' : |
| 404 | |
| 405 | # client time-out set to 2mn30. |
| 406 | clitimeout 150000 |
| 407 | |
| 408 | - the time we accept to wait for data from the server, or for the server to |
| 409 | accept data : 'srvtimeout' : |
| 410 | |
| 411 | # server time-out set to 30s. |
| 412 | srvtimeout 30000 |
| 413 | |
| 414 | - the time we accept to wait for a connection to establish on a server : |
| 415 | 'contimeout' : |
| 416 | |
| 417 | # we give up if the connection does not complete within 4 seconds |
| 418 | contimeout 4000 |
| 419 | |
| 420 | Notes : |
| 421 | ------- |
| 422 | - 'contimeout' and 'srvtimeout' have no sense on 'health' mode servers ; |
| 423 | - under high loads, or with a saturated or defective network, it's possible |
| 424 | that some packets get lost. Since the first TCP retransmit only happens |
| 425 | after 3 seconds, a time-out equal to, or lower than 3 seconds cannot |
| 426 | compensate for a packet loss. A 4 seconds time-out seems a reasonable |
| 427 | minimum which will considerably reduce connection failures. |
| 428 | |
| 429 | 2.6) Attempts to reconnect |
| 430 | -------------------------- |
| 431 | After a connection failure to a server, it is possible to retry, potentially |
| 432 | on another server. This is useful if health-checks are too rare and you don't |
| 433 | want the clients to see the failures. The number of attempts to reconnect is |
| 434 | set by the 'retries' paramter. |
| 435 | |
| 436 | Example : |
| 437 | --------- |
| 438 | # we can retry 3 times max after a failure |
| 439 | retries 3 |
| 440 | |
| 441 | |
| 442 | 2.7) Address of the dispatch server (deprecated) |
| 443 | ------------------------------------------------ |
| 444 | The server which will be sent all new connections is defined by the 'dispatch' |
| 445 | parameter, in the form <address>:<port>. It generally is dedicated to unknown |
| 446 | connections and will assign them a cookie, in case of HTTP persistence mode, |
| 447 | or simply is a single server in case of generic TCP proxy. This old mode is only |
| 448 | provided for backwards compatibility, but doesn't allow to check remote servers |
| 449 | state, and has a rather limited usage. All new setups should switch to 'balance' |
| 450 | mode. The principle of the dispatcher is to be able to perform the load |
| 451 | balancing itself, but work only on new clients so that the server doesn't need |
| 452 | to be a big machine. |
| 453 | |
| 454 | Example : |
| 455 | --------- |
| 456 | # all new connections go there |
| 457 | dispatch 192.168.1.2:80 |
| 458 | |
| 459 | Note : |
| 460 | ------ |
| 461 | This parameter has no sense for 'health' servers, and is incompatible with |
| 462 | 'balance' mode. |
| 463 | |
| 464 | |
| 465 | 2.8) Outgoing source address |
| 466 | ---------------------------- |
| 467 | It is often necessary to bind to a particular address when connecting to some |
| 468 | remote hosts. This is done via the 'source' parameter which is a per-proxy |
| 469 | parameter. A newer version may allow to fix different sources to reach different |
| 470 | servers. The syntax is 'source <address>[:<port>]', where <address> is a valid |
| 471 | local address (or '0.0.0.0' or '*' or empty to let the system choose), and |
| 472 | <port> is an optional parameter allowing the user to force the source port for |
| 473 | very specific needs. If the port is not specified or is '0', the system will |
| 474 | choose a free port. Note that as of version 1.1.18, the servers health checks |
| 475 | are also performed from the same source. |
| 476 | |
| 477 | Examples : |
| 478 | ---------- |
| 479 | listen http_proxy *:80 |
| 480 | # all connections take 192.168.1.200 as source address |
| 481 | source 192.168.1.200:0 |
| 482 | |
| 483 | listen rlogin_proxy *:513 |
| 484 | # use address 192.168.1.200 and the reserved port 900 (needs to be root) |
| 485 | source 192.168.1.200:900 |
| 486 | |
| 487 | |
| 488 | 2.9) Setting the cookie name |
| 489 | ---------------------------- |
| 490 | In HTTP mode, it is possible to look for a particular cookie which will contain |
| 491 | a server identifier which should handle the connection. The cookie name is set |
| 492 | via the 'cookie' parameter. |
| 493 | |
| 494 | Example : |
| 495 | --------- |
| 496 | listen http_proxy :80 |
| 497 | mode http |
| 498 | cookie SERVERID |
| 499 | |
| 500 | It is possible to change the cookie behaviour to get a smarter persistence, |
| 501 | depending on applications. It is notably possible to delete or modify a cookie |
| 502 | emitted by a server, insert a cookie identifying the server in an HTTP response |
| 503 | and even add a header to tell upstream caches not to cache this response. |
| 504 | |
| 505 | Examples : |
| 506 | ---------- |
| 507 | |
| 508 | To remove the cookie for direct accesses (ie when the server matches the one |
| 509 | which was specified in the client cookie) : |
| 510 | |
| 511 | cookie SERVERID indirect |
| 512 | |
| 513 | To replace the cookie value with the one assigned to the server if any (no |
| 514 | cookie will be created if the server does not provide one, nor if the |
| 515 | configuration does not provide one). This lets the application put the cookie |
| 516 | exactly on certain pages (eg: successful authentication) : |
| 517 | |
| 518 | cookie SERVERID rewrite |
| 519 | |
| 520 | To create a new cookie and assign the server identifier to it (in this case, all |
| 521 | servers should be associated with a valid cookie, since no cookie will simply |
| 522 | delete the cookie from the client's browser) : |
| 523 | |
| 524 | cookie SERVERID insert |
| 525 | |
| 526 | To insert a cookie and ensure that no upstream cache will store it, add the |
| 527 | 'nocache' option : |
| 528 | |
| 529 | cookie SERVERID insert nocache |
| 530 | |
| 531 | To insert a cookie only after a POST request, add 'postonly' after 'insert'. |
| 532 | This has the advantage that there's no risk of caching, and that all pages |
| 533 | seen before the POST one can still be cached : |
| 534 | |
| 535 | cookie SERVERID insert postonly |
| 536 | |
| 537 | Notes : |
| 538 | ----------- |
| 539 | - it is possible to combine 'insert' with 'indirect' or 'rewrite' to adapt to |
| 540 | applications which already generate the cookie with an invalid content. |
| 541 | |
| 542 | - in the case where 'insert' and 'indirect' are both specified, the cookie is |
| 543 | never transmitted to the server, since it wouldn't understand it. This is |
| 544 | the most application-transparent mode. |
| 545 | |
| 546 | - it is particularly recommended to use 'nocache' in 'insert' mode if any |
| 547 | upstream HTTP/1.0 cache is susceptible to cache the result, because this may |
| 548 | lead to many clients going to the same server, or even worse, some clients |
| 549 | having their server changed while retrieving a page from the cache. |
| 550 | |
| 551 | - when the application is well known and controlled, the best method is to |
| 552 | only add the persistence cookie on a POST form because it's up to the |
| 553 | application to select which page it wants the upstream servers to cache. |
| 554 | In this case, you would use 'insert postonly indirect'. |
| 555 | |
| 556 | 2.10) Associating a cookie value with a server |
| 557 | ---------------------------------------------- |
| 558 | In HTTP mode, it's possible to associate a cookie value to each server. This |
| 559 | was initially used in combination with 'dispatch' mode to handle direct accesses |
| 560 | but it is now the standard way of doing the load balancing. The syntax is : |
| 561 | |
| 562 | server <identifier> <address>:<port> cookie <value> |
| 563 | |
| 564 | - <identifier> is any name which can be used to identify the server in the logs. |
| 565 | - <address>:<port> specifies where the server is bound. |
| 566 | - <value> is the value to put in or to read from the cookie. |
| 567 | |
| 568 | Example : the 'SERVERID' cookie can be either 'server01' or 'server02' |
| 569 | --------- |
| 570 | listen http_proxy :80 |
| 571 | mode http |
| 572 | cookie SERVERID |
| 573 | dispatch 192.168.1.100:80 |
| 574 | server web1 192.168.1.1:80 cookie server01 |
| 575 | server web2 192.168.1.2:80 cookie server02 |
| 576 | |
| 577 | Warning : the syntax has changed since version 1.0 ! |
| 578 | --------- |
| 579 | |
| 580 | 3) Autonomous load balancer |
| 581 | =========================== |
| 582 | |
| 583 | The proxy can perform the load-balancing itself, both in TCP and in HTTP modes. |
| 584 | This is the most interesting mode which obsoletes the old 'dispatch' mode |
| 585 | described above. It has advantages such as server health monitoring, multiple |
| 586 | port binding and port mapping. To use this mode, the 'balance' keyword is used, |
| 587 | followed by the selected algorithm. As of version 1.1.23, only 'roundrobin' is |
| 588 | available, which is also the default value if unspecified. In this mode, there |
| 589 | will be no dispatch address, but the proxy needs at least one server. |
| 590 | |
| 591 | Example : same as the last one, with internal load balancer |
| 592 | --------- |
| 593 | |
| 594 | listen http_proxy :80 |
| 595 | mode http |
| 596 | cookie SERVERID |
| 597 | balance roundrobin |
| 598 | server web1 192.168.1.1:80 cookie server01 |
| 599 | server web2 192.168.1.2:80 cookie server02 |
| 600 | |
| 601 | |
| 602 | Since version 1.1.22, it is possible to automatically determine on which port |
| 603 | the server will get the connection, depending on the port the client connected |
| 604 | to. Indeed, there now are 4 possible combinations for the server's <port> field: |
| 605 | |
| 606 | - unspecified or '0' : |
| 607 | the connection will be sent to the same port as the one on which the proxy |
| 608 | received the client connection itself. |
| 609 | |
| 610 | - numerical value (the only one supported in versions earlier than 1.1.22) : |
| 611 | the connection will always be sent to the specified port. |
| 612 | |
| 613 | - '+' followed by a numerical value : |
| 614 | the connection will be sent to the same port as the one on which the proxy |
| 615 | received the connection, plus this value. |
| 616 | |
| 617 | - '-' followed by a numerical value : |
| 618 | the connection will be sent to the same port as the one on which the proxy |
| 619 | received the connection, minus this value. |
| 620 | |
| 621 | Examples : |
| 622 | ---------- |
| 623 | |
| 624 | # same as previous example |
| 625 | |
| 626 | listen http_proxy :80 |
| 627 | mode http |
| 628 | cookie SERVERID |
| 629 | balance roundrobin |
| 630 | server web1 192.168.1.1 cookie server01 |
| 631 | server web2 192.168.1.2 cookie server02 |
| 632 | |
| 633 | # simultaneous relaying of ports 80, 81 and 8080-8089 |
| 634 | |
| 635 | listen http_proxy :80,:81,:8080-8089 |
| 636 | mode http |
| 637 | cookie SERVERID |
| 638 | balance roundrobin |
| 639 | server web1 192.168.1.1 cookie server01 |
| 640 | server web2 192.168.1.2 cookie server02 |
| 641 | |
| 642 | # relaying of TCP ports 25, 389 and 663 to ports 1025, 1389 and 1663 |
| 643 | |
| 644 | listen http_proxy :25,:389,:663 |
| 645 | mode tcp |
| 646 | balance roundrobin |
| 647 | server srv1 192.168.1.1:+1000 |
| 648 | server srv2 192.168.1.2:+1000 |
| 649 | |
| 650 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 651 | 3.1) Server monitoring |
| 652 | ---------------------- |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 653 | |
| 654 | It is possible to check the servers status by trying to establish TCP |
| 655 | connections or even sending HTTP requests to them. A server which fails to |
| 656 | reply to health checks as expected will not be used by the load balancing |
| 657 | algorithms. To enable monitoring, add the 'check' keyword on a server line. |
| 658 | It is possible to specify the interval between tests (in milliseconds) with |
| 659 | the 'inter' parameter, the number of failures supported before declaring that |
| 660 | the server has fallen down with the 'fall' parameter, and the number of valid |
| 661 | checks needed for the server to fully get up with the 'rise' parameter. Since |
| 662 | version 1.1.22, it is also possible to send checks to a different port |
| 663 | (mandatory when none is specified) with the 'port' parameter. The default |
| 664 | values are the following ones : |
| 665 | |
| 666 | - inter : 2000 |
| 667 | - rise : 2 |
| 668 | - fall : 3 |
| 669 | - port : default server port |
| 670 | |
| 671 | The default mode consists in establishing TCP connections only. But in certain |
| 672 | types of application failures, it is often that the server continues to accept |
| 673 | connections because the system does it itself while the application is running |
| 674 | an endless loop, or is completely stuck. So in version 1.1.16 were introduced |
| 675 | HTTP health checks which only performed simple lightweight requests and analysed |
| 676 | the response. Now, as of version 1.1.23, it is possible to change the HTTP |
| 677 | method, the URI, and the HTTP version string (which even allows to send headers |
| 678 | with a dirty trick). To enable HTTP health-checks, use 'option httpchk'. |
| 679 | |
| 680 | By default, requests use the 'OPTIONS' method because it's very light and easy |
| 681 | to filter from logs, and does it on '/'. Only HTTP responses 2xx and 3xx are |
| 682 | considered valid ones, and only if they come before the time to send a new |
| 683 | request is reached ('inter' parameter). If some servers block this type of |
| 684 | request, 3 other forms help to forge a request : |
| 685 | |
| 686 | - option httpchk -> OPTIONS / HTTP/1.0 |
| 687 | - option httpchk URI -> OPTIONS <URI> HTTP/1.0 |
| 688 | - option httpchk METH URI -> <METH> <URI> HTTP/1.0 |
| 689 | - option httpchk METH URI VER -> <METH> <URI> <VER> |
| 690 | |
| 691 | See examples below. |
| 692 | |
| 693 | Since version 1.1.17, it is possible to specify backup servers. These servers |
| 694 | are only sollicited when no other server is available. This may only be useful |
| 695 | to serve a maintenance page, or define one active and one backup server (seldom |
| 696 | used in TCP mode). To make a server a backup one, simply add the 'backup' option |
| 697 | on its line. These servers also support cookies, so if a cookie is specified for |
| 698 | a backup server, clients assigned to this server will stick to it even when the |
| 699 | other ones come back. Conversely, if no cookie is assigned to such a server, |
| 700 | the clients will get their cookies removed (empty cookie = removal), and will |
| 701 | be balanced against other servers once they come back. Please note that there |
| 702 | is no load-balancing among backup servers. If there are several backup servers, |
| 703 | the second one will only be used when the first one dies, and so on. |
| 704 | |
| 705 | Since version 1.1.17, it is also possible to visually check the status of all |
| 706 | servers at once. For this, you just have to send a SIGHUP signal to the proxy. |
| 707 | The servers status will be dumped into the logs at the 'notice' level, as well |
| 708 | as on <stderr> if not closed. For this reason, it's always a good idea to have |
| 709 | one local log server at the 'notice' level. |
| 710 | |
| 711 | Examples : |
| 712 | ---------- |
| 713 | # same setup as in paragraph 3) with TCP monitoring |
| 714 | listen http_proxy 0.0.0.0:80 |
| 715 | mode http |
| 716 | cookie SERVERID |
| 717 | balance roundrobin |
| 718 | server web1 192.168.1.1:80 cookie server01 check |
| 719 | server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2 |
| 720 | |
| 721 | # same with HTTP monitoring via 'OPTIONS / HTTP/1.0' |
| 722 | listen http_proxy 0.0.0.0:80 |
| 723 | mode http |
| 724 | cookie SERVERID |
| 725 | balance roundrobin |
| 726 | option httpchk |
| 727 | server web1 192.168.1.1:80 cookie server01 check |
| 728 | server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2 |
| 729 | |
| 730 | # same with HTTP monitoring via 'OPTIONS /index.html HTTP/1.0' |
| 731 | listen http_proxy 0.0.0.0:80 |
| 732 | mode http |
| 733 | cookie SERVERID |
| 734 | balance roundrobin |
| 735 | option httpchk /index.html |
| 736 | server web1 192.168.1.1:80 cookie server01 check |
| 737 | server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2 |
| 738 | |
| 739 | # same with HTTP monitoring via 'HEAD /index.jsp? HTTP/1.1\r\nHost: www' |
| 740 | listen http_proxy 0.0.0.0:80 |
| 741 | mode http |
| 742 | cookie SERVERID |
| 743 | balance roundrobin |
| 744 | option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www |
| 745 | server web1 192.168.1.1:80 cookie server01 check |
| 746 | server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2 |
| 747 | |
| 748 | # automatic insertion of a cookie in the server's response, and automatic |
| 749 | # deletion of the cookie in the client request, while asking upstream caches |
| 750 | # not to cache replies. |
| 751 | listen web_appl 0.0.0.0:80 |
| 752 | mode http |
| 753 | cookie SERVERID insert nocache indirect |
| 754 | balance roundrobin |
| 755 | server web1 192.168.1.1:80 cookie server01 check |
| 756 | server web2 192.168.1.2:80 cookie server02 check |
| 757 | |
| 758 | # same with off-site application backup and local error pages server |
| 759 | listen web_appl 0.0.0.0:80 |
| 760 | mode http |
| 761 | cookie SERVERID insert nocache indirect |
| 762 | balance roundrobin |
| 763 | server web1 192.168.1.1:80 cookie server01 check |
| 764 | server web2 192.168.1.2:80 cookie server02 check |
| 765 | server web-backup 192.168.2.1:80 cookie server03 check backup |
| 766 | server web-excuse 192.168.3.1:80 check backup |
| 767 | |
| 768 | # SMTP+TLS relaying with heakth-checks and backup servers |
| 769 | |
| 770 | listen http_proxy :25,:587 |
| 771 | mode tcp |
| 772 | balance roundrobin |
| 773 | server srv1 192.168.1.1 check port 25 inter 30000 rise 1 fall 2 |
| 774 | server srv2 192.168.1.2 backup |
| 775 | |
| 776 | |
| 777 | 3.2) Redistribute connections in case of failure |
| 778 | ------------------------------------------------ |
| 779 | In HTTP mode, if a server designated by a cookie does not respond, the clients |
| 780 | may definitely stick to it because they cannot flush the cookie, so they will |
| 781 | not be able to access the service anymore. Specifying 'redispatch' will allow |
| 782 | the proxy to break their persistence and redistribute them to working servers. |
| 783 | |
| 784 | Example : |
| 785 | --------- |
| 786 | listen http_proxy 0.0.0.0:80 |
| 787 | mode http |
| 788 | cookie SERVERID |
| 789 | dispatch 192.168.1.100:80 |
| 790 | server web1 192.168.1.1:80 cookie server01 |
| 791 | server web2 192.168.1.2:80 cookie server02 |
| 792 | redispatch # send back to dispatch in case of connection failure |
| 793 | |
| 794 | Up to, and including version 1.1.16, this parameter only applied to connection |
| 795 | failures. Since version 1.1.17, it also applies to servers which have been |
| 796 | detected as failed by the health check mechanism. Indeed, a server may be broken |
| 797 | but still accepting connections, which would not solve every case. But it is |
| 798 | possible to conserve the old behaviour, that is, make a client insist on trying |
| 799 | to connect to a server even if it is said to be down, by setting the 'persist' |
| 800 | option : |
| 801 | |
| 802 | listen http_proxy 0.0.0.0:80 |
| 803 | mode http |
| 804 | option persist |
| 805 | cookie SERVERID |
| 806 | dispatch 192.168.1.100:80 |
| 807 | server web1 192.168.1.1:80 cookie server01 |
| 808 | server web2 192.168.1.2:80 cookie server02 |
| 809 | redispatch # send back to dispatch in case of connection failure |
| 810 | |
| 811 | |
| 812 | 4) Additionnal features |
| 813 | ======================= |
| 814 | |
| 815 | Other features are available. They are transparent mode, event logging and |
| 816 | header rewriting/filtering. |
| 817 | |
| 818 | 4.1) Transparent mode |
| 819 | --------------------- |
| 820 | In HTTP mode, the 'transparent' keyword allows to intercept sessions which are |
| 821 | routed through the system hosting the proxy. This mode was implemented as a |
| 822 | replacement for the 'dispatch' mode, since connections without cookie will be |
| 823 | sent to the original address while known cookies will be sent to the servers. |
| 824 | This mode implies that the system can redirect sessions to a local port. |
| 825 | |
| 826 | Example : |
| 827 | --------- |
| 828 | listen http_proxy 0.0.0.0:65000 |
| 829 | mode http |
| 830 | transparent |
| 831 | cookie SERVERID |
| 832 | server server01 192.168.1.1:80 |
| 833 | server server02 192.168.1.2:80 |
| 834 | |
| 835 | # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \ |
| 836 | --dport 80 -j REDIRECT --to-ports 65000 |
| 837 | |
| 838 | Note : |
| 839 | ------ |
| 840 | If the port is left unspecified on the server, the port the client connected to |
| 841 | will be used. This allows to relay a full port range without using transparent |
| 842 | mode nor thousands of file descriptors, provided that the system can redirect |
| 843 | sessions to local ports. |
| 844 | |
| 845 | Example : |
| 846 | --------- |
| 847 | # redirect all ports to local port 65000, then forward to the server on the |
| 848 | # original port. |
| 849 | listen http_proxy 0.0.0.0:65000 |
| 850 | mode tcp |
| 851 | server server01 192.168.1.1 check port 60000 |
| 852 | server server02 192.168.1.2 check port 60000 |
| 853 | |
| 854 | # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \ |
| 855 | -j REDIRECT --to-ports 65000 |
| 856 | |
| 857 | |
| 858 | 4.2) Event logging |
| 859 | ------------------ |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 860 | 4.2.1) Log levels |
| 861 | ----------------- |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 862 | TCP and HTTP connections can be logged with informations such as date, time, |
| 863 | source IP address, destination address, connection duration, response times, |
| 864 | HTTP request, the HTTP return code, number of bytes transmitted, the conditions |
| 865 | in which the session ended, and even exchanged cookies values, to track a |
| 866 | particular user's problems for example. All messages are sent to up to two |
| 867 | syslog servers. Consult section 1.1 for more info about log facilities. The |
| 868 | syntax follows : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 869 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 870 | log <address_1> <facility_1> [max_level_1] |
| 871 | log <address_2> <facility_2> [max_level_2] |
| 872 | or |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 873 | log global |
| 874 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 875 | Note : |
| 876 | ------ |
| 877 | The particular syntax 'log global' means that the same log configuration as the |
| 878 | 'global' section will be used. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 879 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 880 | Example : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 881 | --------- |
| 882 | listen http_proxy 0.0.0.0:80 |
| 883 | mode http |
| 884 | log 192.168.2.200 local3 |
| 885 | log 192.168.2.201 local4 |
| 886 | |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 887 | 4.2.2) Log format |
| 888 | ----------------- |
| 889 | By default, connections are logged at the TCP level, as soon as the session |
| 890 | establishes between the client and the proxy. By enabling the 'tcplog' option, |
| 891 | the proxy will wait until the session ends to generate an enhanced log |
| 892 | containing more information such as session duration and its state during the |
| 893 | disconnection. |
| 894 | |
| 895 | Another option, 'httplog', provides more detailed information about HTTP |
| 896 | contents, such as the request and some cookies. In the event where an external |
| 897 | component would establish frequent connections to check the service, logs may be |
| 898 | full of useless lines. So it is possible not to log any session which didn't |
| 899 | transfer any data, by the setting of the 'dontlognull' option. This only has |
| 900 | effect on sessions which are established then closed. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 901 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 902 | Example : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 903 | --------- |
| 904 | listen http_proxy 0.0.0.0:80 |
| 905 | mode http |
| 906 | option httplog |
| 907 | option dontlognull |
| 908 | log 192.168.2.200 local3 |
| 909 | |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 910 | 4.2.3) Timing events |
| 911 | -------------------- |
| 912 | Timers provide a great help in trouble shooting network problems. All values |
| 913 | are reported in milliseconds (ms). In HTTP mode, four control points are |
| 914 | reported under the form 'Tq/Tc/Tr/Tt' : |
| 915 | |
| 916 | - Tq: total time to get the client request. |
| 917 | It's the time elapsed between the moment the client connection was accepted |
| 918 | and the moment the proxy received the last HTTP header. The value '-1' |
| 919 | indicates that the end of headers (empty line) has never been seen. |
| 920 | |
| 921 | - Tc: total time to establish the TCP connection to the server. |
| 922 | It's the time elapsed between the moment the proxy sent the connection |
| 923 | request, and the moment it was acknowledged, or between the TCP SYN packet |
| 924 | and the matching SYN/ACK in return. The value '-1' means that the |
| 925 | connection never established. |
| 926 | |
| 927 | - Tr: server response time. It's the time elapsed between the moment the |
| 928 | TCP connection was established to the server and the moment it send its |
| 929 | complete response header. It purely shows its request processing time, |
| 930 | without the network overhead due to the data transmission. The value '-1' |
| 931 | means that the last the response header (empty line) was never seen. |
| 932 | |
| 933 | - Tt: total session duration time, between the moment the proxy accepted it |
| 934 | and the moment both ends were closed. From this one, we can deduce Td, |
| 935 | the data transmission time, by substracting other timers when valid : |
| 936 | |
| 937 | Td = Tt - (Tq + Tc + Tr) |
| 938 | |
| 939 | Timers with '-1' values have to be excluded from this equation. |
| 940 | |
| 941 | In TCP mode ('option tcplog'), only Tc and Tt are reported. |
| 942 | |
| 943 | These timers provide precious indications on trouble causes. Since the TCP |
| 944 | protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure |
| 945 | that timers close to multiples of 3s are nearly always related to packets lost |
| 946 | due to network problems (wires or negociation). Moreover, if <Tt> is close to |
| 947 | a timeout value specified in the configuration, it often means that a session |
| 948 | has been aborted on time-out. |
| 949 | |
| 950 | Most common cases : |
| 951 | |
| 952 | - If Tq is close to 3000, a packet has probably been lost between the client |
| 953 | and the proxy. |
| 954 | - If Tc is close to 3000, a packet has probably been lost between the server |
| 955 | and the proxy during the server connection phase. This one should always be |
| 956 | very low (less than a few tens). |
| 957 | - If Tr is nearly always lower than 3000 except some rare values which seem to |
| 958 | be the average majored by 3000, there are probably some packets lost between |
| 959 | the proxy and the server. |
| 960 | - If Tt is often slightly higher than a time-out, it's often because the |
| 961 | client and the server use HTTP keep-alive and the session is maintained |
| 962 | after the response ends. Se further for how to disable HTTP keep-alive. |
| 963 | |
| 964 | Other cases ('xx' means any value to be ignored) : |
| 965 | -1/xx/xx/Tt : the client was not able to send its complete request in time, |
| 966 | or that it aborted it too early. |
| 967 | Tq/-1/xx/Tt : the connection could not establish on the server. Either it |
| 968 | refused it or it timed out after Tt-Tq ms. |
| 969 | Tq/Tc/-1/Tt : the server has accepted the connection but did not return a |
| 970 | complete response in time, or it closed its connexion |
| 971 | unexpectedly, after Tt-(Tq+Tc) ms. |
| 972 | |
| 973 | 4.2.4) Session state at disconnection |
| 974 | ------------------------------------- |
| 975 | TCP and HTTP logs provide a session completion indicator. It's a 4-characters |
| 976 | (2 in TCP) field preceeding the HTTP request, and indicating : |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 977 | - On the first character, a code reporting the first event which caused the |
| 978 | session to terminate : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 979 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 980 | C : the TCP session was aborted by the client. |
| 981 | S : the TCP session was aborted by the server, or the server refused it. |
| 982 | P : the session was abordted prematurely by the proxy, either because of |
| 983 | an internal error, or because a DENY filter was matched. |
| 984 | c : the client time-out expired first. |
| 985 | s : the server time-out expired first. |
| 986 | - : normal session completion. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 987 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 988 | - on the second character, the HTTP session state when it was closed : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 989 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 990 | R : waiting for complete REQUEST from the client |
| 991 | C : waiting for CONNECTION to establish on the server |
| 992 | H : waiting for complete HEADERS from the server |
| 993 | D : the session was in the DATA phase |
| 994 | L : the proxy was still transmitting LAST data to the client while the |
| 995 | server had already finished. |
| 996 | - : normal session completion after end of data transfer. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 997 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 998 | - the third character tells whether the persistence cookie was provided by |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 999 | the client (only in HTTP mode) : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1000 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1001 | N : the client provided NO cookie. |
| 1002 | I : the client provided an INVALID cookie matching no known server. |
| 1003 | D : the client provided a cookie designating a server which was DOWN, |
| 1004 | so either the 'persist' option was used and the client was sent to |
| 1005 | this server, or it was not set and the client was redispatched to |
| 1006 | another server. |
| 1007 | V : the client provided a valid cookie, and was sent to the associated |
| 1008 | server. |
| 1009 | - : does not apply (no cookie set in configuration). |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1010 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1011 | - the last character reports what operations were performed on the persistence |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 1012 | cookie returned by the server (only in HTTP mode) : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1013 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1014 | N : NO cookie was provided by the server. |
| 1015 | P : a cookie was PROVIDED by the server and transmitted as-is. |
| 1016 | I : no cookie was provided by the server, and one was INSERTED by the |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1017 | proxy. |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1018 | D : the cookie provided by the server was DELETED by the proxy. |
| 1019 | R : the cookie provided by the server was REWRITTEN by the proxy. |
| 1020 | - : does not apply (no cookie set in configuration). |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1021 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1022 | The 'capture' keyword allows to capture and log informations exchanged between |
| 1023 | clients and servers. As of version 1.1.23, only cookies can be captured, which |
| 1024 | makes it easy to track a complete user session. The syntax is : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1025 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1026 | capture cookie <cookie_prefix> len <capture_length> |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1027 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1028 | The FIRST cookie whose name starts with <cookie_prefix> will be captured, and |
| 1029 | logged as 'NAME=value', without exceeding <capture_length> characters (64 max). |
| 1030 | When the cookie name is fixed and known, it's preferable to suffix '=' to it to |
| 1031 | ensure that no other cookie will be logged. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1032 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1033 | Examples : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1034 | ---------- |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1035 | # capture the first cookie whose name starts with "ASPSESSION" |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1036 | capture cookie ASPSESSION len 32 |
| 1037 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1038 | # capture the first cookie whose name is exactly "vgnvisitor" |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1039 | capture cookie vgnvisitor= len 32 |
| 1040 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1041 | In the logs, the field preceeding the completion indicator contains the cookie |
| 1042 | value as sent by the server, preceeded by the cookie value as sent by the |
| 1043 | client. Each of these field is replaced with '-' when no cookie was seen. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1044 | |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 1045 | 4.2.5) Examples of logs |
| 1046 | ----------------------- |
| 1047 | - haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57] relais-http Srv1 6559/7/147/6723 200 243 - - ---- "HEAD / HTTP/1.0" |
| 1048 | => long request (6.5s) entered by hand through 'telnet'. The server replied |
| 1049 | in 147 ms, and the session ended normally ('----') |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1050 | |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 1051 | - haproxy[18113]: 127.0.0.1:34548 [15/Oct/2003:15:18:55] relais-http <NOSRV> -1/-1/-1/8490 -1 0 - - CR-- "" |
| 1052 | => the client never completed its request and aborted itself ('C---') after |
| 1053 | 8.5s, while the proxy was waiting for the request headers ('-R--'). |
| 1054 | Nothing was sent to the server. |
| 1055 | |
| 1056 | - haproxy[18113]: 127.0.0.1:34549 [15/Oct/2003:15:19:06] relais-http <NOSRV> -1/-1/-1/50001 408 0 - - cR-- "" |
| 1057 | => The client never completed its request, which was aborted by the time-out |
| 1058 | ('c---') after 50s, while the proxy was waiting for the request headers ('-R--'). |
| 1059 | Nothing was sent to the server, but the proxy could send a 408 return code |
| 1060 | to the client. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1061 | |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 1062 | - haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28] relais-tcp Srv1 0/5007 0 cD |
| 1063 | => This is a 'tcplog' entry. Client-side time-out ('c----') occured after 5s. |
| 1064 | |
| 1065 | - haproxy[18989]: 10.0.0.1:34552 [15/Oct/2003:15:26:31] relais-http Srv1 3183/-1/-1/11215 503 0 - - SC-- "HEAD / HTTP/1.0" |
| 1066 | => The request took 3s to complete (probably a network problem), and the |
| 1067 | connection to the server failed ('SC--') after 4 attemps of 2 seconds |
| 1068 | (config says 'retries 3'), then a 503 error code was sent to the client. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1069 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1070 | 4.3) HTTP header manipulation |
| 1071 | ----------------------------- |
| 1072 | In HTTP mode, it is possible to rewrite, add or delete some of the request and |
| 1073 | response headers based on regular expressions. It is also possible to block a |
| 1074 | request or a response if a particular header matches a regular expression, |
| 1075 | which is enough to stops most elementary protocol attacks, and to protect |
| 1076 | against information leak from the internal network. But there is a limitation |
| 1077 | to this : since haproxy's HTTP engine knows nothing about keep-alive, only |
| 1078 | headers passed during the first request of a TCP session will be seen. All |
| 1079 | subsequent headers will be considered data only and not analyzed. Furthermore, |
| 1080 | haproxy doesn't touch data contents, it stops at the end of headers. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1081 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1082 | The syntax is : |
| 1083 | reqadd <string> to add a header to the request |
| 1084 | reqrep <search> <replace> to modify the request |
| 1085 | reqirep <search> <replace> same, but ignoring the case |
| 1086 | reqdel <search> to delete a header in the request |
| 1087 | reqidel <search> same, but ignoring the case |
| 1088 | reqallow <search> definitely allow a request if a header matches <search> |
| 1089 | reqiallow <search> same, but ignoring the case |
| 1090 | reqdeny <search> denies a request if a header matches <search> |
| 1091 | reqideny <search> same, but ignoring the case |
| 1092 | reqpass <search> ignore a header matching <search> |
| 1093 | reqipass <search> same, but ignoring the case |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1094 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1095 | rspadd <string> to add a header to the response |
| 1096 | rsprep <search> <replace> to modify the response |
| 1097 | rspirep <search> <replace> same, but ignoring the case |
| 1098 | rspdel <search> to delete the response |
| 1099 | rspidel <search> same, but ignoring the case |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1100 | |
| 1101 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1102 | <search> is a POSIX regular expression (regex) which supports grouping through |
| 1103 | parenthesis (without the backslash). Spaces and other delimiters must be |
| 1104 | prefixed with a backslash ('\') to avoid confusion with a field delimiter. |
| 1105 | Other characters may be prefixed with a backslash to change their meaning : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1106 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1107 | \t for a tab |
| 1108 | \r for a carriage return (CR) |
| 1109 | \n for a new line (LF) |
| 1110 | \ to mark a space and differentiate it from a delimiter |
| 1111 | \# to mark a sharp and differentiate it from a comment |
| 1112 | \\ to use a backslash in a regex |
| 1113 | \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy) |
| 1114 | \xXX to write the ASCII hex code XX as in the C language |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1115 | |
| 1116 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1117 | <replace> containst the string to be used to replace the largest portion of text |
| 1118 | matching the regex. It can make use of the special characters above, and can |
| 1119 | reference a substring delimited by parenthesis in the regex, by the group |
| 1120 | numerical order from 1 to 9. In this case, you would write a backslah ('\') |
| 1121 | immediately followed by one digit indicating the group position. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1122 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1123 | <string> represents the string which will systematically be added after the last |
| 1124 | header line. It can also use special characters above. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1125 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1126 | Notes : |
| 1127 | ------- |
| 1128 | - the first line is considered as a header, which makes it possible to rewrite |
| 1129 | or filter HTTP requests URIs or response codes. |
| 1130 | - 'reqrep' is the equivalent of 'cliexp' in version 1.0, and 'rsprep' is the |
| 1131 | equivalent of 'srvexp' in 1.0. Those names are still supported but |
| 1132 | deprecated. |
| 1133 | - for performances reasons, the number of characters added to a request or to |
| 1134 | a response is limited to 4096 since version 1.1.5 (it was 256 before). This |
| 1135 | value is easy to modify in the code if needed (#define). If it is too short |
| 1136 | on occasional uses, it is possible to gain some space by removing some |
| 1137 | useless headers before adding new ones. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1138 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1139 | Examples : |
| 1140 | ---------- |
| 1141 | ###### a few examples ###### |
| 1142 | |
| 1143 | # rewrite 'online.fr' instead of 'free.fr' for GET and POST requests |
| 1144 | reqrep ^(GET\ .*)(.free.fr)(.*) \1.online.fr\3 |
| 1145 | reqrep ^(POST\ .*)(.free.fr)(.*) \1.online.fr\3 |
| 1146 | |
| 1147 | # force proxy connections to close |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1148 | reqirep ^Proxy-Connection:.* Proxy-Connection:\ close |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1149 | # rewrite locations |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1150 | rspirep ^(Location:\ )([^:]*://[^/]*)(.*) \1\3 |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1151 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1152 | ###### A full configuration being used on production ###### |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1153 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1154 | # Every header should end with a colon followed by one space. |
| 1155 | reqideny ^[^:\ ]*[\ ]*$ |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1156 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1157 | # block Apache chunk exploit |
| 1158 | reqideny ^Transfer-Encoding:[\ ]*chunked |
| 1159 | reqideny ^Host:\ apache- |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1160 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1161 | # block annoying worms that fill the logs... |
| 1162 | reqideny ^[^:\ ]*\ .*(\.|%2e)(\.|%2e)(%2f|%5c|/|\\\\) |
| 1163 | reqideny ^[^:\ ]*\ ([^\ ]*\ [^\ ]*\ |.*%00) |
| 1164 | reqideny ^[^:\ ]*\ .*<script |
| 1165 | reqideny ^[^:\ ]*\ .*/(root\.exe\?|cmd\.exe\?|default\.ida\?) |
| 1166 | |
| 1167 | # allow other syntactically valid requests, and block any other method |
| 1168 | reqipass ^(GET|POST|HEAD|OPTIONS)\ /.*\ HTTP/1\.[01]$ |
| 1169 | reqipass ^OPTIONS\ \\*\ HTTP/1\.[01]$ |
| 1170 | reqideny ^[^:\ ]*\ |
| 1171 | |
| 1172 | # force connection:close, thus disabling HTTP keep-alive |
| 1173 | reqidel ^Connection: |
| 1174 | rspidel ^Connection: |
| 1175 | reqadd Connection:\ close |
| 1176 | rspadd Connection:\ close |
| 1177 | |
| 1178 | # change the server name |
| 1179 | rspidel ^Server:\ |
| 1180 | rspadd Server:\ Formilux/0.1.8 |
| 1181 | |
| 1182 | |
willy tarreau | c1cae63 | 2005-12-17 14:12:23 +0100 | [diff] [blame] | 1183 | Last, the 'forwardfor' option creates an HTTP 'X-Forwarded-For' header which |
| 1184 | contains the client's IP address. This is useful to let the final web server |
| 1185 | know what the client address was (eg for statistics on domains). |
| 1186 | |
| 1187 | Example : |
| 1188 | --------- |
| 1189 | listen http_proxy 0.0.0.0:80 |
| 1190 | mode http |
| 1191 | log global |
| 1192 | option httplog |
| 1193 | option dontlognull |
| 1194 | option forwardfor |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1195 | |
| 1196 | 4.4) Load balancing with persistence |
| 1197 | ------------------------------------ |
| 1198 | |
| 1199 | Combining cookie insertion with internal load balancing allows to transparently |
| 1200 | bring persistence to applications. The principle is quite simple : |
| 1201 | - assign a cookie value to each server |
| 1202 | - enable the load balancing between servers |
| 1203 | - insert a cookie into responses resulting from the balancing algorithm |
| 1204 | (indirect accesses), end ensure that no upstream proxy will cache it. |
| 1205 | - remove the cookie in the request headers so that the application never sees |
| 1206 | it. |
| 1207 | |
| 1208 | Example : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1209 | --------- |
| 1210 | listen application 0.0.0.0:80 |
| 1211 | mode http |
| 1212 | cookie SERVERID insert nocache indirect |
| 1213 | balance roundrobin |
| 1214 | server 192.168.1.1:80 cookie server01 check |
| 1215 | server 192.168.1.2:80 cookie server02 check |
| 1216 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1217 | 4.5) Customizing errors |
| 1218 | ----------------------- |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1219 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1220 | Some situations can make haproxy return an HTTP error code to the client : |
| 1221 | - invalid or too long request => HTTP 400 |
| 1222 | - request not completely sent in time => HTTP 408 |
| 1223 | - forbidden request (matches a deny filter) => HTTP 403 |
| 1224 | - internal error in haproxy => HTTP 500 |
| 1225 | - the server returned an invalid or incomplete response => HTTP 502 |
| 1226 | - no server was available to handle the request => HTTP 503 |
| 1227 | - the server failed to reply in time => HTTP 504 |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1228 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1229 | A succint error message taken from the RFC accompanies these return codes. |
| 1230 | But depending on the clients knowledge, it may be better to return custom, user |
| 1231 | friendly, error pages. This is made possible through the use of the 'errorloc' |
| 1232 | command : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1233 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1234 | errorloc <HTTP_code> <location> |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1235 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1236 | Instead of generating an HTTP error <HTTP_code> among those above, the proxy |
| 1237 | will return a temporary redirection code (HTTP 302) towards the address |
| 1238 | specified in <location>. This address may be either relative to the site or |
| 1239 | absolute. Since this request will be handled by the client's browser, it's |
| 1240 | mandatory that the returned address be reachable from the outside. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1241 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1242 | Example : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1243 | --------- |
| 1244 | listen application 0.0.0.0:80 |
| 1245 | errorloc 400 /badrequest.html |
| 1246 | errorloc 403 /forbidden.html |
| 1247 | errorloc 408 /toolong.html |
| 1248 | errorloc 500 http://haproxy.domain.net/bugreport.html |
| 1249 | errorloc 502 http://192.168.114.58/error50x.html |
| 1250 | errorloc 503 http://192.168.114.58/error50x.html |
| 1251 | errorloc 504 http://192.168.114.58/error50x.html |
| 1252 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1253 | 4.6) Modifying default values |
| 1254 | ----------------------------- |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1255 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1256 | Version 1.1.22 introduced the notion of default values, which eliminates the |
| 1257 | pain of often repeating common parameters between many instances, such as |
| 1258 | logs, timeouts, modes, etc... |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1259 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1260 | Default values are set in a 'defaults' section. Each of these section clears |
| 1261 | all previously set default parameters, so there may be as many default |
| 1262 | parameters as needed. Only the last one before a 'listen' section will be |
| 1263 | used for this section. The 'defaults' section uses the same syntax as the |
| 1264 | 'listen' section, for the supported parameters. The 'defaults' keyword ignores |
| 1265 | everything on its command line, so that fake instance names can be specified |
| 1266 | there for better clarity. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1267 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1268 | In version 1.1.23, only those parameters can be preset in the 'default' |
| 1269 | section : |
| 1270 | - log (the first and second one) |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1271 | - mode { tcp, http, health } |
| 1272 | - balance { roundrobin } |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1273 | - disabled (to disable every further instances) |
| 1274 | - enabled (to enable every further instances, this is the default) |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1275 | - contimeout, clitimeout, srvtimeout, grace, retries, maxconn |
| 1276 | - option { redispatch, transparent, keepalive, forwardfor, httplog, |
| 1277 | dontlognull, persist, httpchk } |
| 1278 | - redispatch, redisp, transparent, source { addr:port } |
| 1279 | - cookie, capture |
| 1280 | - errorloc |
| 1281 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1282 | As of 1.1.24, it is not possible to put certain parameters in a 'defaults' |
| 1283 | section, mainly regular expressions and server configurations : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1284 | - dispatch, server, |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1285 | - req*, rsp* |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1286 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1287 | Last, there's no way yet to change a boolean option from its assigned default |
| 1288 | value. So if an 'option' statement is set in a 'defaults' section, the only |
| 1289 | way to flush it is to redefine a new 'defaults' section without this 'option'. |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1290 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1291 | Examples : |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1292 | ---------- |
| 1293 | defaults applications TCP |
| 1294 | log global |
| 1295 | mode tcp |
| 1296 | balance roundrobin |
| 1297 | clitimeout 180000 |
| 1298 | srvtimeout 180000 |
| 1299 | contimeout 4000 |
| 1300 | retries 3 |
| 1301 | redispatch |
| 1302 | |
| 1303 | listen app_tcp1 10.0.0.1:6000-6063 |
| 1304 | server srv1 192.168.1.1 check port 6000 inter 10000 |
| 1305 | server srv2 192.168.1.2 backup |
| 1306 | |
| 1307 | listen app_tcp2 10.0.0.2:6000-6063 |
| 1308 | server srv1 192.168.2.1 check port 6000 inter 10000 |
| 1309 | server srv2 192.168.2.2 backup |
| 1310 | |
| 1311 | defaults applications HTTP |
| 1312 | log global |
| 1313 | mode http |
| 1314 | option httplog |
| 1315 | option forwardfor |
| 1316 | option dontlognull |
| 1317 | balance roundrobin |
| 1318 | clitimeout 20000 |
| 1319 | srvtimeout 20000 |
| 1320 | contimeout 4000 |
| 1321 | retries 3 |
| 1322 | |
| 1323 | listen app_http1 10.0.0.1:80-81 |
| 1324 | cookie SERVERID postonly insert indirect |
| 1325 | capture cookie userid= len 10 |
| 1326 | server srv1 192.168.1.1:+8000 cookie srv1 check port 8080 inter 1000 |
| 1327 | server srv1 192.168.1.2:+8000 cookie srv2 check port 8080 inter 1000 |
| 1328 | |
| 1329 | defaults |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1330 | # this empty section voids all default parameters |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1331 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1332 | ========================= |
| 1333 | | System-specific setup | |
| 1334 | ========================= |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1335 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1336 | Linux 2.4 |
| 1337 | ========= |
willy tarreau | eedaa9f | 2005-12-17 14:08:03 +0100 | [diff] [blame] | 1338 | |
| 1339 | -- cut here -- |
| 1340 | #!/bin/sh |
| 1341 | # set this to about 256/4M (16384 for 256M machine) |
| 1342 | MAXFILES=16384 |
| 1343 | echo $MAXFILES > /proc/sys/fs/file-max |
| 1344 | ulimit -n $MAXFILES |
| 1345 | |
| 1346 | if [ -e /proc/sys/net/ipv4/ip_conntrack_max ]; then |
| 1347 | echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max |
| 1348 | fi |
| 1349 | |
| 1350 | if [ -e /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait ]; then |
| 1351 | # 30 seconds for fin, 15 for time wait |
| 1352 | echo 3000 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait |
| 1353 | echo 1500 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_time_wait |
| 1354 | echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_invalid_scale |
| 1355 | echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_out_of_window |
| 1356 | fi |
| 1357 | |
| 1358 | echo 1024 60999 > /proc/sys/net/ipv4/ip_local_port_range |
| 1359 | echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout |
| 1360 | echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog |
| 1361 | echo 262144 > /proc/sys/net/ipv4/tcp_max_tw_buckets |
| 1362 | echo 262144 > /proc/sys/net/ipv4/tcp_max_orphans |
| 1363 | echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time |
| 1364 | echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle |
| 1365 | echo 0 > /proc/sys/net/ipv4/tcp_timestamps |
| 1366 | echo 0 > /proc/sys/net/ipv4/tcp_ecn |
| 1367 | echo 0 > /proc/sys/net/ipv4/tcp_sack |
| 1368 | echo 0 > /proc/sys/net/ipv4/tcp_dsack |
| 1369 | |
| 1370 | # auto-tuned on 2.4 |
| 1371 | #echo 262143 > /proc/sys/net/core/rmem_max |
| 1372 | #echo 262143 > /proc/sys/net/core/rmem_default |
| 1373 | |
| 1374 | echo 16384 65536 524288 > /proc/sys/net/ipv4/tcp_rmem |
| 1375 | echo 16384 349520 699040 > /proc/sys/net/ipv4/tcp_wmem |
| 1376 | |
| 1377 | -- cut here -- |
| 1378 | |
willy tarreau | 197e8ec | 2005-12-17 14:10:59 +0100 | [diff] [blame] | 1379 | |
| 1380 | FreeBSD |
| 1381 | ======= |
| 1382 | |
| 1383 | A FreeBSD port of HA-Proxy is now available and maintained, thanks to |
| 1384 | Clement Laforet <sheepkiller@cultdeadsheep.org>. |
| 1385 | |
| 1386 | For more information : |
| 1387 | http://www.freebsd.org/cgi/url.cgi?ports/net/haproxy/pkg-descr |
| 1388 | http://www.freebsd.org/cgi/cvsweb.cgi/ports/net/haproxy/ |
| 1389 | http://www.freshports.org/net/haproxy |
| 1390 | |
| 1391 | |
| 1392 | -- end -- |