blob: 09d311e52e6ca3669f9eb861e6f2d68398aae97a [file] [log] [blame]
willy tarreau0174f312005-12-18 01:02:42 +01001 -------------------
Willy Tarreau94b45912006-05-31 06:40:15 +02002 HAProxy
willy tarreau0174f312005-12-18 01:02:42 +01003 Reference Manual
4 -------------------
Willy Tarreau2272dc12006-09-03 10:19:38 +02005 version 1.3.2
willy tarreauc5f73ed2005-12-18 01:26:38 +01006 willy tarreau
Willy Tarreau2272dc12006-09-03 10:19:38 +02007 2006/09/03
willy tarreaueedaa9f2005-12-17 14:08:03 +01008
9============
10| Abstract |
11============
12
Willy Tarreau94b45912006-05-31 06:40:15 +020013HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high
willy tarreaueedaa9f2005-12-17 14:08:03 +010014availability environments. Indeed, it can :
15 - route HTTP requests depending on statically assigned cookies ;
16 - spread the load among several servers while assuring server persistence
17 through the use of HTTP cookies ;
18 - switch to backup servers in the event a main one fails ;
19 - accept connections to special ports dedicated to service monitoring ;
20 - stop accepting connections without breaking existing ones ;
21 - add/modify/delete HTTP headers both ways ;
22 - block requests matching a particular pattern ;
willy tarreau532bb552006-05-13 18:40:37 +020023 - hold clients to the right application server depending on application
24 cookies
willy tarreau481132e2006-05-21 21:43:10 +020025 - report detailed status as HTML pages to authenticated users from an URI
26 intercepted from the application.
willy tarreaueedaa9f2005-12-17 14:08:03 +010027
28It needs very little resource. Its event-driven architecture allows it to easily
29handle thousands of simultaneous connections on hundreds of instances without
30risking the system's stability.
31
32====================
33| Start parameters |
34====================
35
36There are only a few command line options :
37
38 -f <configuration file>
39 -n <high limit for the total number of simultaneous connections>
willy tarreau532bb552006-05-13 18:40:37 +020040 = 'maxconn' in 'global' section
41 -N <high limit for the per-listener number of simultaneous connections>
42 = 'maxconn' in 'listen' or 'default' sections
willy tarreaueedaa9f2005-12-17 14:08:03 +010043 -d starts in foregreound with debugging mode enabled
44 -D starts in daemon mode
willy tarreau982249e2005-12-18 00:57:06 +010045 -q disable messages on output
46 -V displays messages on output even when -q or 'quiet' are specified.
47 -c only checks config file and exits with code 0 if no error was found, or
48 exits with code 1 if a syntax error was found.
willy tarreaufe2c5c12005-12-17 14:14:34 +010049 -p <pidfile> asks the process to write down each of its children's
50 pids to this file in daemon mode.
willy tarreau34f45302006-04-15 21:37:14 +020051 -sf specifies a list of pids to send a FINISH signal to after startup.
52 -st specifies a list of pids to send a TERMINATE signal to after startup.
willy tarreaueedaa9f2005-12-17 14:08:03 +010053 -s shows statistics (only if compiled in)
54 -l shows even more statistics (implies '-s')
Willy Tarreaude99e992007-04-16 00:53:59 +020055 -dk disables use of kqueue()
56 -ds disables use of speculative epoll()
willy tarreau64a3cc32005-12-18 01:13:11 +010057 -de disables use of epoll()
58 -dp disables use of poll()
willy tarreau34f45302006-04-15 21:37:14 +020059 -db disables background mode (stays in foreground, useful for debugging)
60 -m <megs> enforces a memory usage limit to a maximum of <megs> megabytes.
willy tarreaueedaa9f2005-12-17 14:08:03 +010061
willy tarreau532bb552006-05-13 18:40:37 +020062The maximal number of connections per proxy instance is used as the default
63parameter for each instance for which the 'maxconn' paramter is not set in the
64'listen' section.
willy tarreaueedaa9f2005-12-17 14:08:03 +010065
66The maximal number of total connections limits the number of connections used by
67the whole process if the 'maxconn' parameter is not set in the 'global' section.
68
69The debugging mode has the same effect as the 'debug' option in the 'global'
70section. When the proxy runs in this mode, it dumps every connections,
71disconnections, timestamps, and HTTP headers to stdout. This should NEVER
72be used in an init script since it will prevent the system from starting up.
73
willy tarreau34f45302006-04-15 21:37:14 +020074For debugging, the '-db' option is very useful as it temporarily disables
75daemon mode and multi-process mode. The service can then be stopped by simply
76pressing Ctrl-C, without having to edit the config nor run full debug.
77
willy tarreaueedaa9f2005-12-17 14:08:03 +010078Statistics are only available if compiled in with the 'STATTIME' option. It's
willy tarreau481132e2006-05-21 21:43:10 +020079only used during code optimization phases, and will soon disappear.
willy tarreaueedaa9f2005-12-17 14:08:03 +010080
willy tarreau532bb552006-05-13 18:40:37 +020081The '-st' and '-sf' options are used for hot reconfiguration (see below).
willy tarreau34f45302006-04-15 21:37:14 +020082
willy tarreaueedaa9f2005-12-17 14:08:03 +010083======================
84| Configuration file |
85======================
86
87Structure
88=========
89
90The configuration file parser ignores empty lines, spaces, tabs. Anything
91between a sharp ('#') not following a backslash ('\'), and the end of a line
92constitutes a comment and is ignored too.
93
94The configuration file is segmented in sections. A section begins whenever
95one of these 3 keywords are encountered :
96
97 - 'global'
98 - 'listen'
99 - 'defaults'
100
101Every parameter refer to the section beginning at the last one of these 3
102keywords.
103
104
1051) Global parameters
106====================
107
108Global parameters affect the whole process behaviour. They are all set in the
109'global' section. There may be several 'global' sections if needed, but their
110parameters will only be merged. Allowed parameters in 'global' section include
111the following ones :
112
113 - log <address> <facility> [max_level]
114 - maxconn <number>
115 - uid <user id>
116 - gid <group id>
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200117 - user <user name>
118 - group <group name>
willy tarreaueedaa9f2005-12-17 14:08:03 +0100119 - chroot <directory>
120 - nbproc <number>
121 - daemon
122 - debug
Willy Tarreaude99e992007-04-16 00:53:59 +0200123 - nokqueue
124 - nosepoll
willy tarreau64a3cc32005-12-18 01:13:11 +0100125 - noepoll
126 - nopoll
willy tarreaueedaa9f2005-12-17 14:08:03 +0100127 - quiet
willy tarreaufe2c5c12005-12-17 14:14:34 +0100128 - pidfile <file>
willy tarreauc5f73ed2005-12-18 01:26:38 +0100129 - ulimit-n <number>
willy tarreau598da412005-12-18 01:07:29 +0100130 - stats
Willy Tarreau1db37712007-06-03 17:16:49 +0200131 - tune.maxpollevents <number>
willy tarreaueedaa9f2005-12-17 14:08:03 +0100132
willy tarreauc5f73ed2005-12-18 01:26:38 +0100133
willy tarreaueedaa9f2005-12-17 14:08:03 +01001341.1) Event logging
135------------------
136Most events are logged : start, stop, servers going up and down, connections and
137errors. Each event generates a syslog message which can be sent to up to 2
138servers. The syntax is :
139
140 log <ip_address> <facility> [max_level]
141
142Connections are logged at level "info". Services initialization and servers
143going up are logged at level "notice", termination signals are logged at
144"warning", and definitive service termination, as well as loss of servers are
145logged at level "alert". The optional parameter <max_level> specifies above
146what level messages should be sent. Level can take one of these 8 values :
147
148 emerg, alert, crit, err, warning, notice, info, debug
149
150For backwards compatibility with versions 1.1.16 and earlier, the default level
151value is "debug" if not specified.
152
153Permitted facilities are :
154 kern, user, mail, daemon, auth, syslog, lpr, news,
155 uucp, cron, auth2, ftp, ntp, audit, alert, cron2,
156 local0, local1, local2, local3, local4, local5, local6, local7
157
158According to RFC3164, messages are truncated to 1024 bytes before being emitted.
159
160Example :
161---------
162 global
willy tarreauc5f73ed2005-12-18 01:26:38 +0100163 log 192.168.2.200 local3
164 log 127.0.0.1 local4 notice
165
willy tarreaueedaa9f2005-12-17 14:08:03 +0100166
1671.2) limiting the number of connections
168---------------------------------------
169It is possible and recommended to limit the global number of per-process
willy tarreauc5f73ed2005-12-18 01:26:38 +0100170connections using the 'maxconn' global keyword. Since one connection includes
171both a client and a server, it means that the max number of TCP sessions will
172be about the double of this number. It's important to understand this when
173trying to find best values for 'ulimit -n' before starting the proxy. To
174anticipate the number of sockets needed, all these parameters must be counted :
willy tarreaueedaa9f2005-12-17 14:08:03 +0100175
176 - 1 socket per incoming connection
177 - 1 socket per outgoing connection
178 - 1 socket per address/port/proxy tuple.
179 - 1 socket per server being health-checked
180 - 1 socket for all logs
181
182In simple configurations where each proxy only listens one one address/port,
willy tarreauc5f73ed2005-12-18 01:26:38 +0100183set the limit of file descriptors (ulimit -n) to
184(2 * maxconn + nbproxies + nbservers + 1). Starting with versions 1.1.32/1.2.6,
185it is now possible to set the limit in the configuration using the 'ulimit-n'
186global keyword, provided the proxy is started as root. This puts an end to the
187recurrent problem of ensuring that the system limits are adapted to the proxy
188values. Note that these limits are per-process.
189
190Example :
191---------
192 global
193 maxconn 32000
194 ulimit-n 65536
195
willy tarreaueedaa9f2005-12-17 14:08:03 +0100196
1971.3) Drop of priviledges
198------------------------
199In order to reduce the risk and consequences of attacks, in the event where a
200yet non-identified vulnerability would be successfully exploited, it's possible
201to lower the process priviledges and even isolate it in a riskless directory.
202
203In the 'global' section, the 'uid' parameter sets a numerical user identifier
204which the process will switch to after binding its listening sockets. The value
205'0', which normally represents the super-user, here indicates that the UID must
206not change during startup. It's the default behaviour. The 'gid' parameter does
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200207the same for the group identifier. If setting an uid is not possible because of
208deployment constraints, it is possible to set a user name with the 'user'
209keyword followed by a valid user name. The same is true for the gid. It is
210possible to specify a group name after the 'group' keyword.
211
212It is particularly advised against use of generic accounts such as 'nobody'
213because it has the same consequences as using 'root' if other services use
214them.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100215
216The 'chroot' parameter makes the process isolate itself in an empty directory
217just before switching its UID. This type of isolation (chroot) can sometimes
218be worked around on certain OS (Linux, Solaris), provided that the attacker
219has gained 'root' priviledges and has the ability to use or create a directory.
220For this reason, it's capital to use a dedicated directory and not to share one
221between several services of different nature. To make isolation more resistant,
222it's recommended to use an empty directory without any right, and to change the
223UID of the process so that it cannot do anything there.
224
225Note: in the event where such a vulnerability would be exploited, it's most
226likely that first attempts would kill the process due to 'Segmentation Fault',
227'Bus Error' or 'Illegal Instruction' signals. Eventhough it's true that
228isolating the server reduces the risks of intrusion, it's sometimes useful to
229find why a process dies, via the analysis of a 'core' file, although very rare
230(the last bug of this sort was fixed in 1.1.9). For security reasons, most
231systems disable the generation of core file when a process changes its UID. So
232the two workarounds are either to start the process from a restricted user
233account, which will not be able to chroot itself, or start it as root and not
234change the UID. In both cases the core will be either in the start or the chroot
235directories. Do not forget to allow core dumps prior to start the process :
236
237# ulimit -c unlimited
238
239Example :
240---------
241
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200242 # with uid/gid
willy tarreaueedaa9f2005-12-17 14:08:03 +0100243 global
willy tarreauc5f73ed2005-12-18 01:26:38 +0100244 uid 30000
245 gid 30000
246 chroot /var/chroot/haproxy
247
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200248 # with user/group
249 global
250 user haproxy
251 group public
252 chroot /var/chroot/haproxy
253
willy tarreaueedaa9f2005-12-17 14:08:03 +0100254
2551.4) Startup modes
256------------------
willy tarreau34f45302006-04-15 21:37:14 +0200257The service can start in several different modes :
willy tarreaueedaa9f2005-12-17 14:08:03 +0100258 - foreground / background
259 - quiet / normal / debug
260
261The default mode is normal, foreground, which means that the program doesn't
262return once started. NEVER EVER use this mode in a system startup script, or
263the system won't boot. It needs to be started in background, so that it
264returns immediately after forking. That's accomplished by the 'daemon' option
265in the 'global' section, which is the equivalent of the '-D' command line
266argument.
267
willy tarreau34f45302006-04-15 21:37:14 +0200268The '-db' command line argument overrides the 'daemon' and 'nbproc' global
269options to make the process run in normal, foreground mode.
270
willy tarreaueedaa9f2005-12-17 14:08:03 +0100271Moreover, certain alert messages are still sent to the standard output even
272in 'daemon' mode. To make them disappear, simply add the 'quiet' option in the
273'global' section. This option has no command-line equivalent.
274
275Last, the 'debug' mode, enabled with the 'debug' option in the 'global' section,
276and which is equivalent of the '-d' option, allows deep TCP/HTTP analysis, with
277timestamped display of each connection, disconnection, and HTTP headers for both
278ways. This mode is incompatible with 'daemon' and 'quiet' modes for obvious
279reasons.
280
willy tarreauc5f73ed2005-12-18 01:26:38 +0100281
willy tarreaueedaa9f2005-12-17 14:08:03 +01002821.5) Increasing the overall processing power
283--------------------------------------------
284On multi-processor systems, it may seem to be a shame to use only one processor,
willy tarreau982249e2005-12-18 00:57:06 +0100285eventhough the load needed to saturate a recent processor is far above common
willy tarreaueedaa9f2005-12-17 14:08:03 +0100286usage. Anyway, for very specific needs, the proxy can start several processes
287between which the operating system will spread the incoming connections. The
288number of processes is controlled by the 'nbproc' parameter in the 'global'
willy tarreau4302f492005-12-18 01:00:37 +0100289section. It defaults to 1, and obviously works only in 'daemon' mode. One
290typical usage of this parameter has been to workaround the default per-process
291file-descriptor limit that Solaris imposes to user processes.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100292
293Example :
294---------
295
296 global
willy tarreauc5f73ed2005-12-18 01:26:38 +0100297 daemon
298 quiet
299 nbproc 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100300
301
willy tarreaufe2c5c12005-12-17 14:14:34 +01003021.6) Helping process management
303-------------------------------
304Haproxy now supports the notion of pidfile. If the '-p' command line argument,
305or the 'pidfile' global option is followed with a file name, this file will be
306removed, then filled with all children's pids, one per line (only in daemon
307mode). This file is NOT within the chroot, which allows to work with a readonly
308 chroot. It will be owned by the user starting the process, and will have
309permissions 0644.
310
311Example :
312---------
313
314 global
315 daemon
316 quiet
willy tarreauc5f73ed2005-12-18 01:26:38 +0100317 nbproc 2
willy tarreaufe2c5c12005-12-17 14:14:34 +0100318 pidfile /var/run/haproxy-private.pid
319
320 # to stop only those processes among others :
321 # kill $(</var/run/haproxy-private.pid)
322
willy tarreau34f45302006-04-15 21:37:14 +0200323 # to reload a new configuration with minimal service impact and without
324 # breaking existing sessions :
Willy Tarreau10806d52007-09-09 23:49:18 +0200325 # haproxy -f haproxy.cfg -p /var/run/haproxy-private.pid -sf $(</var/run/haproxy-private.pid)
willy tarreaufe2c5c12005-12-17 14:14:34 +0100326
willy tarreau64a3cc32005-12-18 01:13:11 +01003271.7) Polling mechanisms
328-----------------------
329Starting from version 1.2.5, haproxy supports the poll() and epoll() polling
330mechanisms. On systems where select() is limited by FD_SETSIZE (like Solaris),
331poll() can be an interesting alternative. Performance tests show that Solaris'
332poll() performance does not decay as fast as the numbers of sockets increase,
333making it a safe solution for high loads. However, Solaris already uses poll()
334to emulate select(), so as long as the number of sockets has no reason to go
335higher than FD_SETSIZE, poll() should not provide any better performance. On
336Linux systems with the epoll() patch (or any 2.6 version), haproxy will use
337epoll() which is extremely fast and non dependant on the number of sockets.
338Tests have shown constant performance from 1 to 20000 simultaneous sessions.
Willy Tarreaude99e992007-04-16 00:53:59 +0200339Version 1.3.9 introduced kqueue() for FreeBSD/OpenBSD, and speculative epoll()
340which consists in trying to perform I/O before queuing the events via syscalls.
willy tarreau64a3cc32005-12-18 01:13:11 +0100341
Willy Tarreau1db37712007-06-03 17:16:49 +0200342In order to optimize latency, it is now possible to limit the number of events
343returned by a single call to poll. The limit is fixed to 200 by default. If a
344smaller latency is seeked, it may be useful to reduce this value by using the
345'tune.maxpollevents' parameter in the 'global' section. Increasing it will
346slightly save CPU cycles in presence of large number of connections.
347
Willy Tarreaude99e992007-04-16 00:53:59 +0200348Haproxy will use kqueue() or speculative epoll() when available, then epoll(),
349and will fall back to poll(), then to select(). However, if for any reason you
350need to disable epoll() or poll() (eg. because of a bug or just to compare
351performance), new global options have been created for this matter : 'nosepoll',
352'nokqueue', 'noepoll' and 'nopoll'.
willy tarreau64a3cc32005-12-18 01:13:11 +0100353
354Example :
355---------
356
357 global
358 # use only select()
359 noepoll
360 nopoll
Willy Tarreau1db37712007-06-03 17:16:49 +0200361 tune.maxpollevents 100
willy tarreau64a3cc32005-12-18 01:13:11 +0100362
363Note :
364------
365For the sake of configuration file portability, these options are accepted but
366ignored if the poll() or epoll() mechanisms have not been enabled at compile
367time.
368
Willy Tarreaude99e992007-04-16 00:53:59 +0200369To make debugging easier, the '-de' runtime argument disables epoll support,
370the '-dp' argument disables poll support, '-dk' disables kqueue and '-ds'
371disables speculative epoll(). They are respectively equivalent to 'noepoll',
372'nopoll', 'nokqueue' and 'nosepoll'.
willy tarreau64a3cc32005-12-18 01:13:11 +0100373
374
willy tarreaueedaa9f2005-12-17 14:08:03 +01003752) Declaration of a listening service
376=====================================
377
378Service sections start with the 'listen' keyword :
379
380 listen <instance_name> [ <IP_address>:<port_range>[,...] ]
381
382- <instance_name> is the name of the instance. This name will be reported in
383 logs, so it is good to have it reflect the proxied service. No unicity test
384 is done on this name, and it's not mandatory for it to be unique, but highly
385 recommended.
386
387- <IP_address> is the IP address the proxy binds to. Empty address, '*' and
388 '0.0.0.0' all mean that the proxy listens to all valid addresses on the
389 system.
390
391- <port_range> is either a unique port, or a port range for which the proxy will
392 accept connections for the IP address specified above. This range can be :
393 - a numerical port (ex: '80')
394 - a dash-delimited ports range explicitly stating the lower and upper bounds
395 (ex: '2000-2100') which are included in the range.
396
397 Particular care must be taken against port ranges, because every <addr:port>
398 couple consumes one socket (=a file descriptor), so it's easy to eat lots of
399 descriptors with a simple range. The <addr:port> couple must be used only once
400 among all instances running on a same system. Please note that attaching to
401 ports lower than 1024 need particular priviledges to start the program, which
402 are independant of the 'uid' parameter.
403
404- the <IP_address>:<port_range> couple may be repeated indefinitely to require
405 the proxy to listen to other addresses and/or ports. To achieve this, simply
406 separate them with a coma.
407
408Examples :
409---------
410 listen http_proxy :80
411 listen x11_proxy 127.0.0.1:6000-6009
412 listen smtp_proxy 127.0.0.1:25,127.0.0.1:587
413 listen ldap_proxy :389,:663
414
415In the event that all addresses do not fit line width, it's preferable to
416detach secondary addresses on other lines with the 'bind' keyword. If this
417keyword is used, it's not even necessary to specify the first address on the
418'listen' line, which sometimes makes multiple configuration handling easier :
419
420 bind [ <IP_address>:<port_range>[,...] ]
421
422Examples :
423----------
424 listen http_proxy
425 bind :80,:443
willy tarreauc5f73ed2005-12-18 01:26:38 +0100426 bind 10.0.0.1:10080,10.0.0.1:10443
427
willy tarreaueedaa9f2005-12-17 14:08:03 +0100428
4292.1) Inhibiting a service
430-------------------------
431A service may be disabled for maintenance reasons, without needing to comment
432out the whole section, simply by specifying the 'disabled' keyword in the
433section to be disabled :
434
435 listen smtp_proxy 0.0.0.0:25
willy tarreauc5f73ed2005-12-18 01:26:38 +0100436 disabled
willy tarreaueedaa9f2005-12-17 14:08:03 +0100437
438Note: the 'enabled' keyword allows to enable a service which has been disabled
439 previously by a default configuration.
440
willy tarreauc5f73ed2005-12-18 01:26:38 +0100441
willy tarreaueedaa9f2005-12-17 14:08:03 +01004422.2) Modes of operation
443-----------------------
444A service can work in 3 different distinct modes :
445 - TCP
446 - HTTP
willy tarreau532bb552006-05-13 18:40:37 +0200447 - health
willy tarreaueedaa9f2005-12-17 14:08:03 +0100448
449TCP mode
450--------
451In this mode, the service relays TCP connections as soon as they're established,
452towards one or several servers. No processing is done on the stream. It's only
453an association of source(addr:port) -> destination(addr:port). To use this mode,
454you must specify 'mode tcp' in the 'listen' section. This is the default mode.
455
456Example :
457---------
458 listen smtp_proxy 0.0.0.0:25
willy tarreauc5f73ed2005-12-18 01:26:38 +0100459 mode tcp
willy tarreaueedaa9f2005-12-17 14:08:03 +0100460
461HTTP mode
462---------
463In this mode, the service relays TCP connections towards one or several servers,
464when it has enough informations to decide, which normally means that all HTTP
465headers have been read. Some of them may be scanned for a cookie or a pattern
466matching a regex. To use this mode, specify 'mode http' in the 'listen' section.
467
468Example :
469---------
470 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100471 mode http
willy tarreaueedaa9f2005-12-17 14:08:03 +0100472
473Health-checking mode
474--------------------
475This mode provides a way for external components to check the proxy's health.
476It is meant to be used with intelligent load-balancers which can use send/expect
477scripts to check for all of their servers' availability. This one simply accepts
willy tarreau197e8ec2005-12-17 14:10:59 +0100478the connection, returns the word 'OK' and closes it. If the 'option httpchk' is
479set, then the reply will be 'HTTP/1.0 200 OK' with no data, so that it can be
480tested from a tool which supports HTTP health-checks. To enable it, simply
willy tarreaueedaa9f2005-12-17 14:08:03 +0100481specify 'health' as the working mode :
482
483Example :
484---------
willy tarreau197e8ec2005-12-17 14:10:59 +0100485 # simple response : 'OK'
willy tarreaueedaa9f2005-12-17 14:08:03 +0100486 listen health_check 0.0.0.0:60000
willy tarreauc5f73ed2005-12-18 01:26:38 +0100487 mode health
willy tarreaueedaa9f2005-12-17 14:08:03 +0100488
willy tarreau197e8ec2005-12-17 14:10:59 +0100489 # HTTP response : 'HTTP/1.0 200 OK'
490 listen http_health_check 0.0.0.0:60001
willy tarreauc5f73ed2005-12-18 01:26:38 +0100491 mode health
492 option httpchk
493
willy tarreau532bb552006-05-13 18:40:37 +02004942.2.1 Monitoring
495----------------
willy tarreauc5f73ed2005-12-18 01:26:38 +0100496Versions 1.1.32 and 1.2.6 provide a new solution to check the proxy's
497availability without perturbating the service. The 'monitor-net' keyword was
498created to specify a network of equipments which CANNOT use the service for
499anything but health-checks. This is particularly suited to TCP proxies, because
500it prevents the proxy from relaying the monitor's connection to the remote
501server.
502
503When used with TCP, the connection is accepted then closed and nothing is
504logged. This is enough for a front-end load-balancer to detect the service as
505available.
willy tarreau197e8ec2005-12-17 14:10:59 +0100506
willy tarreauc5f73ed2005-12-18 01:26:38 +0100507When used with HTTP, the connection is accepted, nothing is logged, the
508following response is sent, then the session is closed : "HTTP/1.0 200 OK".
509This is normally enough for any front-end HTTP load-balancer to detect the
510service as available too, both with TCP and HTTP checks.
511
512Proxies using the "monitor-net" keyword can remove the "option dontlognull", as
513it will make them log empty connections from hosts outside the monitoring
514network.
515
516Example :
517---------
518
519 listen tse-proxy
520 bind :3389,:1494,:5900 # TSE, ICA and VNC at once.
521 mode tcp
522 balance roundrobin
523 server tse-farm 192.168.1.10
524 monitor-net 192.168.1.252/31 # L4 load-balancers on .252 and .253
525
willy tarreaueedaa9f2005-12-17 14:08:03 +0100526
Willy Tarreau1c47f852006-07-09 08:22:27 +0200527When the system executing the checks is located behind a proxy, the monitor-net
528keyword cannot be used because haproxy will always see the proxy's address. To
529overcome this limitation, version 1.2.15 brought the 'monitor-uri' keyword. It
530defines an URI which will not be forwarded nor logged, but for which haproxy
531will immediately send an "HTTP/1.0 200 OK" response. This makes it possible to
532check the validity of the reverse-proxy->haproxy chain with one request. It can
533be used in HTTPS checks in front of an stunnel -> haproxy combination for
534instance. Obviously, this keyword is only valid in HTTP mode, otherwise there
535is no notion of URI. Note that the method and HTTP versions are simply ignored.
536
537Example :
538---------
539
540 listen stunnel_backend :8080
541 mode http
542 balance roundrobin
543 server web1 192.168.1.10:80 check
544 server web2 192.168.1.11:80 check
545 monitor-uri /haproxy_test
546
547
willy tarreaueedaa9f2005-12-17 14:08:03 +01005482.3) Limiting the number of simultaneous connections
549----------------------------------------------------
550The 'maxconn' parameter allows a proxy to refuse connections above a certain
551amount of simultaneous ones. When the limit is reached, it simply stops
552listening, but the system may still be accepting them because of the back log
willy tarreau982249e2005-12-18 00:57:06 +0100553queue. These connections will be processed later when other ones have freed
willy tarreaueedaa9f2005-12-17 14:08:03 +0100554some slots. This provides a serialization effect which helps very fragile
willy tarreau34f45302006-04-15 21:37:14 +0200555servers resist to high loads. See further for system limitations.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100556
557Example :
558---------
559 listen tiny_server 0.0.0.0:80
560 maxconn 10
561
562
5632.4) Soft stop
564--------------
565It is possible to stop services without breaking existing connections by the
willy tarreau22739ef2006-01-20 20:43:32 +0100566sending of the SIGUSR1 signal to the process. All services are then put into
willy tarreaueedaa9f2005-12-17 14:08:03 +0100567soft-stop state, which means that they will refuse to accept new connections,
568except for those which have a non-zero value in the 'grace' parameter, in which
569case they will still accept connections for the specified amount of time, in
willy tarreau22739ef2006-01-20 20:43:32 +0100570milliseconds. This makes it possible to tell a load-balancer that the service
571is failing, while still doing the job during the time it needs to detect it.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100572
573Note: active connections are never killed. In the worst case, the user will have
574to wait for all of them to close or to time-out, or simply kill the process
willy tarreau22739ef2006-01-20 20:43:32 +0100575normally (SIGTERM). The default 'grace' value is '0'.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100576
577Example :
578---------
579 # enter soft stop after 'killall -USR1 haproxy'
580 # the service will still run 10 seconds after the signal
581 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100582 mode http
583 grace 10000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100584
585 # this port is dedicated to a load-balancer, and must fail immediately
586 listen health_check 0.0.0.0:60000
willy tarreauc5f73ed2005-12-18 01:26:38 +0100587 mode health
588 grace 0
willy tarreaueedaa9f2005-12-17 14:08:03 +0100589
590
willy tarreau39df2dc2006-01-29 21:56:05 +0100591As of version 1.2.8, a new soft-reconfiguration mechanism has been introduced.
willy tarreau22739ef2006-01-20 20:43:32 +0100592It is now possible to "pause" all the proxies by sending a SIGTTOU signal to
593the processes. This will disable the listening socket without breaking existing
594connections. After that, sending a SIGTTIN signal to those processes enables
595the listening sockets again. This is very useful to try to load a new
596configuration or even a new version of haproxy without breaking existing
597connections. If the load succeeds, then simply send a SIGUSR1 which will make
598the previous proxies exit immediately once their sessions are closed ; and if
599the load fails, then simply send a SIGTTIN to restore the service immediately.
600Please note that the 'grace' parameter is ignored for SIGTTOU, as well as for
601SIGUSR1 when the process was in the pause mode. Please also note that it would
602be useful to save the pidfile before starting a new instance.
603
willy tarreau34f45302006-04-15 21:37:14 +0200604This mechanism fully exploited since 1.2.11 with the '-st' and '-sf' options
willy tarreau532bb552006-05-13 18:40:37 +0200605(see below).
606
6072.4.1) Hot reconfiguration
608--------------------------
609The '-st' and '-sf' command line options are used to inform previously running
610processes that a configuration is being reloaded. They will receive the SIGTTOU
611signal to ask them to temporarily stop listening to the ports so that the new
612process can grab them. If anything wrong happens, the new process will send
613them a SIGTTIN to tell them to re-listen to the ports and continue their normal
614work. Otherwise, it will either ask them to finish (-sf) their work then softly
615exit, or immediately terminate (-st), breaking existing sessions. A typical use
616of this allows a configuration reload without service interruption :
617
618 # haproxy -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)
619
willy tarreau22739ef2006-01-20 20:43:32 +0100620
willy tarreaueedaa9f2005-12-17 14:08:03 +01006212.5) Connections expiration time
622--------------------------------
623It is possible (and recommended) to configure several time-outs on TCP
624connections. Three independant timers are adjustable with values specified
625in milliseconds. A session will be terminated if either one of these timers
626expire.
627
628 - the time we accept to wait for data from the client, or for the client to
629 accept data : 'clitimeout' :
630
willy tarreauc5f73ed2005-12-18 01:26:38 +0100631 # client time-out set to 2mn30.
632 clitimeout 150000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100633
634 - the time we accept to wait for data from the server, or for the server to
635 accept data : 'srvtimeout' :
636
willy tarreauc5f73ed2005-12-18 01:26:38 +0100637 # server time-out set to 30s.
638 srvtimeout 30000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100639
640 - the time we accept to wait for a connection to establish on a server :
641 'contimeout' :
642
643 # we give up if the connection does not complete within 4 seconds
willy tarreauc5f73ed2005-12-18 01:26:38 +0100644 contimeout 4000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100645
646Notes :
647-------
648 - 'contimeout' and 'srvtimeout' have no sense on 'health' mode servers ;
649 - under high loads, or with a saturated or defective network, it's possible
650 that some packets get lost. Since the first TCP retransmit only happens
651 after 3 seconds, a time-out equal to, or lower than 3 seconds cannot
652 compensate for a packet loss. A 4 seconds time-out seems a reasonable
653 minimum which will considerably reduce connection failures.
654
willy tarreauc5f73ed2005-12-18 01:26:38 +0100655
willy tarreaueedaa9f2005-12-17 14:08:03 +01006562.6) Attempts to reconnect
657--------------------------
658After a connection failure to a server, it is possible to retry, potentially
659on another server. This is useful if health-checks are too rare and you don't
660want the clients to see the failures. The number of attempts to reconnect is
661set by the 'retries' paramter.
662
663Example :
664---------
willy tarreauc5f73ed2005-12-18 01:26:38 +0100665 # we can retry 3 times max after a failure
666 retries 3
willy tarreaueedaa9f2005-12-17 14:08:03 +0100667
willy tarreau34f45302006-04-15 21:37:14 +0200668Please note that the reconnection attempt may lead to getting the connection
669sent to a new server if the original one died between connection attempts.
670
willy tarreaueedaa9f2005-12-17 14:08:03 +0100671
6722.7) Address of the dispatch server (deprecated)
673------------------------------------------------
674The server which will be sent all new connections is defined by the 'dispatch'
675parameter, in the form <address>:<port>. It generally is dedicated to unknown
676connections and will assign them a cookie, in case of HTTP persistence mode,
677or simply is a single server in case of generic TCP proxy. This old mode is only
678provided for backwards compatibility, but doesn't allow to check remote servers
679state, and has a rather limited usage. All new setups should switch to 'balance'
680mode. The principle of the dispatcher is to be able to perform the load
681balancing itself, but work only on new clients so that the server doesn't need
682to be a big machine.
683
684Example :
685---------
willy tarreauc5f73ed2005-12-18 01:26:38 +0100686 # all new connections go there
687 dispatch 192.168.1.2:80
willy tarreaueedaa9f2005-12-17 14:08:03 +0100688
689Note :
690------
691This parameter has no sense for 'health' servers, and is incompatible with
692'balance' mode.
693
694
6952.8) Outgoing source address
696----------------------------
697It is often necessary to bind to a particular address when connecting to some
698remote hosts. This is done via the 'source' parameter which is a per-proxy
699parameter. A newer version may allow to fix different sources to reach different
700servers. The syntax is 'source <address>[:<port>]', where <address> is a valid
701local address (or '0.0.0.0' or '*' or empty to let the system choose), and
702<port> is an optional parameter allowing the user to force the source port for
703very specific needs. If the port is not specified or is '0', the system will
704choose a free port. Note that as of version 1.1.18, the servers health checks
705are also performed from the same source.
706
707Examples :
708----------
709 listen http_proxy *:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100710 # all connections take 192.168.1.200 as source address
711 source 192.168.1.200:0
willy tarreaueedaa9f2005-12-17 14:08:03 +0100712
713 listen rlogin_proxy *:513
willy tarreauc5f73ed2005-12-18 01:26:38 +0100714 # use address 192.168.1.200 and the reserved port 900 (needs to be root)
715 source 192.168.1.200:900
willy tarreaueedaa9f2005-12-17 14:08:03 +0100716
717
7182.9) Setting the cookie name
719----------------------------
720In HTTP mode, it is possible to look for a particular cookie which will contain
721a server identifier which should handle the connection. The cookie name is set
722via the 'cookie' parameter.
723
724Example :
725---------
726 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100727 mode http
728 cookie SERVERID
willy tarreaueedaa9f2005-12-17 14:08:03 +0100729
730It is possible to change the cookie behaviour to get a smarter persistence,
731depending on applications. It is notably possible to delete or modify a cookie
732emitted by a server, insert a cookie identifying the server in an HTTP response
733and even add a header to tell upstream caches not to cache this response.
734
735Examples :
736----------
737
738To remove the cookie for direct accesses (ie when the server matches the one
739which was specified in the client cookie) :
740
willy tarreauc5f73ed2005-12-18 01:26:38 +0100741 cookie SERVERID indirect
willy tarreaueedaa9f2005-12-17 14:08:03 +0100742
743To replace the cookie value with the one assigned to the server if any (no
744cookie will be created if the server does not provide one, nor if the
745configuration does not provide one). This lets the application put the cookie
746exactly on certain pages (eg: successful authentication) :
747
willy tarreauc5f73ed2005-12-18 01:26:38 +0100748 cookie SERVERID rewrite
willy tarreaueedaa9f2005-12-17 14:08:03 +0100749
750To create a new cookie and assign the server identifier to it (in this case, all
751servers should be associated with a valid cookie, since no cookie will simply
752delete the cookie from the client's browser) :
753
willy tarreauc5f73ed2005-12-18 01:26:38 +0100754 cookie SERVERID insert
willy tarreaueedaa9f2005-12-17 14:08:03 +0100755
willy tarreau0174f312005-12-18 01:02:42 +0100756To reuse an existing application cookie and prefix it with the server's
757identifier, and remove it in the request, use the 'prefix' option. This allows
758to insert a haproxy in front of an application without risking to break clients
759which does not support more than one cookie :
760
willy tarreauc5f73ed2005-12-18 01:26:38 +0100761 cookie JSESSIONID prefix
willy tarreau0174f312005-12-18 01:02:42 +0100762
willy tarreaueedaa9f2005-12-17 14:08:03 +0100763To insert a cookie and ensure that no upstream cache will store it, add the
764'nocache' option :
765
willy tarreauc5f73ed2005-12-18 01:26:38 +0100766 cookie SERVERID insert nocache
willy tarreaueedaa9f2005-12-17 14:08:03 +0100767
768To insert a cookie only after a POST request, add 'postonly' after 'insert'.
769This has the advantage that there's no risk of caching, and that all pages
770seen before the POST one can still be cached :
771
willy tarreauc5f73ed2005-12-18 01:26:38 +0100772 cookie SERVERID insert postonly
willy tarreaueedaa9f2005-12-17 14:08:03 +0100773
774Notes :
775-----------
776- it is possible to combine 'insert' with 'indirect' or 'rewrite' to adapt to
777 applications which already generate the cookie with an invalid content.
778
779- in the case where 'insert' and 'indirect' are both specified, the cookie is
willy tarreau0174f312005-12-18 01:02:42 +0100780 never transmitted to the server, since it wouldn't understand it. This is the
781 most application-transparent mode.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100782
783- it is particularly recommended to use 'nocache' in 'insert' mode if any
784 upstream HTTP/1.0 cache is susceptible to cache the result, because this may
785 lead to many clients going to the same server, or even worse, some clients
786 having their server changed while retrieving a page from the cache.
787
willy tarreau0174f312005-12-18 01:02:42 +0100788- the 'prefix' mode normally does not need 'indirect', 'nocache', nor
789 'postonly', because just as in the 'rewrite' mode, it relies on the
790 application to know when a cookie can be emitted. However, since it has to
791 fix the cookie name in every subsequent requests, you must ensure that the
792 proxy will be used without any "HTTP keep-alive". Use option "httpclose" if
793 unsure.
794
willy tarreaueedaa9f2005-12-17 14:08:03 +0100795- when the application is well known and controlled, the best method is to
796 only add the persistence cookie on a POST form because it's up to the
willy tarreau0174f312005-12-18 01:02:42 +0100797 application to select which page it wants the upstream servers to cache. In
798 this case, you would use 'insert postonly indirect'.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100799
willy tarreauc5f73ed2005-12-18 01:26:38 +0100800
willy tarreaueedaa9f2005-12-17 14:08:03 +01008012.10) Associating a cookie value with a server
802----------------------------------------------
803In HTTP mode, it's possible to associate a cookie value to each server. This
804was initially used in combination with 'dispatch' mode to handle direct accesses
805but it is now the standard way of doing the load balancing. The syntax is :
806
807 server <identifier> <address>:<port> cookie <value>
808
809- <identifier> is any name which can be used to identify the server in the logs.
810- <address>:<port> specifies where the server is bound.
811- <value> is the value to put in or to read from the cookie.
812
813Example : the 'SERVERID' cookie can be either 'server01' or 'server02'
814---------
815 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100816 mode http
817 cookie SERVERID
818 dispatch 192.168.1.100:80
819 server web1 192.168.1.1:80 cookie server01
820 server web2 192.168.1.2:80 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100821
822Warning : the syntax has changed since version 1.0 !
823---------
824
willy tarreauc5f73ed2005-12-18 01:26:38 +0100825
willy tarreau598da412005-12-18 01:07:29 +01008262.11) Application Cookies
827-------------------------
828Since 1.2.4 it is possible to catch the cookie that comes from an
829application server in order to apply "application session stickyness".
830The server's response is searched for 'appsession' cookie, the first
831'len' bytes are used for matching and it is stored for a period of
832'timeout'.
833The syntax is:
834
willy tarreau532bb552006-05-13 18:40:37 +0200835 appsession <session_cookie> len <match_length> timeout <holdtime>
willy tarreau598da412005-12-18 01:07:29 +0100836
willy tarreau532bb552006-05-13 18:40:37 +0200837- <session_cookie> is the cookie, the server uses for it's session-handling
838- <match_length> how many bytes/characters should be used for matching equal
willy tarreau598da412005-12-18 01:07:29 +0100839 sessions
willy tarreau532bb552006-05-13 18:40:37 +0200840- <holdtime> after this inactivaty time, in ms, the cookie will be deleted
willy tarreau598da412005-12-18 01:07:29 +0100841 from the sessionstore
842
843The appsession is only per 'listen' section possible.
844
845Example :
846---------
willy tarreau532bb552006-05-13 18:40:37 +0200847 listen http_lb1 192.168.3.4:80
848 mode http
849 capture request header Cookie len 200
850 # Havind a ServerID cookie on the client allows him to reach
851 # the right server even after expiration of the appsession.
852 cookie ServerID insert nocache indirect
853 # Will memorize 52 bytes of the cookie 'JSESSIONID' and keep them
854 # for 3 hours. It will match it in the cookie and the URL field.
855 appsession JSESSIONID len 52 timeout 10800000
856 server first1 10.3.9.2:10805 check inter 3000 cookie first
857 server secon1 10.3.9.3:10805 check inter 3000 cookie secon
858 server first1 10.3.9.4:10805 check inter 3000 cookie first
859 server secon2 10.3.9.5:10805 check inter 3000 cookie secon
860 option httpchk GET /test.jsp
willy tarreau598da412005-12-18 01:07:29 +0100861
willy tarreauc5f73ed2005-12-18 01:26:38 +0100862
willy tarreaueedaa9f2005-12-17 14:08:03 +01008633) Autonomous load balancer
864===========================
865
866The proxy can perform the load-balancing itself, both in TCP and in HTTP modes.
867This is the most interesting mode which obsoletes the old 'dispatch' mode
868described above. It has advantages such as server health monitoring, multiple
869port binding and port mapping. To use this mode, the 'balance' keyword is used,
willy tarreau34f45302006-04-15 21:37:14 +0200870followed by the selected algorithm. Up to version 1.2.11, only 'roundrobin' was
871available, which is also the default value if unspecified. Starting with
Willy Tarreau2fcb5002007-05-08 13:35:26 +0200872version 1.2.12, a new 'source' keyword appeared. A new 'uri' keyword was added
873in version 1.3.10. In this mode, there will be no dispatch address, but the
874proxy needs at least one server.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100875
876Example : same as the last one, with internal load balancer
877---------
878
879 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100880 mode http
881 cookie SERVERID
882 balance roundrobin
883 server web1 192.168.1.1:80 cookie server01
884 server web2 192.168.1.2:80 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100885
886
887Since version 1.1.22, it is possible to automatically determine on which port
888the server will get the connection, depending on the port the client connected
889to. Indeed, there now are 4 possible combinations for the server's <port> field:
890
891 - unspecified or '0' :
892 the connection will be sent to the same port as the one on which the proxy
893 received the client connection itself.
894
895 - numerical value (the only one supported in versions earlier than 1.1.22) :
896 the connection will always be sent to the specified port.
897
898 - '+' followed by a numerical value :
899 the connection will be sent to the same port as the one on which the proxy
900 received the connection, plus this value.
901
902 - '-' followed by a numerical value :
903 the connection will be sent to the same port as the one on which the proxy
904 received the connection, minus this value.
905
906Examples :
907----------
908
909# same as previous example
910
911 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100912 mode http
913 cookie SERVERID
914 balance roundrobin
915 server web1 192.168.1.1 cookie server01
916 server web2 192.168.1.2 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100917
918# simultaneous relaying of ports 80, 81 and 8080-8089
919
920 listen http_proxy :80,:81,:8080-8089
willy tarreauc5f73ed2005-12-18 01:26:38 +0100921 mode http
922 cookie SERVERID
923 balance roundrobin
924 server web1 192.168.1.1 cookie server01
925 server web2 192.168.1.2 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100926
927# relaying of TCP ports 25, 389 and 663 to ports 1025, 1389 and 1663
928
929 listen http_proxy :25,:389,:663
willy tarreauc5f73ed2005-12-18 01:26:38 +0100930 mode tcp
931 balance roundrobin
932 server srv1 192.168.1.1:+1000
933 server srv2 192.168.1.2:+1000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100934
willy tarreau34f45302006-04-15 21:37:14 +0200935As previously stated, version 1.2.12 brought the 'source' keyword. When this
936keyword is used, the client's IP address is hashed and evenly distributed among
937the available servers so that a same source IP will always go to the same
938server as long as there are no change in the number of available servers. This
939can be used for instance to bind HTTP and HTTPS to the same server. It can also
940be used to improve stickyness when one part of the client population does not
941accept cookies. In this case, only those ones will be perturbated should a
942server fail.
943
944NOTE: It is important to consider the fact that many clients surf the net
945 through proxy farms which assign different IP addresses for each
946 request. Others use dialup connections with a different IP at each
947 connection. Thus, the 'source' parameter should be used with extreme
948 care.
949
950Examples :
951----------
952
953# make a same IP go to the same server whatever the service
954
955 listen http_proxy
956 bind :80,:443
957 mode http
958 balance source
959 server web1 192.168.1.1
960 server web2 192.168.1.2
961
962# try to improve client-server binding by using both source IP and cookie :
963
964 listen http_proxy :80
965 mode http
966 cookie SERVERID
967 balance source
968 server web1 192.168.1.1 cookie server01
969 server web2 192.168.1.2 cookie server02
970
Willy Tarreau2fcb5002007-05-08 13:35:26 +0200971As indicated above, the 'uri' keyword was introduced in version 1.3.10. It is
972useful when load-balancing between reverse proxy-caches, because it will hash
973the URI and use the hash result to select a server, thus optimizing the hit
974rate on the caches, because the same URI will always reach the same cache. This
975keyword is only allowed in HTTP mode.
976
977Example :
978---------
979
980# Always send a given URI to the same server
981
982 listen http_proxy
983 bind :3128
984 mode http
985 balance uri
986 server squid1 192.168.1.1
987 server squid2 192.168.1.2
988
willy tarreaueedaa9f2005-12-17 14:08:03 +0100989
willy tarreau197e8ec2005-12-17 14:10:59 +01009903.1) Server monitoring
991----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +0100992It is possible to check the servers status by trying to establish TCP
993connections or even sending HTTP requests to them. A server which fails to
994reply to health checks as expected will not be used by the load balancing
995algorithms. To enable monitoring, add the 'check' keyword on a server line.
996It is possible to specify the interval between tests (in milliseconds) with
997the 'inter' parameter, the number of failures supported before declaring that
998the server has fallen down with the 'fall' parameter, and the number of valid
999checks needed for the server to fully get up with the 'rise' parameter. Since
1000version 1.1.22, it is also possible to send checks to a different port
1001(mandatory when none is specified) with the 'port' parameter. The default
1002values are the following ones :
1003
1004 - inter : 2000
1005 - rise : 2
1006 - fall : 3
1007 - port : default server port
Willy Tarreau2ea3abb2007-03-25 16:45:16 +02001008 - addr : specific address for the test (default = address server)
1009
willy tarreaueedaa9f2005-12-17 14:08:03 +01001010The default mode consists in establishing TCP connections only. But in certain
1011types of application failures, it is often that the server continues to accept
1012connections because the system does it itself while the application is running
1013an endless loop, or is completely stuck. So in version 1.1.16 were introduced
1014HTTP health checks which only performed simple lightweight requests and analysed
1015the response. Now, as of version 1.1.23, it is possible to change the HTTP
1016method, the URI, and the HTTP version string (which even allows to send headers
1017with a dirty trick). To enable HTTP health-checks, use 'option httpchk'.
1018
1019By default, requests use the 'OPTIONS' method because it's very light and easy
1020to filter from logs, and does it on '/'. Only HTTP responses 2xx and 3xx are
1021considered valid ones, and only if they come before the time to send a new
1022request is reached ('inter' parameter). If some servers block this type of
1023request, 3 other forms help to forge a request :
1024
1025 - option httpchk -> OPTIONS / HTTP/1.0
1026 - option httpchk URI -> OPTIONS <URI> HTTP/1.0
1027 - option httpchk METH URI -> <METH> <URI> HTTP/1.0
1028 - option httpchk METH URI VER -> <METH> <URI> <VER>
1029
Willy Tarreauf3c69202006-07-09 16:42:34 +02001030Some people are using HAProxy to relay various TCP-based protocols such as
1031HTTPS, SMTP or LDAP, with the most common one being HTTPS. One problem commonly
1032encountered in data centers is the need to forward the traffic to far remote
1033servers while providing server fail-over. Often, TCP-only checks are not enough
1034because intermediate firewalls, load balancers or proxies might acknowledge the
1035connection before it reaches the real server. The only solution to this problem
1036is to send application-level health checks. Since the demand for HTTPS checks
1037is high, it has been implemented in 1.2.15 based on SSLv3 Client Hello packets.
1038To enable it, use 'option ssl-hello-chk'. It will send SSL CLIENT HELLO packets
1039to the servers, announcing support for most common cipher suites. If the server
1040responds what looks like a SERVER HELLO or an ALERT (refuses the ciphers) then
1041the response is considered as valid. Note that Apache does not generate a log
1042when it receives only an HELLO message, which makes this type of message
1043perfectly suit this need.
1044
Willy Tarreau23677902007-05-08 23:50:35 +02001045Version 1.3.10 introduced the SMTP health check. By default, it sends
1046"HELO localhost" to the servers, and waits for the 250 message. Note that it
1047can also send a specific request :
1048
1049 - option smtpchk -> sends "HELO localhost"
1050 - option smtpchk EHLO mail.mydomain.com -> sends this ESMTP greeting
1051
willy tarreaueedaa9f2005-12-17 14:08:03 +01001052See examples below.
1053
1054Since version 1.1.17, it is possible to specify backup servers. These servers
1055are only sollicited when no other server is available. This may only be useful
1056to serve a maintenance page, or define one active and one backup server (seldom
1057used in TCP mode). To make a server a backup one, simply add the 'backup' option
1058on its line. These servers also support cookies, so if a cookie is specified for
1059a backup server, clients assigned to this server will stick to it even when the
1060other ones come back. Conversely, if no cookie is assigned to such a server,
1061the clients will get their cookies removed (empty cookie = removal), and will
1062be balanced against other servers once they come back. Please note that there
Willy TARREAU3481c462006-03-01 22:37:57 +01001063is no load-balancing among backup servers by default. If there are several
1064backup servers, the second one will only be used when the first one dies, and
1065so on. To force load-balancing between backup servers, specify the 'allbackups'
1066option.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001067
Willy Tarreau2ea3abb2007-03-25 16:45:16 +02001068Since version 1.1.22, it is possible to send health checks to a different port
1069than the service. It is mainly needed in setups where the server does not have
1070any predefined port, for instance when the port is deduced from the listening
1071port. For this, use the 'port' parameter followed by the port number which must
1072respond to health checks. It is also possible to send health checks to a
1073different address than the service. It makes it easier to use a dedicated check
1074daemon on the servers, for instance, check return contents and stop several
1075farms at once in the event of an error anywhere.
1076
willy tarreaueedaa9f2005-12-17 14:08:03 +01001077Since version 1.1.17, it is also possible to visually check the status of all
1078servers at once. For this, you just have to send a SIGHUP signal to the proxy.
1079The servers status will be dumped into the logs at the 'notice' level, as well
1080as on <stderr> if not closed. For this reason, it's always a good idea to have
1081one local log server at the 'notice' level.
1082
willy tarreau982249e2005-12-18 00:57:06 +01001083Since version 1.1.28 and 1.2.1, if an instance loses all its servers, an
willy tarreau0174f312005-12-18 01:02:42 +01001084emergency message will be sent in the logs to inform the administator that an
willy tarreau982249e2005-12-18 00:57:06 +01001085immediate action must be taken.
1086
willy tarreau0174f312005-12-18 01:02:42 +01001087Since version 1.1.30 and 1.2.3, several servers can share the same cookie
1088value. This is particularly useful in backup mode, to select alternate paths
1089for a given server for example, to provide soft-stop, or to direct the clients
1090to a temporary page during an application restart. The principle is that when
1091a server is dead, the proxy will first look for another server which shares the
1092same cookie value for every client which presents the cookie. If there is no
1093standard server for this cookie, it will then look for a backup server which
1094shares the same name. Please consult the architecture guide for more information.
willy tarreau982249e2005-12-18 00:57:06 +01001095
willy tarreaueedaa9f2005-12-17 14:08:03 +01001096Examples :
1097----------
1098# same setup as in paragraph 3) with TCP monitoring
1099 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001100 mode http
1101 cookie SERVERID
1102 balance roundrobin
1103 server web1 192.168.1.1:80 cookie server01 check
1104 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +01001105
1106# same with HTTP monitoring via 'OPTIONS / HTTP/1.0'
1107 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001108 mode http
1109 cookie SERVERID
1110 balance roundrobin
1111 option httpchk
1112 server web1 192.168.1.1:80 cookie server01 check
1113 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +01001114
1115# same with HTTP monitoring via 'OPTIONS /index.html HTTP/1.0'
1116 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001117 mode http
1118 cookie SERVERID
1119 balance roundrobin
1120 option httpchk /index.html
1121 server web1 192.168.1.1:80 cookie server01 check
1122 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +01001123
1124# same with HTTP monitoring via 'HEAD /index.jsp? HTTP/1.1\r\nHost: www'
1125 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001126 mode http
1127 cookie SERVERID
1128 balance roundrobin
1129 option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www
1130 server web1 192.168.1.1:80 cookie server01 check
1131 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +01001132
willy tarreau0174f312005-12-18 01:02:42 +01001133# Load-balancing with 'prefixed cookie' persistence, and soft-stop using an
1134# alternate port 81 on the server for health-checks.
1135 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001136 mode http
1137 cookie JSESSIONID prefix
1138 balance roundrobin
1139 option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www
1140 server web1-norm 192.168.1.1:80 cookie s1 check port 81
1141 server web2-norm 192.168.1.2:80 cookie s2 check port 81
1142 server web1-stop 192.168.1.1:80 cookie s1 check port 80 backup
1143 server web2-stop 192.168.1.2:80 cookie s2 check port 80 backup
willy tarreau0174f312005-12-18 01:02:42 +01001144
willy tarreaueedaa9f2005-12-17 14:08:03 +01001145# automatic insertion of a cookie in the server's response, and automatic
1146# deletion of the cookie in the client request, while asking upstream caches
1147# not to cache replies.
1148 listen web_appl 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001149 mode http
1150 cookie SERVERID insert nocache indirect
1151 balance roundrobin
1152 server web1 192.168.1.1:80 cookie server01 check
1153 server web2 192.168.1.2:80 cookie server02 check
willy tarreaueedaa9f2005-12-17 14:08:03 +01001154
1155# same with off-site application backup and local error pages server
1156 listen web_appl 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001157 mode http
1158 cookie SERVERID insert nocache indirect
1159 balance roundrobin
1160 server web1 192.168.1.1:80 cookie server01 check
1161 server web2 192.168.1.2:80 cookie server02 check
1162 server web-backup 192.168.2.1:80 cookie server03 check backup
1163 server web-excuse 192.168.3.1:80 check backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01001164
willy tarreauc5f73ed2005-12-18 01:26:38 +01001165# SMTP+TLS relaying with health-checks and backup servers
willy tarreaueedaa9f2005-12-17 14:08:03 +01001166
1167 listen http_proxy :25,:587
willy tarreauc5f73ed2005-12-18 01:26:38 +01001168 mode tcp
1169 balance roundrobin
1170 server srv1 192.168.1.1 check port 25 inter 30000 rise 1 fall 2
1171 server srv2 192.168.1.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01001172
Willy Tarreauf3c69202006-07-09 16:42:34 +02001173# HTTPS relaying with health-checks and backup servers
1174
1175 listen http_proxy :443
1176 mode tcp
1177 option ssl-hello-chk
1178 balance roundrobin
1179 server srv1 192.168.1.1 check inter 30000 rise 1 fall 2
1180 server srv2 192.168.1.2 backup
1181
Willy TARREAU3481c462006-03-01 22:37:57 +01001182# Load-balancing using a backup pool (requires haproxy 1.2.9)
1183 listen http_proxy 0.0.0.0:80
1184 mode http
1185 balance roundrobin
1186 option httpchk
1187 server inst1 192.168.1.1:80 cookie s1 check
1188 server inst2 192.168.1.2:80 cookie s2 check
1189 server inst3 192.168.1.3:80 cookie s3 check
1190 server back1 192.168.1.10:80 check backup
1191 server back2 192.168.1.11:80 check backup
1192 option allbackups # all backups will be used
1193
willy tarreaueedaa9f2005-12-17 14:08:03 +01001194
11953.2) Redistribute connections in case of failure
1196------------------------------------------------
1197In HTTP mode, if a server designated by a cookie does not respond, the clients
1198may definitely stick to it because they cannot flush the cookie, so they will
1199not be able to access the service anymore. Specifying 'redispatch' will allow
1200the proxy to break their persistence and redistribute them to working servers.
1201
1202Example :
1203---------
1204 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001205 mode http
1206 cookie SERVERID
1207 dispatch 192.168.1.100:80
1208 server web1 192.168.1.1:80 cookie server01
1209 server web2 192.168.1.2:80 cookie server02
1210 redispatch # send back to dispatch in case of connection failure
willy tarreaueedaa9f2005-12-17 14:08:03 +01001211
1212Up to, and including version 1.1.16, this parameter only applied to connection
1213failures. Since version 1.1.17, it also applies to servers which have been
1214detected as failed by the health check mechanism. Indeed, a server may be broken
1215but still accepting connections, which would not solve every case. But it is
1216possible to conserve the old behaviour, that is, make a client insist on trying
1217to connect to a server even if it is said to be down, by setting the 'persist'
1218option :
1219
1220 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001221 mode http
1222 option persist
1223 cookie SERVERID
1224 dispatch 192.168.1.100:80
1225 server web1 192.168.1.1:80 cookie server01
1226 server web2 192.168.1.2:80 cookie server02
1227 redispatch # send back to dispatch in case of connection failure
willy tarreaueedaa9f2005-12-17 14:08:03 +01001228
1229
willy tarreau34f45302006-04-15 21:37:14 +020012303.3) Assigning different weights to servers
1231-------------------------------------------
1232Sometimes you will need to bring new servers to increase your server farm's
1233capacity, but the new server will be either smaller (emergency use of anything
1234that fits) or bigger (when investing in new hardware). For this reason, it
1235might be wise to be able to send more clients to biggest servers. Till version
12361.2.11, it was necessary to replicate the same server multiple times in the
1237configuration. Starting with 1.2.12, the 'weight' option is available. HAProxy
1238then computes the most homogenous possible map of servers based on their
willy tarreau532bb552006-05-13 18:40:37 +02001239weights so that the load gets distributed as smoothly as possible among them.
1240The weight, between 1 and 256, should reflect one server's capacity relative to
1241others. Weight 1 represents the lowest frequency and 256 the highest. This way,
1242if a server fails, the remaining capacities are still respected.
willy tarreau34f45302006-04-15 21:37:14 +02001243
1244Example :
1245---------
1246# fair distribution among two opterons and one old pentium3
1247
1248 listen web_appl 0.0.0.0:80
1249 mode http
1250 cookie SERVERID insert nocache indirect
1251 balance roundrobin
1252 server pentium3-800 192.168.1.1:80 cookie server01 weight 8 check
1253 server opteron-2.0G 192.168.1.2:80 cookie server02 weight 20 check
1254 server opteron-2.4G 192.168.1.3:80 cookie server03 weight 24 check
1255 server web-backup1 192.168.2.1:80 cookie server04 check backup
1256 server web-excuse 192.168.3.1:80 check backup
1257
1258Notes :
1259-------
1260 - if unspecified, the default weight is 1
1261
1262 - the weight does not impact health checks, so it is cleaner to use weights
1263 than replicating the same server several times
1264
1265 - weights also work on backup servers if the 'allbackups' option is used
1266
1267 - the weights also apply to the source address load balancing
1268 ('balance source').
1269
1270 - whatever the weights, the first server will always be assigned first. This
1271 is helpful for troubleshooting.
1272
1273 - for the purists, the map calculation algorithm gives precedence to first
1274 server, so the map is the most uniform when servers are declared in
1275 ascending order relative to their weights.
1276
willy tarreau532bb552006-05-13 18:40:37 +02001277The load distribution will follow exactly this sequence :
1278
1279 Request| 1 1 1 1
1280 number | 1 2 3 4 5 6 7 8 9 0 1 2 3
1281 --------+---------------------------
1282 p3-800 | X . . . . . . X . . . . .
1283 opt-20 | . X . X . X . . . X . X .
1284 opt-24 | . . X . X . X . X . X . X
1285
1286
12873.4) Limiting the number of concurrent sessions on each server
1288--------------------------------------------------------------
1289Some pre-forked servers such as Apache suffer from too many concurrent
1290sessions, because it's very expensive to run hundreds or thousands of
1291processes on one system. One solution is to increase the number of servers
1292and load-balance between them, but it is a problem when the only goal is
1293to resist to short surges.
1294
1295To solve this problem, a new feature was implemented in HAProxy 1.2.13.
1296It's a per-server 'maxconn', associated with a per-server and a per-proxy
1297queue. This transforms haproxy into a request buffer between the thousands of
1298clients and the few servers. On many circumstances, lowering the maxconn value
1299will increase the server's performance and decrease the overall response times
1300because the servers will be less congested.
1301
1302When a request tries to reach any server, the first non-saturated server is
1303used, respective to the load balancing algorithm. If all servers are saturated,
1304then the request gets queued into the instance's global queue. It will be
1305dequeued once a server will have freed a session and all previously queued
1306requests have been processed.
1307
1308If a request references a particular server (eg: source hashing, or persistence
1309cookie), and if this server is full, then the request will be queued into the
1310server's dedicated queue. This queue has higher priority than the global queue,
1311so it's easier for already registered users to enter the site than for new
1312users.
1313
1314For this, the logs have been enhanced to show the number of sessions per
1315server, the request's position in the queue and the time spent in the queue.
1316This helps doing capacity planning. See the 'logs' section below for more info.
1317
1318Example :
1319---------
1320 # be nice with P3 which only has 256 MB of RAM.
1321 listen web_appl 0.0.0.0:80
1322 maxconn 10000
1323 mode http
1324 cookie SERVERID insert nocache indirect
1325 balance roundrobin
1326 server pentium3-800 192.168.1.1:80 cookie s1 weight 8 maxconn 100 check
1327 server opteron-2.0G 192.168.1.2:80 cookie s2 weight 20 maxconn 300 check
1328 server opteron-2.4G 192.168.1.3:80 cookie s3 weight 24 maxconn 300 check
1329 server web-backup1 192.168.2.1:80 cookie s4 check maxconn 200 backup
1330 server web-excuse 192.168.3.1:80 check backup
1331
willy tarreauf76e6ca2006-05-21 21:09:55 +02001332
1333This was so much efficient at reducing the server's response time that some
1334users wanted to use low values to improve their server's performance. However,
1335they were not able anymore to handle very large loads because it was not
1336possible anymore to saturate the servers. For this reason, version 1.2.14 has
1337brought dynamic limitation with the addition of the parameter 'minconn'. When
1338this parameter is set along with maxconn, it will enable dynamic limitation
1339based on the instance's load. The maximum number of concurrent sessions on a
1340server will be proportionnal to the number of sessions on the instance relative
1341to its maxconn. A minimum of <minconn> will be allowed whatever the load. This
1342will ensure that servers will perform at their best level under normal loads,
1343while still handling surges when needed. The dynamic limit is computed like
1344this :
1345
1346 srv.dyn_limit = max(srv.minconn, srv.maxconn * inst.sess / inst.maxconn)
1347
1348Example :
1349---------
1350 # be nice with P3 which only has 256 MB of RAM.
1351 listen web_appl 0.0.0.0:80
1352 maxconn 10000
1353 mode http
1354 cookie SERVERID insert nocache indirect
1355 balance roundrobin
1356 server pentium3-800 192.168.1.1:80 cookie s1 weight 8 minconn 10 maxconn 100 check
1357 server opteron-2.0G 192.168.1.2:80 cookie s2 weight 20 minconn 30 maxconn 300 check
1358 server opteron-2.4G 192.168.1.3:80 cookie s3 weight 24 minconn 30 maxconn 300 check
1359 server web-backup1 192.168.2.1:80 cookie s4 check maxconn 200 backup
1360 server web-excuse 192.168.3.1:80 check backup
1361
1362In the example above, the server 'pentium3-800' will receive at most 100
1363simultaneous sessions when the proxy instance will reach 10000 sessions, and
1364will receive only 10 simultaneous sessions when the proxy will be under 1000
1365sessions.
1366
willy tarreau532bb552006-05-13 18:40:37 +02001367Notes :
1368-------
1369 - The requests will not stay indefinitely in the queue, they follow the
1370 'contimeout' parameter, and if a request cannot be dequeued within this
1371 timeout because the server is saturated or because the queue is filled,
1372 the session will expire with a 503 error.
1373
willy tarreauf76e6ca2006-05-21 21:09:55 +02001374 - if only <minconn> is specified, it has the same effect as <maxconn>
1375
willy tarreau532bb552006-05-13 18:40:37 +02001376 - setting too low values for maxconn might improve performance but might also
1377 allow slow users to block access to the server for other users.
1378
willy tarreau34f45302006-04-15 21:37:14 +02001379
willy tarreaue0bdd622006-05-21 20:51:54 +020013803.5) Dropping aborted requests
1381------------------------------
1382In presence of very high loads, the servers will take some time to respond. The
1383per-proxy's connection queue will inflate, and the response time will increase
1384respective to the size of the queue times the average per-session response
1385time. When clients will wait for more than a few seconds, they will often hit
1386the 'STOP' button on their browser, leaving a useless request in the queue, and
1387slowing down other users.
1388
1389As there is no way to distinguish between a full STOP and a simple
1390shutdown(SHUT_WR) on the client side, HTTP agents should be conservative and
1391consider that the client might only have closed its output channel while
1392waiting for the response. However, this introduces risks of congestion when
1393lots of users do the same, and is completely useless nowadays because probably
1394no client at all will close the session while waiting for the response. Some
1395HTTP agents support this (Squid, Apache, HAProxy), and others do not (TUX, most
1396hardware-based load balancers). So the probability for a closed input channel
1397to represent a user hitting the 'STOP' button is close to 100%, and it is very
1398tempting to be able to abort the session early without polluting the servers.
1399
1400For this reason, a new option "abortonclose" was introduced in version 1.2.14.
1401By default (without the option) the behaviour is HTTP-compliant. But when the
1402option is specified, a session with an incoming channel closed will be aborted
1403if it's still possible, which means that it's either waiting for a connect() to
1404establish or it is queued waiting for a connection slot. This considerably
1405reduces the queue size and the load on saturated servers when users are tempted
1406to click on STOP, which in turn reduces the response time for other users.
1407
1408Example :
1409---------
1410 listen web_appl 0.0.0.0:80
1411 maxconn 10000
1412 mode http
1413 cookie SERVERID insert nocache indirect
1414 balance roundrobin
1415 server web1 192.168.1.1:80 cookie s1 weight 10 maxconn 100 check
1416 server web2 192.168.1.2:80 cookie s2 weight 10 maxconn 100 check
1417 server web3 192.168.1.3:80 cookie s3 weight 10 maxconn 100 check
1418 server bck1 192.168.2.1:80 cookie s4 check maxconn 200 backup
1419 option abortonclose
1420
1421
willy tarreaueedaa9f2005-12-17 14:08:03 +010014224) Additionnal features
1423=======================
1424
willy tarreau481132e2006-05-21 21:43:10 +02001425Other features are available. They are transparent mode, event logging, header
1426rewriting/filtering, and the status as an HTML page.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001427
willy tarreauc5f73ed2005-12-18 01:26:38 +01001428
willy tarreau0174f312005-12-18 01:02:42 +010014294.1) Network features
willy tarreaueedaa9f2005-12-17 14:08:03 +01001430---------------------
willy tarreau0174f312005-12-18 01:02:42 +010014314.1.1) Transparent mode
1432-----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +01001433In HTTP mode, the 'transparent' keyword allows to intercept sessions which are
1434routed through the system hosting the proxy. This mode was implemented as a
1435replacement for the 'dispatch' mode, since connections without cookie will be
1436sent to the original address while known cookies will be sent to the servers.
1437This mode implies that the system can redirect sessions to a local port.
1438
1439Example :
1440---------
1441 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001442 mode http
1443 transparent
1444 cookie SERVERID
1445 server server01 192.168.1.1:80
1446 server server02 192.168.1.2:80
willy tarreaueedaa9f2005-12-17 14:08:03 +01001447
1448 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
1449 --dport 80 -j REDIRECT --to-ports 65000
1450
1451Note :
1452------
1453If the port is left unspecified on the server, the port the client connected to
1454will be used. This allows to relay a full port range without using transparent
1455mode nor thousands of file descriptors, provided that the system can redirect
1456sessions to local ports.
1457
1458Example :
1459---------
1460 # redirect all ports to local port 65000, then forward to the server on the
1461 # original port.
1462 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001463 mode tcp
1464 server server01 192.168.1.1 check port 60000
1465 server server02 192.168.1.2 check port 60000
willy tarreaueedaa9f2005-12-17 14:08:03 +01001466
1467 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
1468 -j REDIRECT --to-ports 65000
1469
willy tarreau0174f312005-12-18 01:02:42 +010014704.1.2) Per-server source address binding
1471----------------------------------------
1472As of versions 1.1.30 and 1.2.3, it is possible to specify a particular source
1473to reach each server. This is useful when reaching backup servers from a
1474different LAN, or to use an alternate path to reach the same server. It is also
1475usable to provide source load-balancing for outgoing connections. Obviously,
1476the same source address is used to send health-checks.
1477
1478Example :
1479---------
1480 # use a particular source to reach both servers
1481 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001482 mode http
1483 balance roundrobin
1484 server server01 192.168.1.1:80 source 192.168.2.13
1485 server server02 192.168.1.2:80 source 192.168.2.13
willy tarreau0174f312005-12-18 01:02:42 +01001486
1487Example :
1488---------
1489 # use a particular source to reach each servers
1490 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001491 mode http
1492 balance roundrobin
1493 server server01 192.168.1.1:80 source 192.168.1.1
1494 server server02 192.168.2.1:80 source 192.168.2.1
willy tarreau0174f312005-12-18 01:02:42 +01001495
1496Example :
1497---------
1498 # provide source load-balancing to reach the same proxy through 2 WAN links
1499 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001500 mode http
1501 balance roundrobin
1502 server remote-proxy-way1 192.168.1.1:3128 source 192.168.2.1
1503 server remote-proxy-way2 192.168.1.1:3128 source 192.168.3.1
willy tarreau0174f312005-12-18 01:02:42 +01001504
1505Example :
1506---------
1507 # force a TCP connection to bind to a specific port
1508 listen http_proxy 0.0.0.0:2000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001509 mode tcp
1510 balance roundrobin
1511 server srv1 192.168.1.1:80 source 192.168.2.1:20
1512 server srv2 192.168.1.2:80 source 192.168.2.1:20
willy tarreau0174f312005-12-18 01:02:42 +01001513
willy tarreaub952e1d2005-12-18 01:31:20 +010015144.1.3) TCP keep-alive
1515---------------------
1516With version 1.2.7, it becomes possible to enable TCP keep-alives on both the
1517client and server sides. This makes it possible to prevent long sessions from
1518expiring on external layer 4 components such as firewalls and load-balancers.
1519It also allows the system to terminate dead sessions when no timeout has been
1520set (not recommanded). The proxy cannot set the keep-alive probes intervals nor
1521maximal count, consult your operating system manual for this. There are 3
1522options to enable TCP keep-alive :
1523
1524 option tcpka # enables keep-alive both on client and server side
1525 option clitcpka # enables keep-alive only on client side
1526 option srvtcpka # enables keep-alive only on server side
1527
Alexandre Cassen87ea5482007-10-11 20:48:58 +020015284.1.4) TCP lingering
1529--------------------
1530It is possible to disable the system's lingering of data unacked by the client
1531at the end of a session. This is sometimes required when haproxy is used as a
1532front-end with lots of unreliable clients, and you observe thousands of sockets
1533in the FIN_WAIT state on the machine. This may be used in a frontend to affect
1534the client-side connection, as well as in a backend for the server-side
1535connection :
1536
1537 option nolinger # disables data lingering
1538
willy tarreaueedaa9f2005-12-17 14:08:03 +01001539
15404.2) Event logging
1541------------------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001542
1543HAProxy's strength certainly lies in its precise logs. It probably provides the
1544finest level of information available for such a product, which is very
1545important for troubleshooting complex environments. Standard log information
1546include client ports, TCP/HTTP state timers, precise session state at
1547termination and precise termination cause, information about decisions to
1548direct trafic to a server, and of course the ability to capture arbitrary
1549headers.
1550
1551In order to improve administrators reactivity, it offers a great transparency
1552about encountered problems, both internal and external, and it is possible to
1553send logs to different sources at the same time with different level filters :
1554
1555 - global process-level logs (system errors, start/stop, etc..)
1556 - per-listener system and internal errors (lack of resource, bugs, ...)
1557 - per-listener external troubles (servers up/down, max connections)
1558 - per-listener activity (client connections), either at the establishment or
1559 at the termination.
1560
1561The ability to distribute different levels of logs to different log servers
1562allow several production teams to interact and to fix their problems as soon
1563as possible. For example, the system team might monitor system-wide errors,
1564while the application team might be monitoring the up/down for their servers in
1565real time, and the security team might analyze the activity logs with one hour
1566delay.
1567
willy tarreauc1cae632005-12-17 14:12:23 +010015684.2.1) Log levels
1569-----------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001570TCP and HTTP connections can be logged with informations such as date, time,
1571source IP address, destination address, connection duration, response times,
1572HTTP request, the HTTP return code, number of bytes transmitted, the conditions
1573in which the session ended, and even exchanged cookies values, to track a
1574particular user's problems for example. All messages are sent to up to two
1575syslog servers. Consult section 1.1 for more info about log facilities. The
1576syntax follows :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001577
willy tarreau197e8ec2005-12-17 14:10:59 +01001578 log <address_1> <facility_1> [max_level_1]
1579 log <address_2> <facility_2> [max_level_2]
1580or
willy tarreaueedaa9f2005-12-17 14:08:03 +01001581 log global
1582
willy tarreau197e8ec2005-12-17 14:10:59 +01001583Note :
1584------
1585The particular syntax 'log global' means that the same log configuration as the
1586'global' section will be used.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001587
willy tarreau197e8ec2005-12-17 14:10:59 +01001588Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001589---------
1590 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001591 mode http
1592 log 192.168.2.200 local3
1593 log 192.168.2.201 local4
willy tarreaueedaa9f2005-12-17 14:08:03 +01001594
willy tarreauc1cae632005-12-17 14:12:23 +010015954.2.2) Log format
1596-----------------
1597By default, connections are logged at the TCP level, as soon as the session
1598establishes between the client and the proxy. By enabling the 'tcplog' option,
1599the proxy will wait until the session ends to generate an enhanced log
1600containing more information such as session duration and its state during the
willy tarreau532bb552006-05-13 18:40:37 +02001601disconnection. The number of remaining session after disconnection is also
1602indicated (for the server, the listener, and the process).
willy tarreauc1cae632005-12-17 14:12:23 +01001603
willy tarreauc5f73ed2005-12-18 01:26:38 +01001604Example of TCP logging :
1605------------------------
willy tarreau982249e2005-12-18 00:57:06 +01001606 listen relais-tcp 0.0.0.0:8000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001607 mode tcp
1608 option tcplog
1609 log 192.168.2.200 local3
willy tarreau982249e2005-12-18 00:57:06 +01001610
willy tarreau532bb552006-05-13 18:40:37 +02001611>>> haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28] relais-tcp Srv1 0/0/5007 0 -- 1/1/1 0/0
willy tarreauc5f73ed2005-12-18 01:26:38 +01001612
willy tarreau532bb552006-05-13 18:40:37 +02001613 Field Format Example
willy tarreauc5f73ed2005-12-18 01:26:38 +01001614
willy tarreau532bb552006-05-13 18:40:37 +02001615 1 process_name '[' pid ']:' haproxy[18989]:
1616 2 client_ip ':' client_port 127.0.0.1:34550
1617 3 '[' date ']' [15/Oct/2003:15:24:28]
1618 4 listener_name relais-tcp
1619 5 server_name Srv1
1620 6 queue_time '/' connect_time '/' total_time 0/0/5007
1621 7 bytes_read 0
1622 8 termination_state --
1623 9 srv_conn '/' listener_conn '/' process_conn 1/1/1
1624 10 position in srv_queue / listener_queue 0/0
1625
willy tarreau982249e2005-12-18 00:57:06 +01001626
willy tarreauc1cae632005-12-17 14:12:23 +01001627Another option, 'httplog', provides more detailed information about HTTP
1628contents, such as the request and some cookies. In the event where an external
1629component would establish frequent connections to check the service, logs may be
1630full of useless lines. So it is possible not to log any session which didn't
1631transfer any data, by the setting of the 'dontlognull' option. This only has
1632effect on sessions which are established then closed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001633
willy tarreauc5f73ed2005-12-18 01:26:38 +01001634Example of HTTP logging :
1635-------------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +01001636 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001637 mode http
1638 option httplog
1639 option dontlognull
1640 log 192.168.2.200 local3
1641
willy tarreau532bb552006-05-13 18:40:37 +02001642>>> haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57] relais-http Srv1 9/0/7/147/723 200 243 - - ---- 2/3/3 0/0 "HEAD / HTTP/1.0"
willy tarreaueedaa9f2005-12-17 14:08:03 +01001643
willy tarreauc5f73ed2005-12-18 01:26:38 +01001644More complete example
willy tarreau532bb552006-05-13 18:40:37 +02001645 haproxy[18989]: 10.0.0.1:34552 [15/Oct/2003:15:26:31] relais-http Srv1 3183/-1/-1/-1/11215 503 0 - - SC-- 137/202/205 0/0 {w.ods.org|Mozilla} {} "HEAD / HTTP/1.0"
willy tarreauc5f73ed2005-12-18 01:26:38 +01001646
willy tarreau532bb552006-05-13 18:40:37 +02001647 Field Format Example
willy tarreauc5f73ed2005-12-18 01:26:38 +01001648
willy tarreau532bb552006-05-13 18:40:37 +02001649 1 process_name '[' pid ']:' haproxy[18989]:
1650 2 client_ip ':' client_port 10.0.0.1:34552
1651 3 '[' date ']' [15/Oct/2003:15:26:31]
1652 4 listener_name relais-http
1653 5 server_name Srv1
1654 6 Tq '/' Tw '/' Tc '/' Tr '/' Tt 3183/-1/-1/-1/11215
1655 7 HTTP_return_code 503
1656 8 bytes_read 0
1657 9 captured_request_cookie -
1658 10 captured_response_cookie -
1659 11 termination_state SC--
1660 12 srv_conn '/' listener_conn '/' process_conn 137/202/205
1661 13 position in srv_queue / listener_queue 0/0
1662 14 '{' captured_request_headers '}' {w.ods.org|Mozilla}
1663 15 '{' captured_response_headers '}' {}
1664 16 '"' HTTP_request '"' "HEAD / HTTP/1.0"
willy tarreauc5f73ed2005-12-18 01:26:38 +01001665
1666Note for log parsers: the URI is ALWAYS the end of the line starting with the
1667 first double quote '"'.
willy tarreau982249e2005-12-18 00:57:06 +01001668
1669The problem when logging at end of connection is that you have no clue about
1670what is happening during very long sessions. To workaround this problem, a
1671new option 'logasap' has been introduced in 1.1.28/1.2.1. When specified, the
1672proxy will log as soon as possible, just before data transfer begins. This means
1673that in case of TCP, it will still log the connection status to the server, and
1674in case of HTTP, it will log just after processing the server headers. In this
1675case, the number of bytes reported is the number of header bytes sent to the
1676client.
1677
1678In order to avoid confusion with normal logs, the total time field and the
1679number of bytes are prefixed with a '+' sign which mean that real numbers are
1680certainly bigger.
1681
1682Example :
1683---------
1684
1685 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001686 mode http
1687 option httplog
1688 option dontlognull
1689 option logasap
1690 log 192.168.2.200 local3
willy tarreau982249e2005-12-18 00:57:06 +01001691
willy tarreau532bb552006-05-13 18:40:37 +02001692>>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17] relais-http Srv1 9/10/7/14/+30 200 +243 - - ---- 1/1/3 1/0 "GET /image.iso HTTP/1.0"
willy tarreau982249e2005-12-18 00:57:06 +01001693
willy tarreauc1cae632005-12-17 14:12:23 +010016944.2.3) Timing events
1695--------------------
1696Timers provide a great help in trouble shooting network problems. All values
1697are reported in milliseconds (ms). In HTTP mode, four control points are
willy tarreau532bb552006-05-13 18:40:37 +02001698reported under the form 'Tq/Tw/Tc/Tr/Tt' :
willy tarreauc1cae632005-12-17 14:12:23 +01001699
1700 - Tq: total time to get the client request.
1701 It's the time elapsed between the moment the client connection was accepted
1702 and the moment the proxy received the last HTTP header. The value '-1'
1703 indicates that the end of headers (empty line) has never been seen.
1704
willy tarreau532bb552006-05-13 18:40:37 +02001705 - Tw: total time spent in the queues waiting for a connection slot. It
1706 accounts for listener's queue as well as the server's queue, and depends
1707 on the queue size, and the time needed for the server to complete previous
1708 sessions. The value '-1' means that the request was killed before reaching
1709 the queue.
1710
willy tarreauc1cae632005-12-17 14:12:23 +01001711 - Tc: total time to establish the TCP connection to the server.
1712 It's the time elapsed between the moment the proxy sent the connection
1713 request, and the moment it was acknowledged, or between the TCP SYN packet
1714 and the matching SYN/ACK in return. The value '-1' means that the
1715 connection never established.
1716
1717 - Tr: server response time. It's the time elapsed between the moment the
1718 TCP connection was established to the server and the moment it send its
1719 complete response header. It purely shows its request processing time,
1720 without the network overhead due to the data transmission. The value '-1'
1721 means that the last the response header (empty line) was never seen.
1722
1723 - Tt: total session duration time, between the moment the proxy accepted it
willy tarreau982249e2005-12-18 00:57:06 +01001724 and the moment both ends were closed. The exception is when the 'logasap'
willy tarreau532bb552006-05-13 18:40:37 +02001725 option is specified. In this case, it only equals (Tq+Tw+Tc+Tr), and is
willy tarreau982249e2005-12-18 00:57:06 +01001726 prefixed with a '+' sign. From this field, we can deduce Td, the data
1727 transmission time, by substracting other timers when valid :
willy tarreauc1cae632005-12-17 14:12:23 +01001728
willy tarreau532bb552006-05-13 18:40:37 +02001729 Td = Tt - (Tq + Tw + Tc + Tr)
willy tarreauc1cae632005-12-17 14:12:23 +01001730
1731 Timers with '-1' values have to be excluded from this equation.
1732
willy tarreau532bb552006-05-13 18:40:37 +02001733In TCP mode ('option tcplog'), only Tw, Tc and Tt are reported.
willy tarreauc1cae632005-12-17 14:12:23 +01001734
1735These timers provide precious indications on trouble causes. Since the TCP
1736protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure
1737that timers close to multiples of 3s are nearly always related to packets lost
1738due to network problems (wires or negociation). Moreover, if <Tt> is close to
1739a timeout value specified in the configuration, it often means that a session
1740has been aborted on time-out.
1741
1742Most common cases :
1743
1744 - If Tq is close to 3000, a packet has probably been lost between the client
1745 and the proxy.
1746 - If Tc is close to 3000, a packet has probably been lost between the server
1747 and the proxy during the server connection phase. This one should always be
1748 very low (less than a few tens).
1749 - If Tr is nearly always lower than 3000 except some rare values which seem to
1750 be the average majored by 3000, there are probably some packets lost between
1751 the proxy and the server.
1752 - If Tt is often slightly higher than a time-out, it's often because the
1753 client and the server use HTTP keep-alive and the session is maintained
1754 after the response ends. Se further for how to disable HTTP keep-alive.
1755
1756Other cases ('xx' means any value to be ignored) :
willy tarreau532bb552006-05-13 18:40:37 +02001757 -1/xx/xx/xx/Tt: the client was not able to send its complete request in time,
1758 or that it aborted it too early.
1759 Tq/-1/xx/xx/Tt: it was not possible to process the request, maybe because
1760 servers were out of order.
1761 Tq/Tw/-1/xx/Tt: the connection could not establish on the server. Either it
1762 refused it or it timed out after Tt-(Tq+Tw) ms.
1763 Tq/Tw/Tc/-1/Tt: the server has accepted the connection but did not return a
1764 complete response in time, or it closed its connexion
1765 unexpectedly, after Tt-(Tq+Tw+Tc) ms.
willy tarreauc1cae632005-12-17 14:12:23 +01001766
17674.2.4) Session state at disconnection
1768-------------------------------------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001769TCP and HTTP logs provide a session completion indicator in the
1770<termination_state> field, just before the number of active
1771connections. It is 2-characters long in TCP, and 4-characters long in
1772HTTP, each of which has a special meaning :
1773
willy tarreau197e8ec2005-12-17 14:10:59 +01001774 - On the first character, a code reporting the first event which caused the
1775 session to terminate :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001776
willy tarreauc5f73ed2005-12-18 01:26:38 +01001777 C : the TCP session was unexpectedly aborted by the client.
1778
1779 S : the TCP session was unexpectedly aborted by the server, or the
1780 server explicitly refused it.
1781
1782 P : the session was prematurely aborted by the proxy, because of a
1783 connection limit enforcement, because a DENY filter was matched,
1784 or because of a security check which detected and blocked a
1785 dangerous error in server response which might have caused
1786 information leak (eg: cacheable cookie).
1787
1788 R : a resource on the proxy has been exhausted (memory, sockets, source
1789 ports, ...). Usually, this appears during the connection phase, and
1790 system logs should contain a copy of the precise error.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001791
willy tarreauc5f73ed2005-12-18 01:26:38 +01001792 I : an internal error was identified by the proxy during a self-check.
1793 This should NEVER happen, and you are encouraged to report any log
1794 containing this, because this is a bug.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001795
willy tarreauc5f73ed2005-12-18 01:26:38 +01001796 c : the client-side time-out expired first.
1797
1798 s : the server-side time-out expired first.
1799
1800 - : normal session completion.
1801
1802 - on the second character, the TCP/HTTP session state when it was closed :
1803
1804 R : waiting for complete REQUEST from the client (HTTP only). Nothing
1805 was sent to any server.
1806
willy tarreau532bb552006-05-13 18:40:37 +02001807 Q : waiting in the QUEUE for a connection slot. This can only happen on
1808 servers which have a 'maxconn' parameter set. No connection attempt
1809 was made to any server.
1810
willy tarreauc5f73ed2005-12-18 01:26:38 +01001811 C : waiting for CONNECTION to establish on the server. The server might
1812 at most have noticed a connection attempt.
1813
1814 H : waiting for, receiving and processing server HEADERS (HTTP only).
1815
1816 D : the session was in the DATA phase.
1817
1818 L : the proxy was still transmitting LAST data to the client while the
1819 server had already finished.
1820
Willy Tarreau2272dc12006-09-03 10:19:38 +02001821 T : the request was tarpitted. It has been held open on with the client
Willy Tarreau08fa2e32006-09-03 10:47:37 +02001822 during the whole contimeout duration or untill the client closed.
Willy Tarreau2272dc12006-09-03 10:19:38 +02001823
willy tarreauc5f73ed2005-12-18 01:26:38 +01001824 - : normal session completion after end of data transfer.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001825
willy tarreau197e8ec2005-12-17 14:10:59 +01001826 - the third character tells whether the persistence cookie was provided by
willy tarreauc1cae632005-12-17 14:12:23 +01001827 the client (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001828
willy tarreauc5f73ed2005-12-18 01:26:38 +01001829 N : the client provided NO cookie. This is usually the case on new
1830 connections.
1831
1832 I : the client provided an INVALID cookie matching no known
1833 server. This might be caused by a recent configuration change,
1834 mixed cookies between HTTP/HTTPS sites, or an attack.
1835
1836 D : the client provided a cookie designating a server which was DOWN,
1837 so either the 'persist' option was used and the client was sent to
1838 this server, or it was not set and the client was redispatched to
1839 another server.
1840
1841 V : the client provided a valid cookie, and was sent to the associated
1842 server.
1843
1844 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001845
willy tarreau197e8ec2005-12-17 14:10:59 +01001846 - the last character reports what operations were performed on the persistence
willy tarreauc1cae632005-12-17 14:12:23 +01001847 cookie returned by the server (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001848
willy tarreauc5f73ed2005-12-18 01:26:38 +01001849 N : NO cookie was provided by the server, and none was inserted either.
1850
1851 I : no cookie was provided by the server, and the proxy INSERTED one.
1852
willy tarreau197e8ec2005-12-17 14:10:59 +01001853 P : a cookie was PROVIDED by the server and transmitted as-is.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001854
willy tarreauc5f73ed2005-12-18 01:26:38 +01001855 R : the cookie provided by the server was REWRITTEN by the proxy.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001856
willy tarreauc5f73ed2005-12-18 01:26:38 +01001857 D : the cookie provided by the server was DELETED by the proxy.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001858
willy tarreauc5f73ed2005-12-18 01:26:38 +01001859 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001860
willy tarreauc5f73ed2005-12-18 01:26:38 +01001861The combination of the two first flags give a lot of information about what was
1862happening when the session terminated. It can be helpful to detect server
1863saturation, network troubles, local system resource starvation, attacks, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01001864
willy tarreauc5f73ed2005-12-18 01:26:38 +01001865The most common termination flags combinations are indicated here.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001866
willy tarreauc5f73ed2005-12-18 01:26:38 +01001867 Flags Reason
1868 CR The client aborted before sending a full request. Most probably the
1869 request was done by hand using a telnet client, and aborted early.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001870
willy tarreauc5f73ed2005-12-18 01:26:38 +01001871 cR The client timed out before sending a full request. This is sometimes
1872 caused by too large TCP MSS values on the client side for PPPoE
1873 networks which cannot transport full-sized packets, or by clients
1874 sending requests by hand and not typing fast enough.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001875
willy tarreauc5f73ed2005-12-18 01:26:38 +01001876 SC The server explicitly refused the connection (the proxy received a
1877 TCP RST or an ICMP in return). Under some circumstances, it can
1878 also be the network stack telling the proxy that the server is
1879 unreachable (eg: no route, or no ARP response on local network).
willy tarreau982249e2005-12-18 00:57:06 +01001880
willy tarreauc5f73ed2005-12-18 01:26:38 +01001881 sC The connection to the server did not complete during contimeout.
willy tarreau982249e2005-12-18 00:57:06 +01001882
willy tarreauc5f73ed2005-12-18 01:26:38 +01001883 PC The proxy refused to establish a connection to the server because the
1884 maxconn limit has been reached. The listener's maxconn parameter may
1885 be increased in the proxy configuration, as well as the global
1886 maxconn parameter.
willy tarreauc1cae632005-12-17 14:12:23 +01001887
willy tarreauc5f73ed2005-12-18 01:26:38 +01001888 RC A local resource has been exhausted (memory, sockets, source ports)
1889 preventing the connection to the server from establishing. The error
1890 logs will tell precisely what was missing. Anyway, this can only be
1891 solved by system tuning.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001892
willy tarreauc5f73ed2005-12-18 01:26:38 +01001893 cH The client timed out during a POST request. This is sometimes caused
1894 by too large TCP MSS values for PPPoE networks which cannot transport
1895 full-sized packets.
willy tarreauc1cae632005-12-17 14:12:23 +01001896
willy tarreau078c79a2006-05-13 12:23:58 +02001897 CH The client aborted while waiting for the server to start responding.
1898 It might be the server taking too long to respond or the client
1899 clicking the 'Stop' button too fast.
1900
1901 CQ The client aborted while its session was queued, waiting for a server
1902 with enough empty slots to accept it. It might be that either all the
1903 servers were saturated or the assigned server taking too long to
1904 respond.
1905
Willy Tarreau08fa2e32006-09-03 10:47:37 +02001906 CT The client aborted while its session was tarpitted.
1907
willy tarreau078c79a2006-05-13 12:23:58 +02001908 sQ The session spent too much time in queue and has been expired.
1909
willy tarreauc5f73ed2005-12-18 01:26:38 +01001910 SH The server aborted before sending its full headers, or it crashed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001911
willy tarreauc5f73ed2005-12-18 01:26:38 +01001912 sH The server failed to reply during the srvtimeout delay, which
1913 indicates too long transactions, probably caused by back-end
1914 saturation. The only solutions are to fix the problem on the
1915 application or to increase the 'srvtimeout' parameter to support
1916 longer delays (at the risk of the client giving up anyway).
1917
1918 PR The proxy blocked the client's request, either because of an invalid
1919 HTTP syntax, in which case it returned an HTTP 400 error to the
1920 client, or because a deny filter matched, in which case it returned
1921 an HTTP 403 error.
1922
1923 PH The proxy blocked the server's response, because it was invalid,
1924 incomplete, dangerous (cache control), or matched a security filter.
1925 In any case, an HTTP 502 error is sent to the client.
1926
Willy Tarreau2272dc12006-09-03 10:19:38 +02001927 PT The proxy blocked the client's request and has tarpitted its
1928 connection before returning it a 500 server error. Nothing was sent
1929 to the server.
1930
willy tarreauc5f73ed2005-12-18 01:26:38 +01001931 cD The client did not read any data for as long as the clitimeout delay.
1932 This is often caused by network failures on the client side.
1933
1934 CD The client unexpectedly aborted during data transfer. This is either
1935 caused by a browser crash, or by a keep-alive session between the
1936 server and the client terminated first by the client.
1937
1938 sD The server did nothing during the srvtimeout delay. This is often
1939 caused by too short timeouts on L4 equipements before the server
1940 (firewalls, load-balancers, ...).
1941
19424.2.5) Non-printable characters
willy tarreau4302f492005-12-18 01:00:37 +01001943-------------------------------
1944As of version 1.1.29, non-printable characters are not sent as-is into log
1945files, but are converted to their two-digits hexadecimal representation,
1946prefixed by the character '#'. The only characters that can now be logged
1947without being escaped are between 32 and 126 (inclusive). Obviously, the
1948escape character '#' is also encoded to avoid any ambiguity. It is the same for
1949the character '"', as well as '{', '|' and '}' when logging headers.
1950
willy tarreauc5f73ed2005-12-18 01:26:38 +010019514.2.6) Capturing HTTP headers and cookies
1952-----------------------------------------
1953Version 1.1.23 brought cookie capture, and 1.1.29 the header capture. All this
1954is performed using the 'capture' keyword.
1955
1956Cookie capture makes it easy to track a complete user session. The syntax is :
1957
1958 capture cookie <cookie_prefix> len <capture_length>
1959
1960This will enable cookie capture from both requests and responses. This way,
1961it's easy to detect when a user switches to a new session for example, because
1962the server will reassign it a new cookie.
1963
1964The FIRST cookie whose name starts with <cookie_prefix> will be captured, and
1965logged as 'NAME=value', without exceeding <capture_length> characters (64 max).
1966When the cookie name is fixed and known, it's preferable to suffix '=' to it to
1967ensure that no other cookie will be logged.
1968
1969Examples :
1970----------
1971 # capture the first cookie whose name starts with "ASPSESSION"
1972 capture cookie ASPSESSION len 32
1973
1974 # capture the first cookie whose name is exactly "vgnvisitor"
1975 capture cookie vgnvisitor= len 32
1976
1977In the logs, the field preceeding the completion indicator contains the cookie
1978value as sent by the server, preceeded by the cookie value as sent by the
1979client. Each of these field is replaced with '-' when no cookie was seen or
1980when the option is disabled.
1981
1982Header captures have a different goal. They are useful to track unique request
1983identifiers set by a previous proxy, virtual host names, user-agents, POST
1984content-length, referrers, etc. In the response, one can search for information
1985about the response length, how the server asked the cache to behave, or an
1986object location during a redirection. As for cookie captures, it is both
1987possible to include request headers and response headers at the same time. The
1988syntax is :
willy tarreau4302f492005-12-18 01:00:37 +01001989
1990 capture request header <name> len <max length>
1991 capture response header <name> len <max length>
1992
1993Note: Header names are not case-sensitive.
1994
1995Examples:
1996---------
1997 # keep the name of the virtual server
1998 capture request header Host len 20
1999 # keep the amount of data uploaded during a POST
2000 capture request header Content-Length len 10
2001
2002 # note the expected cache behaviour on the response
2003 capture response header Cache-Control len 8
2004 # note the URL location during a redirection
2005 capture response header Location len 20
2006
2007Non-existant headers are logged as empty strings, and if one header appears more
2008than once, only its last occurence will be kept. Request headers are grouped
2009within braces '{' and '}' in the same order as they were declared, and delimited
2010with a vertical bar '|' without any space. Response headers follow the same
2011representation, but are displayed after a space following the request headers
2012block. These blocks are displayed just before the HTTP request in the logs.
willy tarreauc5f73ed2005-12-18 01:26:38 +01002013
willy tarreau4302f492005-12-18 01:00:37 +01002014Example :
2015
willy tarreauc5f73ed2005-12-18 01:26:38 +01002016 Config:
2017
2018 capture request header Host len 20
2019 capture request header Content-Length len 10
2020 capture request header Referer len 20
2021 capture response header Server len 20
2022 capture response header Content-Length len 10
2023 capture response header Cache-Control len 8
2024 capture response header Via len 20
2025 capture response header Location len 20
2026
2027 Log :
2028
willy tarreau532bb552006-05-13 18:40:37 +02002029 Aug 9 20:26:09 localhost haproxy[2022]: 127.0.0.1:34014 [09/Aug/2004:20:26:09] relais-http netcache 0/0/0/162/+162 200 +350 - - ---- 0/0/0 0/0 {fr.adserver.yahoo.co||http://fr.f416.mail.} {|864|private||} "GET http://fr.adserver.yahoo.com/"
2030 Aug 9 20:30:46 localhost haproxy[2022]: 127.0.0.1:34020 [09/Aug/2004:20:30:46] relais-http netcache 0/0/0/182/+182 200 +279 - - ---- 0/0/0 0/0 {w.ods.org||} {Formilux/0.1.8|3495|||} "GET http://w.ods.org/sytadin.html HTTP/1.1"
2031 Aug 9 20:30:46 localhost haproxy[2022]: 127.0.0.1:34028 [09/Aug/2004:20:30:46] relais-http netcache 0/0/2/126/+128 200 +223 - - ---- 0/0/0 0/0 {www.infotrafic.com||http://w.ods.org/syt} {Apache/2.0.40 (Red H|9068|||} "GET http://www.infotrafic.com/images/live/cartesidf/grandes/idf_ne.png HTTP/1.1"
willy tarreauc5f73ed2005-12-18 01:26:38 +01002032
2033
20344.2.7) Examples of logs
2035-----------------------
willy tarreau532bb552006-05-13 18:40:37 +02002036- haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57] relais-http Srv1 6559/0/7/147/6723 200 243 - - ---- 1/3/5 0/0 "HEAD / HTTP/1.0"
willy tarreauc5f73ed2005-12-18 01:26:38 +01002037 => long request (6.5s) entered by hand through 'telnet'. The server replied
2038 in 147 ms, and the session ended normally ('----')
2039
willy tarreau532bb552006-05-13 18:40:37 +02002040- haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57] relais-http Srv1 6559/1230/7/147/6870 200 243 - - ---- 99/239/324 0/9 "HEAD / HTTP/1.0"
2041 => Idem, but the request was queued in the global queue behind 9 other
2042 requests, and waited there for 1230 ms.
2043
2044- haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17] relais-http Srv1 9/0/7/14/+30 200 +243 - - ---- 1/3/3 0/0 "GET /image.iso HTTP/1.0"
willy tarreauc5f73ed2005-12-18 01:26:38 +01002045 => request for a long data transfer. The 'logasap' option was specified, so
2046 the log was produced just before transfering data. The server replied in
2047 14 ms, 243 bytes of headers were sent to the client, and total time from
2048 accept to first data byte is 30 ms.
2049
willy tarreau532bb552006-05-13 18:40:37 +02002050- haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17] relais-http Srv1 9/0/7/14/30 502 243 - - PH-- 0/2/3 0/0 "GET /cgi-bin/bug.cgi? HTTP/1.0"
willy tarreauc5f73ed2005-12-18 01:26:38 +01002051 => the proxy blocked a server response either because of an 'rspdeny' or
2052 'rspideny' filter, or because it blocked sensible information which risked
2053 being cached. In this case, the response is replaced with a '502 bad
2054 gateway'.
2055
willy tarreau532bb552006-05-13 18:40:37 +02002056- haproxy[18113]: 127.0.0.1:34548 [15/Oct/2003:15:18:55] relais-http <NOSRV> -1/-1/-1/-1/8490 -1 0 - - CR-- 0/2/2 0/0 ""
willy tarreauc5f73ed2005-12-18 01:26:38 +01002057 => the client never completed its request and aborted itself ('C---') after
2058 8.5s, while the proxy was waiting for the request headers ('-R--').
2059 Nothing was sent to the server.
2060
willy tarreau532bb552006-05-13 18:40:37 +02002061- haproxy[18113]: 127.0.0.1:34549 [15/Oct/2003:15:19:06] relais-http <NOSRV> -1/-1/-1/-1/50001 408 0 - - cR-- 2/2 0/0 ""
willy tarreauc5f73ed2005-12-18 01:26:38 +01002062 => The client never completed its request, which was aborted by the time-out
2063 ('c---') after 50s, while the proxy was waiting for the request headers ('-R--').
2064 Nothing was sent to the server, but the proxy could send a 408 return code
2065 to the client.
willy tarreau4302f492005-12-18 01:00:37 +01002066
willy tarreau532bb552006-05-13 18:40:37 +02002067- haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28] relais-tcp Srv1 0/0/5007 0 cD 0/0/0 0/0
willy tarreauc5f73ed2005-12-18 01:26:38 +01002068 => This is a 'tcplog' entry. Client-side time-out ('c----') occured after 5s.
willy tarreau4302f492005-12-18 01:00:37 +01002069
willy tarreau532bb552006-05-13 18:40:37 +02002070- haproxy[18989]: 10.0.0.1:34552 [15/Oct/2003:15:26:31] relais-http Srv1 3183/-1/-1/-1/11215 503 0 - - SC-- 115/202/205 0/0 "HEAD / HTTP/1.0"
willy tarreauc5f73ed2005-12-18 01:26:38 +01002071 => The request took 3s to complete (probably a network problem), and the
2072 connection to the server failed ('SC--') after 4 attemps of 2 seconds
2073 (config says 'retries 3'), then a 503 error code was sent to the client.
willy tarreau532bb552006-05-13 18:40:37 +02002074 There were 115 connections on this server, 202 connections on this proxy,
2075 and 205 on the global process. It is possible that the server refused the
2076 connection because of too many already established.
willy tarreau4302f492005-12-18 01:00:37 +01002077
willy tarreau4302f492005-12-18 01:00:37 +01002078
willy tarreau197e8ec2005-12-17 14:10:59 +010020794.3) HTTP header manipulation
2080-----------------------------
2081In HTTP mode, it is possible to rewrite, add or delete some of the request and
2082response headers based on regular expressions. It is also possible to block a
2083request or a response if a particular header matches a regular expression,
2084which is enough to stops most elementary protocol attacks, and to protect
2085against information leak from the internal network. But there is a limitation
2086to this : since haproxy's HTTP engine knows nothing about keep-alive, only
2087headers passed during the first request of a TCP session will be seen. All
2088subsequent headers will be considered data only and not analyzed. Furthermore,
2089haproxy doesn't touch data contents, it stops at the end of headers.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002090
willy tarreau197e8ec2005-12-17 14:10:59 +01002091The syntax is :
2092 reqadd <string> to add a header to the request
2093 reqrep <search> <replace> to modify the request
2094 reqirep <search> <replace> same, but ignoring the case
2095 reqdel <search> to delete a header in the request
2096 reqidel <search> same, but ignoring the case
2097 reqallow <search> definitely allow a request if a header matches <search>
2098 reqiallow <search> same, but ignoring the case
2099 reqdeny <search> denies a request if a header matches <search>
2100 reqideny <search> same, but ignoring the case
2101 reqpass <search> ignore a header matching <search>
2102 reqipass <search> same, but ignoring the case
Willy Tarreau2272dc12006-09-03 10:19:38 +02002103 reqtarpit <search> tarpit a request matching <search>
2104 reqitarpit <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01002105
willy tarreau197e8ec2005-12-17 14:10:59 +01002106 rspadd <string> to add a header to the response
2107 rsprep <search> <replace> to modify the response
2108 rspirep <search> <replace> same, but ignoring the case
2109 rspdel <search> to delete the response
2110 rspidel <search> same, but ignoring the case
willy tarreau982249e2005-12-18 00:57:06 +01002111 rspdeny <search> replaces a response with a HTTP 502 if a header matches <search>
2112 rspideny <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01002113
2114
willy tarreau197e8ec2005-12-17 14:10:59 +01002115<search> is a POSIX regular expression (regex) which supports grouping through
2116parenthesis (without the backslash). Spaces and other delimiters must be
2117prefixed with a backslash ('\') to avoid confusion with a field delimiter.
2118Other characters may be prefixed with a backslash to change their meaning :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002119
willy tarreau197e8ec2005-12-17 14:10:59 +01002120 \t for a tab
2121 \r for a carriage return (CR)
2122 \n for a new line (LF)
2123 \ to mark a space and differentiate it from a delimiter
2124 \# to mark a sharp and differentiate it from a comment
2125 \\ to use a backslash in a regex
2126 \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy)
2127 \xXX to write the ASCII hex code XX as in the C language
willy tarreaueedaa9f2005-12-17 14:08:03 +01002128
2129
Willy Tarreau2272dc12006-09-03 10:19:38 +02002130<replace> contains the string to be used to replace the largest portion of text
willy tarreau197e8ec2005-12-17 14:10:59 +01002131matching the regex. It can make use of the special characters above, and can
2132reference a substring delimited by parenthesis in the regex, by the group
Willy Tarreau2272dc12006-09-03 10:19:38 +02002133numerical order from 0 to 9 (0 being the entire line). In this case, you would
2134write a backslash ('\') immediately followed by one digit indicating the group
2135position.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002136
willy tarreau197e8ec2005-12-17 14:10:59 +01002137<string> represents the string which will systematically be added after the last
2138header line. It can also use special characters above.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002139
willy tarreau197e8ec2005-12-17 14:10:59 +01002140Notes :
2141-------
2142 - the first line is considered as a header, which makes it possible to rewrite
2143 or filter HTTP requests URIs or response codes.
2144 - 'reqrep' is the equivalent of 'cliexp' in version 1.0, and 'rsprep' is the
2145 equivalent of 'srvexp' in 1.0. Those names are still supported but
2146 deprecated.
2147 - for performances reasons, the number of characters added to a request or to
2148 a response is limited to 4096 since version 1.1.5 (it was 256 before). This
2149 value is easy to modify in the code if needed (#define). If it is too short
2150 on occasional uses, it is possible to gain some space by removing some
2151 useless headers before adding new ones.
willy tarreau982249e2005-12-18 00:57:06 +01002152 - a denied request will generate an "HTTP 403 forbidden" response, while a
2153 denied response will generate an "HTTP 502 Bad gateway" response.
Willy Tarreau2272dc12006-09-03 10:19:38 +02002154 - a tarpitted request will be held open on the client side for a duration
Willy Tarreau08fa2e32006-09-03 10:47:37 +02002155 defined in the contimeout parameter, or untill the client aborts. Nothing
2156 will be sent to any server. When the timeout is reached, the proxy will
2157 reply with a 500 server error response so that the attacker does not
2158 suspect it has been tarpitted. The logs may report the 500, but the
2159 termination flags will indicate 'PT' in this case.
Willy Tarreau2272dc12006-09-03 10:19:38 +02002160
willy tarreaueedaa9f2005-12-17 14:08:03 +01002161
willy tarreau197e8ec2005-12-17 14:10:59 +01002162Examples :
2163----------
willy tarreauc5f73ed2005-12-18 01:26:38 +01002164 ###### a few examples ######
willy tarreau197e8ec2005-12-17 14:10:59 +01002165
willy tarreauc5f73ed2005-12-18 01:26:38 +01002166 # rewrite 'online.fr' instead of 'free.fr' for GET and POST requests
2167 reqrep ^(GET\ .*)(.free.fr)(.*) \1.online.fr\3
2168 reqrep ^(POST\ .*)(.free.fr)(.*) \1.online.fr\3
willy tarreau197e8ec2005-12-17 14:10:59 +01002169
willy tarreauc5f73ed2005-12-18 01:26:38 +01002170 # force proxy connections to close
2171 reqirep ^Proxy-Connection:.* Proxy-Connection:\ close
2172 # rewrite locations
2173 rspirep ^(Location:\ )([^:]*://[^/]*)(.*) \1\3
willy tarreaueedaa9f2005-12-17 14:08:03 +01002174
willy tarreauc5f73ed2005-12-18 01:26:38 +01002175 ###### A full configuration being used on production ######
willy tarreaueedaa9f2005-12-17 14:08:03 +01002176
willy tarreau197e8ec2005-12-17 14:10:59 +01002177 # Every header should end with a colon followed by one space.
willy tarreauc5f73ed2005-12-18 01:26:38 +01002178 reqideny ^[^:\ ]*[\ ]*$
willy tarreaueedaa9f2005-12-17 14:08:03 +01002179
willy tarreau197e8ec2005-12-17 14:10:59 +01002180 # block Apache chunk exploit
willy tarreauc5f73ed2005-12-18 01:26:38 +01002181 reqideny ^Transfer-Encoding:[\ ]*chunked
2182 reqideny ^Host:\ apache-
willy tarreaueedaa9f2005-12-17 14:08:03 +01002183
willy tarreau197e8ec2005-12-17 14:10:59 +01002184 # block annoying worms that fill the logs...
willy tarreauc5f73ed2005-12-18 01:26:38 +01002185 reqideny ^[^:\ ]*\ .*(\.|%2e)(\.|%2e)(%2f|%5c|/|\\\\)
2186 reqideny ^[^:\ ]*\ ([^\ ]*\ [^\ ]*\ |.*%00)
2187 reqideny ^[^:\ ]*\ .*<script
2188 reqideny ^[^:\ ]*\ .*/(root\.exe\?|cmd\.exe\?|default\.ida\?)
willy tarreau197e8ec2005-12-17 14:10:59 +01002189
Willy Tarreau2272dc12006-09-03 10:19:38 +02002190 # tarpit attacks on the login page.
2191 reqtarpit ^[^:\ ]*\ .*\.php?login=[^0-9]
2192
willy tarreau197e8ec2005-12-17 14:10:59 +01002193 # allow other syntactically valid requests, and block any other method
willy tarreauc5f73ed2005-12-18 01:26:38 +01002194 reqipass ^(GET|POST|HEAD|OPTIONS)\ /.*\ HTTP/1\.[01]$
2195 reqipass ^OPTIONS\ \\*\ HTTP/1\.[01]$
2196 reqideny ^[^:\ ]*\
willy tarreau197e8ec2005-12-17 14:10:59 +01002197
2198 # force connection:close, thus disabling HTTP keep-alive
willy tarreauc5f73ed2005-12-18 01:26:38 +01002199 option httpclose
willy tarreau197e8ec2005-12-17 14:10:59 +01002200
willy tarreauc5f73ed2005-12-18 01:26:38 +01002201 # change the server name
2202 rspidel ^Server:\
2203 rspadd Server:\ Formilux/0.1.8
willy tarreau197e8ec2005-12-17 14:10:59 +01002204
2205
willy tarreau982249e2005-12-18 00:57:06 +01002206Also, the 'forwardfor' option creates an HTTP 'X-Forwarded-For' header which
willy tarreauc1cae632005-12-17 14:12:23 +01002207contains the client's IP address. This is useful to let the final web server
Willy Tarreau7ac51f62007-03-25 16:00:04 +02002208know what the client address was (eg for statistics on domains). Starting with
2209version 1.3.8, it is possible to specify the "except" keyword followed by a
2210source IP address or network for which no header will be added. This is very
2211useful when another reverse-proxy which already adds the header runs on the
2212same machine or in a known DMZ, the most common case being the local use of
2213stunnel on the same system.
willy tarreauc1cae632005-12-17 14:12:23 +01002214
willy tarreau982249e2005-12-18 00:57:06 +01002215Last, the 'httpclose' option removes any 'Connection' header both ways, and
2216adds a 'Connection: close' header in each direction. This makes it easier to
Willy TARREAU767ba712006-03-01 22:40:50 +01002217disable HTTP keep-alive than the previous 4-rules block.
willy tarreau982249e2005-12-18 00:57:06 +01002218
willy tarreauc1cae632005-12-17 14:12:23 +01002219Example :
2220---------
2221 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01002222 mode http
2223 log global
2224 option httplog
2225 option dontlognull
Willy Tarreau7ac51f62007-03-25 16:00:04 +02002226 option forwardfor except 127.0.0.1/8
willy tarreauc5f73ed2005-12-18 01:26:38 +01002227 option httpclose
2228
Willy TARREAU767ba712006-03-01 22:40:50 +01002229Note that some HTTP servers do not necessarily close the connections when they
2230receive the 'Connection: close', and if the client does not close either, then
2231the connection will be maintained up to the time-out. This translates into high
2232number of simultaneous sessions and high global session times in the logs. To
2233workaround this, a new option 'forceclose' appeared in version 1.2.9 to enforce
2234the closing of the outgoing server channel as soon as the server begins to
2235reply and only if the request buffer is empty. Note that this should NOT be
2236used if CONNECT requests are expected between the client and the server. The
2237'forceclose' option implies the 'httpclose' option.
2238
2239Example :
2240---------
2241 listen http_proxy 0.0.0.0:80
2242 mode http
2243 log global
2244 option httplog
2245 option dontlognull
2246 option forwardfor
2247 option forceclose
2248
willy tarreau197e8ec2005-12-17 14:10:59 +01002249
22504.4) Load balancing with persistence
2251------------------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01002252Combining cookie insertion with internal load balancing allows to transparently
2253bring persistence to applications. The principle is quite simple :
2254 - assign a cookie value to each server
2255 - enable the load balancing between servers
2256 - insert a cookie into responses resulting from the balancing algorithm
2257 (indirect accesses), end ensure that no upstream proxy will cache it.
2258 - remove the cookie in the request headers so that the application never sees
2259 it.
2260
2261Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002262---------
2263 listen application 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01002264 mode http
2265 cookie SERVERID insert nocache indirect
2266 balance roundrobin
2267 server srv1 192.168.1.1:80 cookie server01 check
2268 server srv2 192.168.1.2:80 cookie server02 check
willy tarreaueedaa9f2005-12-17 14:08:03 +01002269
willy tarreau0174f312005-12-18 01:02:42 +01002270The other solution brought by versions 1.1.30 and 1.2.3 is to reuse a cookie
2271from the server, and prefix the server's name to it. In this case, don't forget
2272to force "httpclose" mode so that you can be assured that every subsequent
2273request will have its cookie fixed.
2274
2275 listen application 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01002276 mode http
2277 cookie JSESSIONID prefix
2278 balance roundrobin
2279 server srv1 192.168.1.1:80 cookie srv1 check
2280 server srv2 192.168.1.2:80 cookie srv2 check
2281 option httpclose
willy tarreau0174f312005-12-18 01:02:42 +01002282
2283
willy tarreau982249e2005-12-18 00:57:06 +010022844.5) Protection against information leak from the servers
2285---------------------------------------------------------
2286In versions 1.1.28/1.2.1, a new option 'checkcache' was created. It carefully
2287checks 'Cache-control', 'Pragma' and 'Set-cookie' headers in server response
2288to check if there's a risk of caching a cookie on a client-side proxy. When this
2289option is enabled, the only responses which can be delivered to the client are :
2290 - all those without 'Set-Cookie' header ;
2291 - all those with a return code other than 200, 203, 206, 300, 301, 410,
2292 provided that the server has not set a 'Cache-control: public' header ;
2293 - all those that come from a POST request, provided that the server has not
2294 set a 'Cache-Control: public' header ;
2295 - those with a 'Pragma: no-cache' header
2296 - those with a 'Cache-control: private' header
2297 - those with a 'Cache-control: no-store' header
2298 - those with a 'Cache-control: max-age=0' header
2299 - those with a 'Cache-control: s-maxage=0' header
2300 - those with a 'Cache-control: no-cache' header
2301 - those with a 'Cache-control: no-cache="set-cookie"' header
2302 - those with a 'Cache-control: no-cache="set-cookie,' header
2303 (allowing other fields after set-cookie)
willy tarreaueedaa9f2005-12-17 14:08:03 +01002304
willy tarreau982249e2005-12-18 00:57:06 +01002305If a response doesn't respect these requirements, then it will be blocked just
2306as if it was from an 'rspdeny' filter, with an "HTTP 502 bad gateway". The
2307session state shows "PH--" meaning that the proxy blocked the response during
2308headers processing. Additionnaly, an alert will be sent in the logs so that
2309admins are told that there's something to be done.
2310
willy tarreauc5f73ed2005-12-18 01:26:38 +01002311
willy tarreau982249e2005-12-18 00:57:06 +010023124.6) Customizing errors
2313-----------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01002314Some situations can make haproxy return an HTTP error code to the client :
2315 - invalid or too long request => HTTP 400
2316 - request not completely sent in time => HTTP 408
2317 - forbidden request (matches a deny filter) => HTTP 403
2318 - internal error in haproxy => HTTP 500
2319 - the server returned an invalid or incomplete response => HTTP 502
2320 - no server was available to handle the request => HTTP 503
2321 - the server failed to reply in time => HTTP 504
willy tarreaueedaa9f2005-12-17 14:08:03 +01002322
willy tarreau197e8ec2005-12-17 14:10:59 +01002323A succint error message taken from the RFC accompanies these return codes.
2324But depending on the clients knowledge, it may be better to return custom, user
Willy Tarreau3f49b302007-06-11 00:29:26 +02002325friendly, error pages. This is made possible in two ways, one involving a
2326redirection to a known server, and another one consisting in returning a local
2327file.
2328
23294.6.1) Relocation
2330-----------------
2331An error relocation is achieved using the 'errorloc' command :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002332
willy tarreau197e8ec2005-12-17 14:10:59 +01002333 errorloc <HTTP_code> <location>
willy tarreaueedaa9f2005-12-17 14:08:03 +01002334
willy tarreau197e8ec2005-12-17 14:10:59 +01002335Instead of generating an HTTP error <HTTP_code> among those above, the proxy
2336will return a temporary redirection code (HTTP 302) towards the address
2337specified in <location>. This address may be either relative to the site or
2338absolute. Since this request will be handled by the client's browser, it's
2339mandatory that the returned address be reachable from the outside.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002340
willy tarreau197e8ec2005-12-17 14:10:59 +01002341Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002342---------
2343 listen application 0.0.0.0:80
2344 errorloc 400 /badrequest.html
2345 errorloc 403 /forbidden.html
2346 errorloc 408 /toolong.html
willy tarreauc5f73ed2005-12-18 01:26:38 +01002347 errorloc 500 http://haproxy.domain.net/bugreport.html
willy tarreaueedaa9f2005-12-17 14:08:03 +01002348 errorloc 502 http://192.168.114.58/error50x.html
2349 errorloc 503 http://192.168.114.58/error50x.html
2350 errorloc 504 http://192.168.114.58/error50x.html
2351
willy tarreauc1f47532005-12-18 01:08:26 +01002352Note: RFC2616 says that a client must reuse the same method to fetch the
2353Location returned by a 302, which causes problems with the POST method.
2354The return code 303 was designed explicitly to force the client to fetch the
2355Location URL with the GET method, but there are some browsers pre-dating
2356HTTP/1.1 which don't support it. Anyway, most browsers still behave with 302 as
willy tarreauc5f73ed2005-12-18 01:26:38 +01002357if it was a 303. In order to allow the user to chose, versions 1.1.31 and 1.2.5
2358bring two new keywords to replace 'errorloc' : 'errorloc302' and 'errorloc303'.
willy tarreauc1f47532005-12-18 01:08:26 +01002359
2360They are preffered over errorloc (which still does 302). Consider using
2361errorloc303 everytime you know that your clients support HTTP 303 responses..
2362
Willy Tarreau3f49b302007-06-11 00:29:26 +020023634.6.2) Local files
2364------------------
2365Sometimes, it is desirable to change the returned error without resorting to
2366redirections. The second method consists in loading local files during startup
2367and send them as pure HTTP content upon error. This is what the 'errorfile'
2368keyword does.
2369
2370Warning, there are traps to consider :
2371 - The files are loaded while parsing configuration, before doing a chroot().
2372 Thus, they are relative to the real filesystem. For this reason, it is
2373 recommended to pass an absolute path to those files.
2374
2375 - The contents of those files is not HTML, but real HTTP protocol with
2376 possible HTML body. So the first line and headers are mandatory. Ideally,
2377 every line in the HTTP part should end with CR-LF for maximum compatibility.
2378
2379 - The response is limited to the buffer size (BUSIZE), generally 8 or 16 kB.
2380
2381 - The response should not include references to the local server, in order to
2382 avoid infinite loops on the browser in case of local failure.
2383
2384Example :
2385---------
2386 errorfile 400 /etc/haproxy/errorfiles/400badreq.http
2387 errorfile 403 /etc/haproxy/errorfiles/403forbid.http
2388 errorfile 503 /etc/haproxy/errorfiles/503sorry.http
2389
willy tarreauc1f47532005-12-18 01:08:26 +01002390
willy tarreau982249e2005-12-18 00:57:06 +010023914.7) Modifying default values
willy tarreau197e8ec2005-12-17 14:10:59 +01002392-----------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01002393Version 1.1.22 introduced the notion of default values, which eliminates the
2394pain of often repeating common parameters between many instances, such as
2395logs, timeouts, modes, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01002396
willy tarreau197e8ec2005-12-17 14:10:59 +01002397Default values are set in a 'defaults' section. Each of these section clears
2398all previously set default parameters, so there may be as many default
2399parameters as needed. Only the last one before a 'listen' section will be
2400used for this section. The 'defaults' section uses the same syntax as the
2401'listen' section, for the supported parameters. The 'defaults' keyword ignores
2402everything on its command line, so that fake instance names can be specified
2403there for better clarity.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002404
willy tarreau982249e2005-12-18 00:57:06 +01002405In version 1.1.28/1.2.1, only those parameters can be preset in the 'default'
willy tarreau197e8ec2005-12-17 14:10:59 +01002406section :
2407 - log (the first and second one)
willy tarreaueedaa9f2005-12-17 14:08:03 +01002408 - mode { tcp, http, health }
2409 - balance { roundrobin }
willy tarreau197e8ec2005-12-17 14:10:59 +01002410 - disabled (to disable every further instances)
2411 - enabled (to enable every further instances, this is the default)
willy tarreaueedaa9f2005-12-17 14:08:03 +01002412 - contimeout, clitimeout, srvtimeout, grace, retries, maxconn
willy tarreau982249e2005-12-18 00:57:06 +01002413 - option { redispatch, transparent, keepalive, forwardfor, logasap, httpclose,
2414 checkcache, httplog, tcplog, dontlognull, persist, httpchk }
willy tarreaueedaa9f2005-12-17 14:08:03 +01002415 - redispatch, redisp, transparent, source { addr:port }
2416 - cookie, capture
2417 - errorloc
2418
willy tarreau197e8ec2005-12-17 14:10:59 +01002419As of 1.1.24, it is not possible to put certain parameters in a 'defaults'
2420section, mainly regular expressions and server configurations :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002421 - dispatch, server,
willy tarreau197e8ec2005-12-17 14:10:59 +01002422 - req*, rsp*
willy tarreaueedaa9f2005-12-17 14:08:03 +01002423
willy tarreau197e8ec2005-12-17 14:10:59 +01002424Last, there's no way yet to change a boolean option from its assigned default
2425value. So if an 'option' statement is set in a 'defaults' section, the only
2426way to flush it is to redefine a new 'defaults' section without this 'option'.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002427
willy tarreau197e8ec2005-12-17 14:10:59 +01002428Examples :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002429----------
2430 defaults applications TCP
willy tarreauc5f73ed2005-12-18 01:26:38 +01002431 log global
2432 mode tcp
2433 balance roundrobin
2434 clitimeout 180000
2435 srvtimeout 180000
2436 contimeout 4000
2437 retries 3
2438 redispatch
willy tarreaueedaa9f2005-12-17 14:08:03 +01002439
2440 listen app_tcp1 10.0.0.1:6000-6063
willy tarreauc5f73ed2005-12-18 01:26:38 +01002441 server srv1 192.168.1.1 check port 6000 inter 10000
2442 server srv2 192.168.1.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01002443
2444 listen app_tcp2 10.0.0.2:6000-6063
willy tarreauc5f73ed2005-12-18 01:26:38 +01002445 server srv1 192.168.2.1 check port 6000 inter 10000
2446 server srv2 192.168.2.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01002447
2448 defaults applications HTTP
willy tarreauc5f73ed2005-12-18 01:26:38 +01002449 log global
2450 mode http
2451 option httplog
2452 option forwardfor
2453 option dontlognull
2454 balance roundrobin
2455 clitimeout 20000
2456 srvtimeout 20000
2457 contimeout 4000
2458 retries 3
willy tarreaueedaa9f2005-12-17 14:08:03 +01002459
2460 listen app_http1 10.0.0.1:80-81
willy tarreauc5f73ed2005-12-18 01:26:38 +01002461 cookie SERVERID postonly insert indirect
2462 capture cookie userid= len 10
2463 server srv1 192.168.1.1:+8000 cookie srv1 check port 8080 inter 1000
2464 server srv1 192.168.1.2:+8000 cookie srv2 check port 8080 inter 1000
willy tarreaueedaa9f2005-12-17 14:08:03 +01002465
2466 defaults
willy tarreauc5f73ed2005-12-18 01:26:38 +01002467 # this empty section voids all default parameters
willy tarreaueedaa9f2005-12-17 14:08:03 +01002468
willy tarreau481132e2006-05-21 21:43:10 +02002469
24704.8) Status report in HTML page
2471-------------------------------
2472Starting with 1.2.14, it is possible for HAProxy to intercept requests for a
2473particular URI and return a full report of the proxy's activity and servers
2474statistics. This is available through the 'stats' keyword, associated to any
2475such options :
2476
2477 - stats enable
2478 - stats uri <uri prefix>
2479 - stats realm <authentication realm>
2480 - stats auth <user:password>
2481 - stats scope <proxy_id> | '.'
2482
2483By default, the status report is disabled. Specifying any combination above
2484enables it for the proxy instance referencing it. The easiest solution is to
2485use "stats enable" which will enable the report with default parameters :
2486
2487 - default URI : "/haproxy?stats" (CONFIG_STATS_DEFAULT_URI)
2488 - default auth : unspecified (no authentication)
2489 - default realm : "HAProxy Statistics" (CONFIG_STATS_DEFAULT_REALM)
2490 - default scope : unspecified (access to all instances)
2491
2492The "stats uri <uri_prefix>" option allows one to intercept another URI prefix.
2493Note that any URI that BEGINS with this string will match. For instance, one
2494proxy instance might be dedicated to status page only and would reply to any
2495URI.
2496
2497Example :
2498---------
2499 # catches any URI and returns the status page.
2500 listen stats :8080
2501 mode http
2502 stats uri /
2503
2504The "stats auth <user:password>" option enables Basic authentication and adds a
2505valid user:password combination to the list of authorized accounts. The user
2506and password are passed in the configuration file as clear text, and since this
2507is HTTP Basic authentication, you should be aware that it transits as clear
2508text on the network, so you must not use any sensible account. The list is
2509unlimited in order to provide easy accesses to developpers or customers.
2510
2511The "stats realm <realm>" option defines the "realm" name which is displayed
2512in the popup box when the browser asks for a password. It's important to ensure
2513that this one is not used by the application, otherwise the browser will try to
2514use a cached one from the application. Note that any space in the realm name
2515should be escaped with a backslash ('\').
2516
2517The "stats scope <proxy_id>" option limits the scope of the status report. By
2518default, all proxy instances are listed. But under some circumstances, it would
2519be better to limit the listing to some proxies or only to the current one. This
2520is what this option does. The special proxy name "." (a single dot) references
2521the current proxy. The proxy name can be repeated multiple times, even for
2522proxies defined later in the configuration or some which do not exist. The name
2523is the one which appears after the 'listen' keyword.
2524
2525Example :
2526---------
2527 # simple application with authenticated embedded status report
2528 listen app1 192.168.1.100:80
2529 mode http
willy tarreaud4ba08d2006-05-21 21:54:14 +02002530 option httpclose
willy tarreau481132e2006-05-21 21:43:10 +02002531 balance roundrobin
2532 cookie SERVERID postonly insert indirect
2533 server srv1 192.168.1.1:8080 cookie srv1 check inter 1000
2534 server srv1 192.168.1.2:8080 cookie srv2 check inter 1000
2535 stats uri /my_stats
willy tarreaud4ba08d2006-05-21 21:54:14 +02002536 stats realm Statistics\ for\ MyApp1-2
2537 stats auth guest:guest
2538 stats auth admin:AdMiN123
2539 stats scope .
2540 stats scope app2
willy tarreau481132e2006-05-21 21:43:10 +02002541
2542 # simple application with anonymous embedded status report
2543 listen app2 192.168.2.100:80
2544 mode http
willy tarreaud4ba08d2006-05-21 21:54:14 +02002545 option httpclose
willy tarreau481132e2006-05-21 21:43:10 +02002546 balance roundrobin
2547 cookie SERVERID postonly insert indirect
2548 server srv1 192.168.2.1:8080 cookie srv1 check inter 1000
2549 server srv1 192.168.2.2:8080 cookie srv2 check inter 1000
2550 stats uri /my_stats
willy tarreaud4ba08d2006-05-21 21:54:14 +02002551 stats realm Statistics\ for\ MyApp2
2552 stats scope .
willy tarreau481132e2006-05-21 21:43:10 +02002553
2554 listen admin_page :8080
2555 mode http
2556 stats uri /my_stats
willy tarreaud4ba08d2006-05-21 21:54:14 +02002557 stats realm Global\ statistics
2558 stats auth admin:AdMiN123
willy tarreau481132e2006-05-21 21:43:10 +02002559
2560Notes :
2561-------
2562 - The 'stats' options can also be specified in the 'defaults' section, in
2563 which case it will provide the exact same configuration to all further
2564 instances (hence the usefulness of the scope "."). However, if an instance
2565 redefines any 'stats' parameter, defaults will not be used for this
2566 instance.
2567
2568 - HTTP Basic authentication is very basic and unsecure from snooping. No
2569 sensible password should be used, and be aware that there is no way to
2570 remove it from the browser so it will be sent to the whole application
2571 upon further accesses.
2572
willy tarreaud4ba08d2006-05-21 21:54:14 +02002573 - It is very important that the 'option httpclose' is specified, otherwise
2574 the proxy will not be able to detect the URI within keep-alive sessions
2575 maintained between the browser and the servers, so the stats URI will be
2576 forwarded unmodified to the server as if the option was not set.
2577
willy tarreau481132e2006-05-21 21:43:10 +02002578
Willy Tarreau726c2bf2007-05-09 01:31:45 +020025795) Access lists
2580===============
2581
2582With version 1.3.10, a new concept of access lists (acl) was born. As it was
2583not necesary to reinvent the wheel, and because even long thoughts lead to
2584unsatisfying proposals, it was finally decided that something close to what
2585Squid provides would be a good compromise between features and ease of use.
2586
2587The principle is very simple : acls are declared with a name, a test and a list
2588of valid values to check against during the test. Conditions are applied on
2589various actions, and those conditions apply a logical AND between acls. The
2590condition is then only met if all acls are true.
2591
2592It is possible to use the reserved keyword "OR" in conditions, and it is
2593possible for an acl to be specified multiple times, even with various tests, in
2594which case the first one which returns true validates the ACL.
2595
Willy Tarreauae8b7962007-06-09 23:10:04 +02002596As of 1.3.12, only the following tests have been implemented :
Willy Tarreau726c2bf2007-05-09 01:31:45 +02002597
2598 Layer 3/4 :
2599 src <ipv4_address>[/mask] ... : match IPv4 source address
2600 dst <ipv4_address>[/mask] ... : match IPv4 destination address
Willy Tarreauae8b7962007-06-09 23:10:04 +02002601 src_port <range> ... : match source port range
2602 dst_port <range> ... : match destination port range
2603 dst_conn <range> ... : match #connections on frontend
Willy Tarreau726c2bf2007-05-09 01:31:45 +02002604
2605 Layer 7 :
2606 method <HTTP method> ... : match HTTP method
2607 req_ver <1.0|1.1> ... : match HTTP request version
2608 resp_ver <1.0|1.1> ... : match HTTP response version
Willy Tarreauae8b7962007-06-09 23:10:04 +02002609 status <range> ... : match HTTP response status code in range
Willy Tarreau726c2bf2007-05-09 01:31:45 +02002610 url <string> ... : exact string match on URI
2611 url_reg <regex> ... : regex string match on URI
2612 url_beg <string> ... : true if URI begins with <string>
2613 url_end <string> ... : true if URI ends with <string>
2614 url_sub <string> ... : true if URI contains <string>
2615 url_dir <string> ... : true if URI contains <string> between slashes
2616 url_dom <string> ... : true if URI contains <string> between slashes or dots
2617
Willy Tarreauae8b7962007-06-09 23:10:04 +02002618A 'range' is one or two integers which may be prefixed by an operator.
2619The syntax is :
2620
2621 [<op>] <low>[:<high>]
2622
2623Where <op> can be :
2624 'eq' : the tested value must be equal to <low> or within <low>..<high>
2625 'le' : the tested value must be lower than or equal to <low>
2626 'lt' : the tested value must be lower than <low>
2627 'ge' : the tested value must be greater than or equal to <low>
2628 'gt' : the tested value must be greater than <low>
2629
2630When no operator is defined, 'eq' is assumed. Note that when the operator is
2631specified, it applies to all subsequent ranges of values until the end of the
2632line is reached or another operator is specified. Example :
2633
2634 acl status_error status 400:599
2635 acl saturated_frt dst_conn ge 1000
2636 acl invalid_ports src_port lt 512 ge 65535
2637
Willy Tarreau726c2bf2007-05-09 01:31:45 +02002638Other ones are coming (headers, cookies, time, auth), it's just a matter of
2639time. It is also planned to be able to read the patterns from a file, as well
2640as to ignore the case for some of them.
2641
2642The only command supporting a condition right now is the "block" command, which
2643blocks a request and returns a 403 if its condition is true (with the "if"
2644keyword), or if it is false (with the "unless" keyword).
2645
2646Example :
2647---------
2648
2649 acl options_uris url *
2650 acl meth_option method OPTIONS
2651 acl http_1.1 req_ver 1.1
2652 acl allowed_meth method GET HEAD POST OPTIONS CONNECT
2653 acl connect_meth method CONNECT
2654 acl proxy_url url_beg http://
2655
2656 # block if reserved URI "*" used with a method other than "OPTIONS"
2657 block if options_uris !meth_option
2658
2659 # block if the OPTIONS method is used with HTTP 1.0
2660 block if meth_option !http_1.1
2661
2662 # allow non-proxy url with anything but the CONNECT method
2663 block if !connect_meth !proxy_url
2664
2665 # block all unknown methods
2666 block unless allowed_meth
2667
2668Note: this documentation is very light but should permit one to start and above
2669all it should permit to work on the project without being slowed down too much
2670with the doc.
2671
2672
willy tarreau197e8ec2005-12-17 14:10:59 +01002673=========================
2674| System-specific setup |
2675=========================
willy tarreaueedaa9f2005-12-17 14:08:03 +01002676
willy tarreau197e8ec2005-12-17 14:10:59 +01002677Linux 2.4
2678=========
willy tarreaueedaa9f2005-12-17 14:08:03 +01002679
2680-- cut here --
2681#!/bin/sh
2682# set this to about 256/4M (16384 for 256M machine)
2683MAXFILES=16384
2684echo $MAXFILES > /proc/sys/fs/file-max
2685ulimit -n $MAXFILES
2686
2687if [ -e /proc/sys/net/ipv4/ip_conntrack_max ]; then
willy tarreauc5f73ed2005-12-18 01:26:38 +01002688 echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max
willy tarreaueedaa9f2005-12-17 14:08:03 +01002689fi
2690
2691if [ -e /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait ]; then
willy tarreauc5f73ed2005-12-18 01:26:38 +01002692 # 30 seconds for fin, 15 for time wait
2693 echo 3000 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait
2694 echo 1500 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_time_wait
2695 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_invalid_scale
2696 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_out_of_window
willy tarreaueedaa9f2005-12-17 14:08:03 +01002697fi
2698
2699echo 1024 60999 > /proc/sys/net/ipv4/ip_local_port_range
2700echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
2701echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog
2702echo 262144 > /proc/sys/net/ipv4/tcp_max_tw_buckets
2703echo 262144 > /proc/sys/net/ipv4/tcp_max_orphans
2704echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time
2705echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
2706echo 0 > /proc/sys/net/ipv4/tcp_timestamps
2707echo 0 > /proc/sys/net/ipv4/tcp_ecn
willy tarreauc5f73ed2005-12-18 01:26:38 +01002708echo 1 > /proc/sys/net/ipv4/tcp_sack
willy tarreaueedaa9f2005-12-17 14:08:03 +01002709echo 0 > /proc/sys/net/ipv4/tcp_dsack
2710
2711# auto-tuned on 2.4
2712#echo 262143 > /proc/sys/net/core/rmem_max
2713#echo 262143 > /proc/sys/net/core/rmem_default
2714
2715echo 16384 65536 524288 > /proc/sys/net/ipv4/tcp_rmem
2716echo 16384 349520 699040 > /proc/sys/net/ipv4/tcp_wmem
2717
2718-- cut here --
2719
willy tarreau197e8ec2005-12-17 14:10:59 +01002720
2721FreeBSD
2722=======
2723
2724A FreeBSD port of HA-Proxy is now available and maintained, thanks to
2725Clement Laforet <sheepkiller@cultdeadsheep.org>.
2726
2727For more information :
2728http://www.freebsd.org/cgi/url.cgi?ports/net/haproxy/pkg-descr
2729http://www.freebsd.org/cgi/cvsweb.cgi/ports/net/haproxy/
2730http://www.freshports.org/net/haproxy
2731
2732
2733-- end --