blob: b616360849378bbeae2ad52ec7f1dc34934bbc80 [file] [log] [blame]
willy tarreau0174f312005-12-18 01:02:42 +01001 -------------------
2 H A - P r o x y
3 Reference Manual
4 -------------------
willy tarreau532bb552006-05-13 18:40:37 +02005 version 1.2.13
willy tarreauc5f73ed2005-12-18 01:26:38 +01006 willy tarreau
willy tarreau532bb552006-05-13 18:40:37 +02007 2006/05/13
willy tarreaueedaa9f2005-12-17 14:08:03 +01008
9============
10| Abstract |
11============
12
13HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high
14availability 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 tarreaueedaa9f2005-12-17 14:08:03 +010025
26It needs very little resource. Its event-driven architecture allows it to easily
27handle thousands of simultaneous connections on hundreds of instances without
28risking the system's stability.
29
30====================
31| Start parameters |
32====================
33
34There are only a few command line options :
35
36 -f <configuration file>
37 -n <high limit for the total number of simultaneous connections>
willy tarreau532bb552006-05-13 18:40:37 +020038 = 'maxconn' in 'global' section
39 -N <high limit for the per-listener number of simultaneous connections>
40 = 'maxconn' in 'listen' or 'default' sections
willy tarreaueedaa9f2005-12-17 14:08:03 +010041 -d starts in foregreound with debugging mode enabled
42 -D starts in daemon mode
willy tarreau982249e2005-12-18 00:57:06 +010043 -q disable messages on output
44 -V displays messages on output even when -q or 'quiet' are specified.
45 -c only checks config file and exits with code 0 if no error was found, or
46 exits with code 1 if a syntax error was found.
willy tarreaufe2c5c12005-12-17 14:14:34 +010047 -p <pidfile> asks the process to write down each of its children's
48 pids to this file in daemon mode.
willy tarreau34f45302006-04-15 21:37:14 +020049 -sf specifies a list of pids to send a FINISH signal to after startup.
50 -st specifies a list of pids to send a TERMINATE signal to after startup.
willy tarreaueedaa9f2005-12-17 14:08:03 +010051 -s shows statistics (only if compiled in)
52 -l shows even more statistics (implies '-s')
willy tarreau64a3cc32005-12-18 01:13:11 +010053 -de disables use of epoll()
54 -dp disables use of poll()
willy tarreau34f45302006-04-15 21:37:14 +020055 -db disables background mode (stays in foreground, useful for debugging)
56 -m <megs> enforces a memory usage limit to a maximum of <megs> megabytes.
willy tarreaueedaa9f2005-12-17 14:08:03 +010057
willy tarreau532bb552006-05-13 18:40:37 +020058The maximal number of connections per proxy instance is used as the default
59parameter for each instance for which the 'maxconn' paramter is not set in the
60'listen' section.
willy tarreaueedaa9f2005-12-17 14:08:03 +010061
62The maximal number of total connections limits the number of connections used by
63the whole process if the 'maxconn' parameter is not set in the 'global' section.
64
65The debugging mode has the same effect as the 'debug' option in the 'global'
66section. When the proxy runs in this mode, it dumps every connections,
67disconnections, timestamps, and HTTP headers to stdout. This should NEVER
68be used in an init script since it will prevent the system from starting up.
69
willy tarreau34f45302006-04-15 21:37:14 +020070For debugging, the '-db' option is very useful as it temporarily disables
71daemon mode and multi-process mode. The service can then be stopped by simply
72pressing Ctrl-C, without having to edit the config nor run full debug.
73
willy tarreaueedaa9f2005-12-17 14:08:03 +010074Statistics are only available if compiled in with the 'STATTIME' option. It's
75only used during code optimization phases.
76
willy tarreau532bb552006-05-13 18:40:37 +020077The '-st' and '-sf' options are used for hot reconfiguration (see below).
willy tarreau34f45302006-04-15 21:37:14 +020078
willy tarreaueedaa9f2005-12-17 14:08:03 +010079======================
80| Configuration file |
81======================
82
83Structure
84=========
85
86The configuration file parser ignores empty lines, spaces, tabs. Anything
87between a sharp ('#') not following a backslash ('\'), and the end of a line
88constitutes a comment and is ignored too.
89
90The configuration file is segmented in sections. A section begins whenever
91one of these 3 keywords are encountered :
92
93 - 'global'
94 - 'listen'
95 - 'defaults'
96
97Every parameter refer to the section beginning at the last one of these 3
98keywords.
99
100
1011) Global parameters
102====================
103
104Global parameters affect the whole process behaviour. They are all set in the
105'global' section. There may be several 'global' sections if needed, but their
106parameters will only be merged. Allowed parameters in 'global' section include
107the following ones :
108
109 - log <address> <facility> [max_level]
110 - maxconn <number>
111 - uid <user id>
112 - gid <group id>
113 - chroot <directory>
114 - nbproc <number>
115 - daemon
116 - debug
willy tarreau64a3cc32005-12-18 01:13:11 +0100117 - noepoll
118 - nopoll
willy tarreaueedaa9f2005-12-17 14:08:03 +0100119 - quiet
willy tarreaufe2c5c12005-12-17 14:14:34 +0100120 - pidfile <file>
willy tarreauc5f73ed2005-12-18 01:26:38 +0100121 - ulimit-n <number>
willy tarreau598da412005-12-18 01:07:29 +0100122 - stats
willy tarreaueedaa9f2005-12-17 14:08:03 +0100123
willy tarreauc5f73ed2005-12-18 01:26:38 +0100124
willy tarreaueedaa9f2005-12-17 14:08:03 +01001251.1) Event logging
126------------------
127Most events are logged : start, stop, servers going up and down, connections and
128errors. Each event generates a syslog message which can be sent to up to 2
129servers. The syntax is :
130
131 log <ip_address> <facility> [max_level]
132
133Connections are logged at level "info". Services initialization and servers
134going up are logged at level "notice", termination signals are logged at
135"warning", and definitive service termination, as well as loss of servers are
136logged at level "alert". The optional parameter <max_level> specifies above
137what level messages should be sent. Level can take one of these 8 values :
138
139 emerg, alert, crit, err, warning, notice, info, debug
140
141For backwards compatibility with versions 1.1.16 and earlier, the default level
142value is "debug" if not specified.
143
144Permitted facilities are :
145 kern, user, mail, daemon, auth, syslog, lpr, news,
146 uucp, cron, auth2, ftp, ntp, audit, alert, cron2,
147 local0, local1, local2, local3, local4, local5, local6, local7
148
149According to RFC3164, messages are truncated to 1024 bytes before being emitted.
150
151Example :
152---------
153 global
willy tarreauc5f73ed2005-12-18 01:26:38 +0100154 log 192.168.2.200 local3
155 log 127.0.0.1 local4 notice
156
willy tarreaueedaa9f2005-12-17 14:08:03 +0100157
1581.2) limiting the number of connections
159---------------------------------------
160It is possible and recommended to limit the global number of per-process
willy tarreauc5f73ed2005-12-18 01:26:38 +0100161connections using the 'maxconn' global keyword. Since one connection includes
162both a client and a server, it means that the max number of TCP sessions will
163be about the double of this number. It's important to understand this when
164trying to find best values for 'ulimit -n' before starting the proxy. To
165anticipate the number of sockets needed, all these parameters must be counted :
willy tarreaueedaa9f2005-12-17 14:08:03 +0100166
167 - 1 socket per incoming connection
168 - 1 socket per outgoing connection
169 - 1 socket per address/port/proxy tuple.
170 - 1 socket per server being health-checked
171 - 1 socket for all logs
172
173In simple configurations where each proxy only listens one one address/port,
willy tarreauc5f73ed2005-12-18 01:26:38 +0100174set the limit of file descriptors (ulimit -n) to
175(2 * maxconn + nbproxies + nbservers + 1). Starting with versions 1.1.32/1.2.6,
176it is now possible to set the limit in the configuration using the 'ulimit-n'
177global keyword, provided the proxy is started as root. This puts an end to the
178recurrent problem of ensuring that the system limits are adapted to the proxy
179values. Note that these limits are per-process.
180
181Example :
182---------
183 global
184 maxconn 32000
185 ulimit-n 65536
186
willy tarreaueedaa9f2005-12-17 14:08:03 +0100187
1881.3) Drop of priviledges
189------------------------
190In order to reduce the risk and consequences of attacks, in the event where a
191yet non-identified vulnerability would be successfully exploited, it's possible
192to lower the process priviledges and even isolate it in a riskless directory.
193
194In the 'global' section, the 'uid' parameter sets a numerical user identifier
195which the process will switch to after binding its listening sockets. The value
196'0', which normally represents the super-user, here indicates that the UID must
197not change during startup. It's the default behaviour. The 'gid' parameter does
198the same for the group identifier. It's particularly advised against use of
199generic accounts such as 'nobody' because it has the same consequences as using
200'root' if other services use them.
201
202The 'chroot' parameter makes the process isolate itself in an empty directory
203just before switching its UID. This type of isolation (chroot) can sometimes
204be worked around on certain OS (Linux, Solaris), provided that the attacker
205has gained 'root' priviledges and has the ability to use or create a directory.
206For this reason, it's capital to use a dedicated directory and not to share one
207between several services of different nature. To make isolation more resistant,
208it's recommended to use an empty directory without any right, and to change the
209UID of the process so that it cannot do anything there.
210
211Note: in the event where such a vulnerability would be exploited, it's most
212likely that first attempts would kill the process due to 'Segmentation Fault',
213'Bus Error' or 'Illegal Instruction' signals. Eventhough it's true that
214isolating the server reduces the risks of intrusion, it's sometimes useful to
215find why a process dies, via the analysis of a 'core' file, although very rare
216(the last bug of this sort was fixed in 1.1.9). For security reasons, most
217systems disable the generation of core file when a process changes its UID. So
218the two workarounds are either to start the process from a restricted user
219account, which will not be able to chroot itself, or start it as root and not
220change the UID. In both cases the core will be either in the start or the chroot
221directories. Do not forget to allow core dumps prior to start the process :
222
223# ulimit -c unlimited
224
225Example :
226---------
227
228 global
willy tarreauc5f73ed2005-12-18 01:26:38 +0100229 uid 30000
230 gid 30000
231 chroot /var/chroot/haproxy
232
willy tarreaueedaa9f2005-12-17 14:08:03 +0100233
2341.4) Startup modes
235------------------
willy tarreau34f45302006-04-15 21:37:14 +0200236The service can start in several different modes :
willy tarreaueedaa9f2005-12-17 14:08:03 +0100237 - foreground / background
238 - quiet / normal / debug
239
240The default mode is normal, foreground, which means that the program doesn't
241return once started. NEVER EVER use this mode in a system startup script, or
242the system won't boot. It needs to be started in background, so that it
243returns immediately after forking. That's accomplished by the 'daemon' option
244in the 'global' section, which is the equivalent of the '-D' command line
245argument.
246
willy tarreau34f45302006-04-15 21:37:14 +0200247The '-db' command line argument overrides the 'daemon' and 'nbproc' global
248options to make the process run in normal, foreground mode.
249
willy tarreaueedaa9f2005-12-17 14:08:03 +0100250Moreover, certain alert messages are still sent to the standard output even
251in 'daemon' mode. To make them disappear, simply add the 'quiet' option in the
252'global' section. This option has no command-line equivalent.
253
254Last, the 'debug' mode, enabled with the 'debug' option in the 'global' section,
255and which is equivalent of the '-d' option, allows deep TCP/HTTP analysis, with
256timestamped display of each connection, disconnection, and HTTP headers for both
257ways. This mode is incompatible with 'daemon' and 'quiet' modes for obvious
258reasons.
259
willy tarreauc5f73ed2005-12-18 01:26:38 +0100260
willy tarreaueedaa9f2005-12-17 14:08:03 +01002611.5) Increasing the overall processing power
262--------------------------------------------
263On multi-processor systems, it may seem to be a shame to use only one processor,
willy tarreau982249e2005-12-18 00:57:06 +0100264eventhough the load needed to saturate a recent processor is far above common
willy tarreaueedaa9f2005-12-17 14:08:03 +0100265usage. Anyway, for very specific needs, the proxy can start several processes
266between which the operating system will spread the incoming connections. The
267number of processes is controlled by the 'nbproc' parameter in the 'global'
willy tarreau4302f492005-12-18 01:00:37 +0100268section. It defaults to 1, and obviously works only in 'daemon' mode. One
269typical usage of this parameter has been to workaround the default per-process
270file-descriptor limit that Solaris imposes to user processes.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100271
272Example :
273---------
274
275 global
willy tarreauc5f73ed2005-12-18 01:26:38 +0100276 daemon
277 quiet
278 nbproc 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100279
280
willy tarreaufe2c5c12005-12-17 14:14:34 +01002811.6) Helping process management
282-------------------------------
283Haproxy now supports the notion of pidfile. If the '-p' command line argument,
284or the 'pidfile' global option is followed with a file name, this file will be
285removed, then filled with all children's pids, one per line (only in daemon
286mode). This file is NOT within the chroot, which allows to work with a readonly
287 chroot. It will be owned by the user starting the process, and will have
288permissions 0644.
289
290Example :
291---------
292
293 global
294 daemon
295 quiet
willy tarreauc5f73ed2005-12-18 01:26:38 +0100296 nbproc 2
willy tarreaufe2c5c12005-12-17 14:14:34 +0100297 pidfile /var/run/haproxy-private.pid
298
299 # to stop only those processes among others :
300 # kill $(</var/run/haproxy-private.pid)
301
willy tarreau34f45302006-04-15 21:37:14 +0200302 # to reload a new configuration with minimal service impact and without
303 # breaking existing sessions :
304 # haproxy -f haproxy.cfg -p $(</var/run/haproxy-private.pid) -st $(</var/run/haproxy-private.pid)
willy tarreaufe2c5c12005-12-17 14:14:34 +0100305
willy tarreau64a3cc32005-12-18 01:13:11 +01003061.7) Polling mechanisms
307-----------------------
308Starting from version 1.2.5, haproxy supports the poll() and epoll() polling
309mechanisms. On systems where select() is limited by FD_SETSIZE (like Solaris),
310poll() can be an interesting alternative. Performance tests show that Solaris'
311poll() performance does not decay as fast as the numbers of sockets increase,
312making it a safe solution for high loads. However, Solaris already uses poll()
313to emulate select(), so as long as the number of sockets has no reason to go
314higher than FD_SETSIZE, poll() should not provide any better performance. On
315Linux systems with the epoll() patch (or any 2.6 version), haproxy will use
316epoll() which is extremely fast and non dependant on the number of sockets.
317Tests have shown constant performance from 1 to 20000 simultaneous sessions.
318
319Haproxy will use epoll() when available, and will fall back to poll(), then to
320select(). However, if for any reason you need to disable epoll() or poll() (eg.
321because of a bug or just to compare performance), two new global options have
322been created for this matter : 'noepoll' and 'nopoll'.
323
324Example :
325---------
326
327 global
328 # use only select()
329 noepoll
330 nopoll
331
332Note :
333------
334For the sake of configuration file portability, these options are accepted but
335ignored if the poll() or epoll() mechanisms have not been enabled at compile
336time.
337
338To make debugging easier, the '-de' runtime argument disables epoll support and
339the '-dp' argument disables poll support. They are respectively equivalent to
340'noepoll' and 'nopoll'.
341
342
willy tarreaueedaa9f2005-12-17 14:08:03 +01003432) Declaration of a listening service
344=====================================
345
346Service sections start with the 'listen' keyword :
347
348 listen <instance_name> [ <IP_address>:<port_range>[,...] ]
349
350- <instance_name> is the name of the instance. This name will be reported in
351 logs, so it is good to have it reflect the proxied service. No unicity test
352 is done on this name, and it's not mandatory for it to be unique, but highly
353 recommended.
354
355- <IP_address> is the IP address the proxy binds to. Empty address, '*' and
356 '0.0.0.0' all mean that the proxy listens to all valid addresses on the
357 system.
358
359- <port_range> is either a unique port, or a port range for which the proxy will
360 accept connections for the IP address specified above. This range can be :
361 - a numerical port (ex: '80')
362 - a dash-delimited ports range explicitly stating the lower and upper bounds
363 (ex: '2000-2100') which are included in the range.
364
365 Particular care must be taken against port ranges, because every <addr:port>
366 couple consumes one socket (=a file descriptor), so it's easy to eat lots of
367 descriptors with a simple range. The <addr:port> couple must be used only once
368 among all instances running on a same system. Please note that attaching to
369 ports lower than 1024 need particular priviledges to start the program, which
370 are independant of the 'uid' parameter.
371
372- the <IP_address>:<port_range> couple may be repeated indefinitely to require
373 the proxy to listen to other addresses and/or ports. To achieve this, simply
374 separate them with a coma.
375
376Examples :
377---------
378 listen http_proxy :80
379 listen x11_proxy 127.0.0.1:6000-6009
380 listen smtp_proxy 127.0.0.1:25,127.0.0.1:587
381 listen ldap_proxy :389,:663
382
383In the event that all addresses do not fit line width, it's preferable to
384detach secondary addresses on other lines with the 'bind' keyword. If this
385keyword is used, it's not even necessary to specify the first address on the
386'listen' line, which sometimes makes multiple configuration handling easier :
387
388 bind [ <IP_address>:<port_range>[,...] ]
389
390Examples :
391----------
392 listen http_proxy
393 bind :80,:443
willy tarreauc5f73ed2005-12-18 01:26:38 +0100394 bind 10.0.0.1:10080,10.0.0.1:10443
395
willy tarreaueedaa9f2005-12-17 14:08:03 +0100396
3972.1) Inhibiting a service
398-------------------------
399A service may be disabled for maintenance reasons, without needing to comment
400out the whole section, simply by specifying the 'disabled' keyword in the
401section to be disabled :
402
403 listen smtp_proxy 0.0.0.0:25
willy tarreauc5f73ed2005-12-18 01:26:38 +0100404 disabled
willy tarreaueedaa9f2005-12-17 14:08:03 +0100405
406Note: the 'enabled' keyword allows to enable a service which has been disabled
407 previously by a default configuration.
408
willy tarreauc5f73ed2005-12-18 01:26:38 +0100409
willy tarreaueedaa9f2005-12-17 14:08:03 +01004102.2) Modes of operation
411-----------------------
412A service can work in 3 different distinct modes :
413 - TCP
414 - HTTP
willy tarreau532bb552006-05-13 18:40:37 +0200415 - health
willy tarreaueedaa9f2005-12-17 14:08:03 +0100416
417TCP mode
418--------
419In this mode, the service relays TCP connections as soon as they're established,
420towards one or several servers. No processing is done on the stream. It's only
421an association of source(addr:port) -> destination(addr:port). To use this mode,
422you must specify 'mode tcp' in the 'listen' section. This is the default mode.
423
424Example :
425---------
426 listen smtp_proxy 0.0.0.0:25
willy tarreauc5f73ed2005-12-18 01:26:38 +0100427 mode tcp
willy tarreaueedaa9f2005-12-17 14:08:03 +0100428
429HTTP mode
430---------
431In this mode, the service relays TCP connections towards one or several servers,
432when it has enough informations to decide, which normally means that all HTTP
433headers have been read. Some of them may be scanned for a cookie or a pattern
434matching a regex. To use this mode, specify 'mode http' in the 'listen' section.
435
436Example :
437---------
438 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100439 mode http
willy tarreaueedaa9f2005-12-17 14:08:03 +0100440
441Health-checking mode
442--------------------
443This mode provides a way for external components to check the proxy's health.
444It is meant to be used with intelligent load-balancers which can use send/expect
445scripts to check for all of their servers' availability. This one simply accepts
willy tarreau197e8ec2005-12-17 14:10:59 +0100446the connection, returns the word 'OK' and closes it. If the 'option httpchk' is
447set, then the reply will be 'HTTP/1.0 200 OK' with no data, so that it can be
448tested from a tool which supports HTTP health-checks. To enable it, simply
willy tarreaueedaa9f2005-12-17 14:08:03 +0100449specify 'health' as the working mode :
450
451Example :
452---------
willy tarreau197e8ec2005-12-17 14:10:59 +0100453 # simple response : 'OK'
willy tarreaueedaa9f2005-12-17 14:08:03 +0100454 listen health_check 0.0.0.0:60000
willy tarreauc5f73ed2005-12-18 01:26:38 +0100455 mode health
willy tarreaueedaa9f2005-12-17 14:08:03 +0100456
willy tarreau197e8ec2005-12-17 14:10:59 +0100457 # HTTP response : 'HTTP/1.0 200 OK'
458 listen http_health_check 0.0.0.0:60001
willy tarreauc5f73ed2005-12-18 01:26:38 +0100459 mode health
460 option httpchk
461
willy tarreau532bb552006-05-13 18:40:37 +02004622.2.1 Monitoring
463----------------
willy tarreauc5f73ed2005-12-18 01:26:38 +0100464Versions 1.1.32 and 1.2.6 provide a new solution to check the proxy's
465availability without perturbating the service. The 'monitor-net' keyword was
466created to specify a network of equipments which CANNOT use the service for
467anything but health-checks. This is particularly suited to TCP proxies, because
468it prevents the proxy from relaying the monitor's connection to the remote
469server.
470
471When used with TCP, the connection is accepted then closed and nothing is
472logged. This is enough for a front-end load-balancer to detect the service as
473available.
willy tarreau197e8ec2005-12-17 14:10:59 +0100474
willy tarreauc5f73ed2005-12-18 01:26:38 +0100475When used with HTTP, the connection is accepted, nothing is logged, the
476following response is sent, then the session is closed : "HTTP/1.0 200 OK".
477This is normally enough for any front-end HTTP load-balancer to detect the
478service as available too, both with TCP and HTTP checks.
479
480Proxies using the "monitor-net" keyword can remove the "option dontlognull", as
481it will make them log empty connections from hosts outside the monitoring
482network.
483
484Example :
485---------
486
487 listen tse-proxy
488 bind :3389,:1494,:5900 # TSE, ICA and VNC at once.
489 mode tcp
490 balance roundrobin
491 server tse-farm 192.168.1.10
492 monitor-net 192.168.1.252/31 # L4 load-balancers on .252 and .253
493
willy tarreaueedaa9f2005-12-17 14:08:03 +0100494
4952.3) Limiting the number of simultaneous connections
496----------------------------------------------------
497The 'maxconn' parameter allows a proxy to refuse connections above a certain
498amount of simultaneous ones. When the limit is reached, it simply stops
499listening, but the system may still be accepting them because of the back log
willy tarreau982249e2005-12-18 00:57:06 +0100500queue. These connections will be processed later when other ones have freed
willy tarreaueedaa9f2005-12-17 14:08:03 +0100501some slots. This provides a serialization effect which helps very fragile
willy tarreau34f45302006-04-15 21:37:14 +0200502servers resist to high loads. See further for system limitations.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100503
504Example :
505---------
506 listen tiny_server 0.0.0.0:80
507 maxconn 10
508
509
5102.4) Soft stop
511--------------
512It is possible to stop services without breaking existing connections by the
willy tarreau22739ef2006-01-20 20:43:32 +0100513sending of the SIGUSR1 signal to the process. All services are then put into
willy tarreaueedaa9f2005-12-17 14:08:03 +0100514soft-stop state, which means that they will refuse to accept new connections,
515except for those which have a non-zero value in the 'grace' parameter, in which
516case they will still accept connections for the specified amount of time, in
willy tarreau22739ef2006-01-20 20:43:32 +0100517milliseconds. This makes it possible to tell a load-balancer that the service
518is failing, while still doing the job during the time it needs to detect it.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100519
520Note: active connections are never killed. In the worst case, the user will have
521to wait for all of them to close or to time-out, or simply kill the process
willy tarreau22739ef2006-01-20 20:43:32 +0100522normally (SIGTERM). The default 'grace' value is '0'.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100523
524Example :
525---------
526 # enter soft stop after 'killall -USR1 haproxy'
527 # the service will still run 10 seconds after the signal
528 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100529 mode http
530 grace 10000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100531
532 # this port is dedicated to a load-balancer, and must fail immediately
533 listen health_check 0.0.0.0:60000
willy tarreauc5f73ed2005-12-18 01:26:38 +0100534 mode health
535 grace 0
willy tarreaueedaa9f2005-12-17 14:08:03 +0100536
537
willy tarreau39df2dc2006-01-29 21:56:05 +0100538As of version 1.2.8, a new soft-reconfiguration mechanism has been introduced.
willy tarreau22739ef2006-01-20 20:43:32 +0100539It is now possible to "pause" all the proxies by sending a SIGTTOU signal to
540the processes. This will disable the listening socket without breaking existing
541connections. After that, sending a SIGTTIN signal to those processes enables
542the listening sockets again. This is very useful to try to load a new
543configuration or even a new version of haproxy without breaking existing
544connections. If the load succeeds, then simply send a SIGUSR1 which will make
545the previous proxies exit immediately once their sessions are closed ; and if
546the load fails, then simply send a SIGTTIN to restore the service immediately.
547Please note that the 'grace' parameter is ignored for SIGTTOU, as well as for
548SIGUSR1 when the process was in the pause mode. Please also note that it would
549be useful to save the pidfile before starting a new instance.
550
willy tarreau34f45302006-04-15 21:37:14 +0200551This mechanism fully exploited since 1.2.11 with the '-st' and '-sf' options
willy tarreau532bb552006-05-13 18:40:37 +0200552(see below).
553
5542.4.1) Hot reconfiguration
555--------------------------
556The '-st' and '-sf' command line options are used to inform previously running
557processes that a configuration is being reloaded. They will receive the SIGTTOU
558signal to ask them to temporarily stop listening to the ports so that the new
559process can grab them. If anything wrong happens, the new process will send
560them a SIGTTIN to tell them to re-listen to the ports and continue their normal
561work. Otherwise, it will either ask them to finish (-sf) their work then softly
562exit, or immediately terminate (-st), breaking existing sessions. A typical use
563of this allows a configuration reload without service interruption :
564
565 # haproxy -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)
566
willy tarreau22739ef2006-01-20 20:43:32 +0100567
willy tarreaueedaa9f2005-12-17 14:08:03 +01005682.5) Connections expiration time
569--------------------------------
570It is possible (and recommended) to configure several time-outs on TCP
571connections. Three independant timers are adjustable with values specified
572in milliseconds. A session will be terminated if either one of these timers
573expire.
574
575 - the time we accept to wait for data from the client, or for the client to
576 accept data : 'clitimeout' :
577
willy tarreauc5f73ed2005-12-18 01:26:38 +0100578 # client time-out set to 2mn30.
579 clitimeout 150000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100580
581 - the time we accept to wait for data from the server, or for the server to
582 accept data : 'srvtimeout' :
583
willy tarreauc5f73ed2005-12-18 01:26:38 +0100584 # server time-out set to 30s.
585 srvtimeout 30000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100586
587 - the time we accept to wait for a connection to establish on a server :
588 'contimeout' :
589
590 # we give up if the connection does not complete within 4 seconds
willy tarreauc5f73ed2005-12-18 01:26:38 +0100591 contimeout 4000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100592
593Notes :
594-------
595 - 'contimeout' and 'srvtimeout' have no sense on 'health' mode servers ;
596 - under high loads, or with a saturated or defective network, it's possible
597 that some packets get lost. Since the first TCP retransmit only happens
598 after 3 seconds, a time-out equal to, or lower than 3 seconds cannot
599 compensate for a packet loss. A 4 seconds time-out seems a reasonable
600 minimum which will considerably reduce connection failures.
601
willy tarreauc5f73ed2005-12-18 01:26:38 +0100602
willy tarreaueedaa9f2005-12-17 14:08:03 +01006032.6) Attempts to reconnect
604--------------------------
605After a connection failure to a server, it is possible to retry, potentially
606on another server. This is useful if health-checks are too rare and you don't
607want the clients to see the failures. The number of attempts to reconnect is
608set by the 'retries' paramter.
609
610Example :
611---------
willy tarreauc5f73ed2005-12-18 01:26:38 +0100612 # we can retry 3 times max after a failure
613 retries 3
willy tarreaueedaa9f2005-12-17 14:08:03 +0100614
willy tarreau34f45302006-04-15 21:37:14 +0200615Please note that the reconnection attempt may lead to getting the connection
616sent to a new server if the original one died between connection attempts.
617
willy tarreaueedaa9f2005-12-17 14:08:03 +0100618
6192.7) Address of the dispatch server (deprecated)
620------------------------------------------------
621The server which will be sent all new connections is defined by the 'dispatch'
622parameter, in the form <address>:<port>. It generally is dedicated to unknown
623connections and will assign them a cookie, in case of HTTP persistence mode,
624or simply is a single server in case of generic TCP proxy. This old mode is only
625provided for backwards compatibility, but doesn't allow to check remote servers
626state, and has a rather limited usage. All new setups should switch to 'balance'
627mode. The principle of the dispatcher is to be able to perform the load
628balancing itself, but work only on new clients so that the server doesn't need
629to be a big machine.
630
631Example :
632---------
willy tarreauc5f73ed2005-12-18 01:26:38 +0100633 # all new connections go there
634 dispatch 192.168.1.2:80
willy tarreaueedaa9f2005-12-17 14:08:03 +0100635
636Note :
637------
638This parameter has no sense for 'health' servers, and is incompatible with
639'balance' mode.
640
641
6422.8) Outgoing source address
643----------------------------
644It is often necessary to bind to a particular address when connecting to some
645remote hosts. This is done via the 'source' parameter which is a per-proxy
646parameter. A newer version may allow to fix different sources to reach different
647servers. The syntax is 'source <address>[:<port>]', where <address> is a valid
648local address (or '0.0.0.0' or '*' or empty to let the system choose), and
649<port> is an optional parameter allowing the user to force the source port for
650very specific needs. If the port is not specified or is '0', the system will
651choose a free port. Note that as of version 1.1.18, the servers health checks
652are also performed from the same source.
653
654Examples :
655----------
656 listen http_proxy *:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100657 # all connections take 192.168.1.200 as source address
658 source 192.168.1.200:0
willy tarreaueedaa9f2005-12-17 14:08:03 +0100659
660 listen rlogin_proxy *:513
willy tarreauc5f73ed2005-12-18 01:26:38 +0100661 # use address 192.168.1.200 and the reserved port 900 (needs to be root)
662 source 192.168.1.200:900
willy tarreaueedaa9f2005-12-17 14:08:03 +0100663
664
6652.9) Setting the cookie name
666----------------------------
667In HTTP mode, it is possible to look for a particular cookie which will contain
668a server identifier which should handle the connection. The cookie name is set
669via the 'cookie' parameter.
670
671Example :
672---------
673 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100674 mode http
675 cookie SERVERID
willy tarreaueedaa9f2005-12-17 14:08:03 +0100676
677It is possible to change the cookie behaviour to get a smarter persistence,
678depending on applications. It is notably possible to delete or modify a cookie
679emitted by a server, insert a cookie identifying the server in an HTTP response
680and even add a header to tell upstream caches not to cache this response.
681
682Examples :
683----------
684
685To remove the cookie for direct accesses (ie when the server matches the one
686which was specified in the client cookie) :
687
willy tarreauc5f73ed2005-12-18 01:26:38 +0100688 cookie SERVERID indirect
willy tarreaueedaa9f2005-12-17 14:08:03 +0100689
690To replace the cookie value with the one assigned to the server if any (no
691cookie will be created if the server does not provide one, nor if the
692configuration does not provide one). This lets the application put the cookie
693exactly on certain pages (eg: successful authentication) :
694
willy tarreauc5f73ed2005-12-18 01:26:38 +0100695 cookie SERVERID rewrite
willy tarreaueedaa9f2005-12-17 14:08:03 +0100696
697To create a new cookie and assign the server identifier to it (in this case, all
698servers should be associated with a valid cookie, since no cookie will simply
699delete the cookie from the client's browser) :
700
willy tarreauc5f73ed2005-12-18 01:26:38 +0100701 cookie SERVERID insert
willy tarreaueedaa9f2005-12-17 14:08:03 +0100702
willy tarreau0174f312005-12-18 01:02:42 +0100703To reuse an existing application cookie and prefix it with the server's
704identifier, and remove it in the request, use the 'prefix' option. This allows
705to insert a haproxy in front of an application without risking to break clients
706which does not support more than one cookie :
707
willy tarreauc5f73ed2005-12-18 01:26:38 +0100708 cookie JSESSIONID prefix
willy tarreau0174f312005-12-18 01:02:42 +0100709
willy tarreaueedaa9f2005-12-17 14:08:03 +0100710To insert a cookie and ensure that no upstream cache will store it, add the
711'nocache' option :
712
willy tarreauc5f73ed2005-12-18 01:26:38 +0100713 cookie SERVERID insert nocache
willy tarreaueedaa9f2005-12-17 14:08:03 +0100714
715To insert a cookie only after a POST request, add 'postonly' after 'insert'.
716This has the advantage that there's no risk of caching, and that all pages
717seen before the POST one can still be cached :
718
willy tarreauc5f73ed2005-12-18 01:26:38 +0100719 cookie SERVERID insert postonly
willy tarreaueedaa9f2005-12-17 14:08:03 +0100720
721Notes :
722-----------
723- it is possible to combine 'insert' with 'indirect' or 'rewrite' to adapt to
724 applications which already generate the cookie with an invalid content.
725
726- in the case where 'insert' and 'indirect' are both specified, the cookie is
willy tarreau0174f312005-12-18 01:02:42 +0100727 never transmitted to the server, since it wouldn't understand it. This is the
728 most application-transparent mode.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100729
730- it is particularly recommended to use 'nocache' in 'insert' mode if any
731 upstream HTTP/1.0 cache is susceptible to cache the result, because this may
732 lead to many clients going to the same server, or even worse, some clients
733 having their server changed while retrieving a page from the cache.
734
willy tarreau0174f312005-12-18 01:02:42 +0100735- the 'prefix' mode normally does not need 'indirect', 'nocache', nor
736 'postonly', because just as in the 'rewrite' mode, it relies on the
737 application to know when a cookie can be emitted. However, since it has to
738 fix the cookie name in every subsequent requests, you must ensure that the
739 proxy will be used without any "HTTP keep-alive". Use option "httpclose" if
740 unsure.
741
willy tarreaueedaa9f2005-12-17 14:08:03 +0100742- when the application is well known and controlled, the best method is to
743 only add the persistence cookie on a POST form because it's up to the
willy tarreau0174f312005-12-18 01:02:42 +0100744 application to select which page it wants the upstream servers to cache. In
745 this case, you would use 'insert postonly indirect'.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100746
willy tarreauc5f73ed2005-12-18 01:26:38 +0100747
willy tarreaueedaa9f2005-12-17 14:08:03 +01007482.10) Associating a cookie value with a server
749----------------------------------------------
750In HTTP mode, it's possible to associate a cookie value to each server. This
751was initially used in combination with 'dispatch' mode to handle direct accesses
752but it is now the standard way of doing the load balancing. The syntax is :
753
754 server <identifier> <address>:<port> cookie <value>
755
756- <identifier> is any name which can be used to identify the server in the logs.
757- <address>:<port> specifies where the server is bound.
758- <value> is the value to put in or to read from the cookie.
759
760Example : the 'SERVERID' cookie can be either 'server01' or 'server02'
761---------
762 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100763 mode http
764 cookie SERVERID
765 dispatch 192.168.1.100:80
766 server web1 192.168.1.1:80 cookie server01
767 server web2 192.168.1.2:80 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100768
769Warning : the syntax has changed since version 1.0 !
770---------
771
willy tarreauc5f73ed2005-12-18 01:26:38 +0100772
willy tarreau598da412005-12-18 01:07:29 +01007732.11) Application Cookies
774-------------------------
775Since 1.2.4 it is possible to catch the cookie that comes from an
776application server in order to apply "application session stickyness".
777The server's response is searched for 'appsession' cookie, the first
778'len' bytes are used for matching and it is stored for a period of
779'timeout'.
780The syntax is:
781
willy tarreau532bb552006-05-13 18:40:37 +0200782 appsession <session_cookie> len <match_length> timeout <holdtime>
willy tarreau598da412005-12-18 01:07:29 +0100783
willy tarreau532bb552006-05-13 18:40:37 +0200784- <session_cookie> is the cookie, the server uses for it's session-handling
785- <match_length> how many bytes/characters should be used for matching equal
willy tarreau598da412005-12-18 01:07:29 +0100786 sessions
willy tarreau532bb552006-05-13 18:40:37 +0200787- <holdtime> after this inactivaty time, in ms, the cookie will be deleted
willy tarreau598da412005-12-18 01:07:29 +0100788 from the sessionstore
789
790The appsession is only per 'listen' section possible.
791
792Example :
793---------
willy tarreau532bb552006-05-13 18:40:37 +0200794 listen http_lb1 192.168.3.4:80
795 mode http
796 capture request header Cookie len 200
797 # Havind a ServerID cookie on the client allows him to reach
798 # the right server even after expiration of the appsession.
799 cookie ServerID insert nocache indirect
800 # Will memorize 52 bytes of the cookie 'JSESSIONID' and keep them
801 # for 3 hours. It will match it in the cookie and the URL field.
802 appsession JSESSIONID len 52 timeout 10800000
803 server first1 10.3.9.2:10805 check inter 3000 cookie first
804 server secon1 10.3.9.3:10805 check inter 3000 cookie secon
805 server first1 10.3.9.4:10805 check inter 3000 cookie first
806 server secon2 10.3.9.5:10805 check inter 3000 cookie secon
807 option httpchk GET /test.jsp
willy tarreau598da412005-12-18 01:07:29 +0100808
willy tarreauc5f73ed2005-12-18 01:26:38 +0100809
willy tarreaueedaa9f2005-12-17 14:08:03 +01008103) Autonomous load balancer
811===========================
812
813The proxy can perform the load-balancing itself, both in TCP and in HTTP modes.
814This is the most interesting mode which obsoletes the old 'dispatch' mode
815described above. It has advantages such as server health monitoring, multiple
816port binding and port mapping. To use this mode, the 'balance' keyword is used,
willy tarreau34f45302006-04-15 21:37:14 +0200817followed by the selected algorithm. Up to version 1.2.11, only 'roundrobin' was
818available, which is also the default value if unspecified. Starting with
819version 1.2.12, a new 'source' keyword appeared. In this mode, there will be no
820dispatch address, but the proxy needs at least one server.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100821
822Example : same as the last one, with internal load balancer
823---------
824
825 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100826 mode http
827 cookie SERVERID
828 balance roundrobin
829 server web1 192.168.1.1:80 cookie server01
830 server web2 192.168.1.2:80 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100831
832
833Since version 1.1.22, it is possible to automatically determine on which port
834the server will get the connection, depending on the port the client connected
835to. Indeed, there now are 4 possible combinations for the server's <port> field:
836
837 - unspecified or '0' :
838 the connection will be sent to the same port as the one on which the proxy
839 received the client connection itself.
840
841 - numerical value (the only one supported in versions earlier than 1.1.22) :
842 the connection will always be sent to the specified port.
843
844 - '+' followed by a numerical value :
845 the connection will be sent to the same port as the one on which the proxy
846 received the connection, plus this value.
847
848 - '-' followed by a numerical value :
849 the connection will be sent to the same port as the one on which the proxy
850 received the connection, minus this value.
851
852Examples :
853----------
854
855# same as previous example
856
857 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100858 mode http
859 cookie SERVERID
860 balance roundrobin
861 server web1 192.168.1.1 cookie server01
862 server web2 192.168.1.2 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100863
864# simultaneous relaying of ports 80, 81 and 8080-8089
865
866 listen http_proxy :80,:81,:8080-8089
willy tarreauc5f73ed2005-12-18 01:26:38 +0100867 mode http
868 cookie SERVERID
869 balance roundrobin
870 server web1 192.168.1.1 cookie server01
871 server web2 192.168.1.2 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100872
873# relaying of TCP ports 25, 389 and 663 to ports 1025, 1389 and 1663
874
875 listen http_proxy :25,:389,:663
willy tarreauc5f73ed2005-12-18 01:26:38 +0100876 mode tcp
877 balance roundrobin
878 server srv1 192.168.1.1:+1000
879 server srv2 192.168.1.2:+1000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100880
willy tarreau34f45302006-04-15 21:37:14 +0200881As previously stated, version 1.2.12 brought the 'source' keyword. When this
882keyword is used, the client's IP address is hashed and evenly distributed among
883the available servers so that a same source IP will always go to the same
884server as long as there are no change in the number of available servers. This
885can be used for instance to bind HTTP and HTTPS to the same server. It can also
886be used to improve stickyness when one part of the client population does not
887accept cookies. In this case, only those ones will be perturbated should a
888server fail.
889
890NOTE: It is important to consider the fact that many clients surf the net
891 through proxy farms which assign different IP addresses for each
892 request. Others use dialup connections with a different IP at each
893 connection. Thus, the 'source' parameter should be used with extreme
894 care.
895
896Examples :
897----------
898
899# make a same IP go to the same server whatever the service
900
901 listen http_proxy
902 bind :80,:443
903 mode http
904 balance source
905 server web1 192.168.1.1
906 server web2 192.168.1.2
907
908# try to improve client-server binding by using both source IP and cookie :
909
910 listen http_proxy :80
911 mode http
912 cookie SERVERID
913 balance source
914 server web1 192.168.1.1 cookie server01
915 server web2 192.168.1.2 cookie server02
916
willy tarreaueedaa9f2005-12-17 14:08:03 +0100917
willy tarreau197e8ec2005-12-17 14:10:59 +01009183.1) Server monitoring
919----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +0100920It is possible to check the servers status by trying to establish TCP
921connections or even sending HTTP requests to them. A server which fails to
922reply to health checks as expected will not be used by the load balancing
923algorithms. To enable monitoring, add the 'check' keyword on a server line.
924It is possible to specify the interval between tests (in milliseconds) with
925the 'inter' parameter, the number of failures supported before declaring that
926the server has fallen down with the 'fall' parameter, and the number of valid
927checks needed for the server to fully get up with the 'rise' parameter. Since
928version 1.1.22, it is also possible to send checks to a different port
929(mandatory when none is specified) with the 'port' parameter. The default
930values are the following ones :
931
932 - inter : 2000
933 - rise : 2
934 - fall : 3
935 - port : default server port
936
937The default mode consists in establishing TCP connections only. But in certain
938types of application failures, it is often that the server continues to accept
939connections because the system does it itself while the application is running
940an endless loop, or is completely stuck. So in version 1.1.16 were introduced
941HTTP health checks which only performed simple lightweight requests and analysed
942the response. Now, as of version 1.1.23, it is possible to change the HTTP
943method, the URI, and the HTTP version string (which even allows to send headers
944with a dirty trick). To enable HTTP health-checks, use 'option httpchk'.
945
946By default, requests use the 'OPTIONS' method because it's very light and easy
947to filter from logs, and does it on '/'. Only HTTP responses 2xx and 3xx are
948considered valid ones, and only if they come before the time to send a new
949request is reached ('inter' parameter). If some servers block this type of
950request, 3 other forms help to forge a request :
951
952 - option httpchk -> OPTIONS / HTTP/1.0
953 - option httpchk URI -> OPTIONS <URI> HTTP/1.0
954 - option httpchk METH URI -> <METH> <URI> HTTP/1.0
955 - option httpchk METH URI VER -> <METH> <URI> <VER>
956
957See examples below.
958
959Since version 1.1.17, it is possible to specify backup servers. These servers
960are only sollicited when no other server is available. This may only be useful
961to serve a maintenance page, or define one active and one backup server (seldom
962used in TCP mode). To make a server a backup one, simply add the 'backup' option
963on its line. These servers also support cookies, so if a cookie is specified for
964a backup server, clients assigned to this server will stick to it even when the
965other ones come back. Conversely, if no cookie is assigned to such a server,
966the clients will get their cookies removed (empty cookie = removal), and will
967be balanced against other servers once they come back. Please note that there
Willy TARREAU3481c462006-03-01 22:37:57 +0100968is no load-balancing among backup servers by default. If there are several
969backup servers, the second one will only be used when the first one dies, and
970so on. To force load-balancing between backup servers, specify the 'allbackups'
971option.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100972
973Since version 1.1.17, it is also possible to visually check the status of all
974servers at once. For this, you just have to send a SIGHUP signal to the proxy.
975The servers status will be dumped into the logs at the 'notice' level, as well
976as on <stderr> if not closed. For this reason, it's always a good idea to have
977one local log server at the 'notice' level.
978
willy tarreau982249e2005-12-18 00:57:06 +0100979Since version 1.1.28 and 1.2.1, if an instance loses all its servers, an
willy tarreau0174f312005-12-18 01:02:42 +0100980emergency message will be sent in the logs to inform the administator that an
willy tarreau982249e2005-12-18 00:57:06 +0100981immediate action must be taken.
982
willy tarreau0174f312005-12-18 01:02:42 +0100983Since version 1.1.30 and 1.2.3, several servers can share the same cookie
984value. This is particularly useful in backup mode, to select alternate paths
985for a given server for example, to provide soft-stop, or to direct the clients
986to a temporary page during an application restart. The principle is that when
987a server is dead, the proxy will first look for another server which shares the
988same cookie value for every client which presents the cookie. If there is no
989standard server for this cookie, it will then look for a backup server which
990shares the same name. Please consult the architecture guide for more information.
willy tarreau982249e2005-12-18 00:57:06 +0100991
willy tarreaueedaa9f2005-12-17 14:08:03 +0100992Examples :
993----------
994# same setup as in paragraph 3) with TCP monitoring
995 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100996 mode http
997 cookie SERVERID
998 balance roundrobin
999 server web1 192.168.1.1:80 cookie server01 check
1000 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +01001001
1002# same with HTTP monitoring via 'OPTIONS / HTTP/1.0'
1003 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001004 mode http
1005 cookie SERVERID
1006 balance roundrobin
1007 option httpchk
1008 server web1 192.168.1.1:80 cookie server01 check
1009 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +01001010
1011# same with HTTP monitoring via 'OPTIONS /index.html HTTP/1.0'
1012 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001013 mode http
1014 cookie SERVERID
1015 balance roundrobin
1016 option httpchk /index.html
1017 server web1 192.168.1.1:80 cookie server01 check
1018 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +01001019
1020# same with HTTP monitoring via 'HEAD /index.jsp? HTTP/1.1\r\nHost: www'
1021 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001022 mode http
1023 cookie SERVERID
1024 balance roundrobin
1025 option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www
1026 server web1 192.168.1.1:80 cookie server01 check
1027 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +01001028
willy tarreau0174f312005-12-18 01:02:42 +01001029# Load-balancing with 'prefixed cookie' persistence, and soft-stop using an
1030# alternate port 81 on the server for health-checks.
1031 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001032 mode http
1033 cookie JSESSIONID prefix
1034 balance roundrobin
1035 option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www
1036 server web1-norm 192.168.1.1:80 cookie s1 check port 81
1037 server web2-norm 192.168.1.2:80 cookie s2 check port 81
1038 server web1-stop 192.168.1.1:80 cookie s1 check port 80 backup
1039 server web2-stop 192.168.1.2:80 cookie s2 check port 80 backup
willy tarreau0174f312005-12-18 01:02:42 +01001040
willy tarreaueedaa9f2005-12-17 14:08:03 +01001041# automatic insertion of a cookie in the server's response, and automatic
1042# deletion of the cookie in the client request, while asking upstream caches
1043# not to cache replies.
1044 listen web_appl 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001045 mode http
1046 cookie SERVERID insert nocache indirect
1047 balance roundrobin
1048 server web1 192.168.1.1:80 cookie server01 check
1049 server web2 192.168.1.2:80 cookie server02 check
willy tarreaueedaa9f2005-12-17 14:08:03 +01001050
1051# same with off-site application backup and local error pages server
1052 listen web_appl 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001053 mode http
1054 cookie SERVERID insert nocache indirect
1055 balance roundrobin
1056 server web1 192.168.1.1:80 cookie server01 check
1057 server web2 192.168.1.2:80 cookie server02 check
1058 server web-backup 192.168.2.1:80 cookie server03 check backup
1059 server web-excuse 192.168.3.1:80 check backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01001060
willy tarreauc5f73ed2005-12-18 01:26:38 +01001061# SMTP+TLS relaying with health-checks and backup servers
willy tarreaueedaa9f2005-12-17 14:08:03 +01001062
1063 listen http_proxy :25,:587
willy tarreauc5f73ed2005-12-18 01:26:38 +01001064 mode tcp
1065 balance roundrobin
1066 server srv1 192.168.1.1 check port 25 inter 30000 rise 1 fall 2
1067 server srv2 192.168.1.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01001068
Willy TARREAU3481c462006-03-01 22:37:57 +01001069# Load-balancing using a backup pool (requires haproxy 1.2.9)
1070 listen http_proxy 0.0.0.0:80
1071 mode http
1072 balance roundrobin
1073 option httpchk
1074 server inst1 192.168.1.1:80 cookie s1 check
1075 server inst2 192.168.1.2:80 cookie s2 check
1076 server inst3 192.168.1.3:80 cookie s3 check
1077 server back1 192.168.1.10:80 check backup
1078 server back2 192.168.1.11:80 check backup
1079 option allbackups # all backups will be used
1080
willy tarreaueedaa9f2005-12-17 14:08:03 +01001081
10823.2) Redistribute connections in case of failure
1083------------------------------------------------
1084In HTTP mode, if a server designated by a cookie does not respond, the clients
1085may definitely stick to it because they cannot flush the cookie, so they will
1086not be able to access the service anymore. Specifying 'redispatch' will allow
1087the proxy to break their persistence and redistribute them to working servers.
1088
1089Example :
1090---------
1091 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001092 mode http
1093 cookie SERVERID
1094 dispatch 192.168.1.100:80
1095 server web1 192.168.1.1:80 cookie server01
1096 server web2 192.168.1.2:80 cookie server02
1097 redispatch # send back to dispatch in case of connection failure
willy tarreaueedaa9f2005-12-17 14:08:03 +01001098
1099Up to, and including version 1.1.16, this parameter only applied to connection
1100failures. Since version 1.1.17, it also applies to servers which have been
1101detected as failed by the health check mechanism. Indeed, a server may be broken
1102but still accepting connections, which would not solve every case. But it is
1103possible to conserve the old behaviour, that is, make a client insist on trying
1104to connect to a server even if it is said to be down, by setting the 'persist'
1105option :
1106
1107 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001108 mode http
1109 option persist
1110 cookie SERVERID
1111 dispatch 192.168.1.100:80
1112 server web1 192.168.1.1:80 cookie server01
1113 server web2 192.168.1.2:80 cookie server02
1114 redispatch # send back to dispatch in case of connection failure
willy tarreaueedaa9f2005-12-17 14:08:03 +01001115
1116
willy tarreau34f45302006-04-15 21:37:14 +020011173.3) Assigning different weights to servers
1118-------------------------------------------
1119Sometimes you will need to bring new servers to increase your server farm's
1120capacity, but the new server will be either smaller (emergency use of anything
1121that fits) or bigger (when investing in new hardware). For this reason, it
1122might be wise to be able to send more clients to biggest servers. Till version
11231.2.11, it was necessary to replicate the same server multiple times in the
1124configuration. Starting with 1.2.12, the 'weight' option is available. HAProxy
1125then computes the most homogenous possible map of servers based on their
willy tarreau532bb552006-05-13 18:40:37 +02001126weights so that the load gets distributed as smoothly as possible among them.
1127The weight, between 1 and 256, should reflect one server's capacity relative to
1128others. Weight 1 represents the lowest frequency and 256 the highest. This way,
1129if a server fails, the remaining capacities are still respected.
willy tarreau34f45302006-04-15 21:37:14 +02001130
1131Example :
1132---------
1133# fair distribution among two opterons and one old pentium3
1134
1135 listen web_appl 0.0.0.0:80
1136 mode http
1137 cookie SERVERID insert nocache indirect
1138 balance roundrobin
1139 server pentium3-800 192.168.1.1:80 cookie server01 weight 8 check
1140 server opteron-2.0G 192.168.1.2:80 cookie server02 weight 20 check
1141 server opteron-2.4G 192.168.1.3:80 cookie server03 weight 24 check
1142 server web-backup1 192.168.2.1:80 cookie server04 check backup
1143 server web-excuse 192.168.3.1:80 check backup
1144
1145Notes :
1146-------
1147 - if unspecified, the default weight is 1
1148
1149 - the weight does not impact health checks, so it is cleaner to use weights
1150 than replicating the same server several times
1151
1152 - weights also work on backup servers if the 'allbackups' option is used
1153
1154 - the weights also apply to the source address load balancing
1155 ('balance source').
1156
1157 - whatever the weights, the first server will always be assigned first. This
1158 is helpful for troubleshooting.
1159
1160 - for the purists, the map calculation algorithm gives precedence to first
1161 server, so the map is the most uniform when servers are declared in
1162 ascending order relative to their weights.
1163
willy tarreau532bb552006-05-13 18:40:37 +02001164The load distribution will follow exactly this sequence :
1165
1166 Request| 1 1 1 1
1167 number | 1 2 3 4 5 6 7 8 9 0 1 2 3
1168 --------+---------------------------
1169 p3-800 | X . . . . . . X . . . . .
1170 opt-20 | . X . X . X . . . X . X .
1171 opt-24 | . . X . X . X . X . X . X
1172
1173
11743.4) Limiting the number of concurrent sessions on each server
1175--------------------------------------------------------------
1176Some pre-forked servers such as Apache suffer from too many concurrent
1177sessions, because it's very expensive to run hundreds or thousands of
1178processes on one system. One solution is to increase the number of servers
1179and load-balance between them, but it is a problem when the only goal is
1180to resist to short surges.
1181
1182To solve this problem, a new feature was implemented in HAProxy 1.2.13.
1183It's a per-server 'maxconn', associated with a per-server and a per-proxy
1184queue. This transforms haproxy into a request buffer between the thousands of
1185clients and the few servers. On many circumstances, lowering the maxconn value
1186will increase the server's performance and decrease the overall response times
1187because the servers will be less congested.
1188
1189When a request tries to reach any server, the first non-saturated server is
1190used, respective to the load balancing algorithm. If all servers are saturated,
1191then the request gets queued into the instance's global queue. It will be
1192dequeued once a server will have freed a session and all previously queued
1193requests have been processed.
1194
1195If a request references a particular server (eg: source hashing, or persistence
1196cookie), and if this server is full, then the request will be queued into the
1197server's dedicated queue. This queue has higher priority than the global queue,
1198so it's easier for already registered users to enter the site than for new
1199users.
1200
1201For this, the logs have been enhanced to show the number of sessions per
1202server, the request's position in the queue and the time spent in the queue.
1203This helps doing capacity planning. See the 'logs' section below for more info.
1204
1205Example :
1206---------
1207 # be nice with P3 which only has 256 MB of RAM.
1208 listen web_appl 0.0.0.0:80
1209 maxconn 10000
1210 mode http
1211 cookie SERVERID insert nocache indirect
1212 balance roundrobin
1213 server pentium3-800 192.168.1.1:80 cookie s1 weight 8 maxconn 100 check
1214 server opteron-2.0G 192.168.1.2:80 cookie s2 weight 20 maxconn 300 check
1215 server opteron-2.4G 192.168.1.3:80 cookie s3 weight 24 maxconn 300 check
1216 server web-backup1 192.168.2.1:80 cookie s4 check maxconn 200 backup
1217 server web-excuse 192.168.3.1:80 check backup
1218
1219Notes :
1220-------
1221 - The requests will not stay indefinitely in the queue, they follow the
1222 'contimeout' parameter, and if a request cannot be dequeued within this
1223 timeout because the server is saturated or because the queue is filled,
1224 the session will expire with a 503 error.
1225
1226 - setting too low values for maxconn might improve performance but might also
1227 allow slow users to block access to the server for other users.
1228
willy tarreau34f45302006-04-15 21:37:14 +02001229
willy tarreaue0bdd622006-05-21 20:51:54 +020012303.5) Dropping aborted requests
1231------------------------------
1232In presence of very high loads, the servers will take some time to respond. The
1233per-proxy's connection queue will inflate, and the response time will increase
1234respective to the size of the queue times the average per-session response
1235time. When clients will wait for more than a few seconds, they will often hit
1236the 'STOP' button on their browser, leaving a useless request in the queue, and
1237slowing down other users.
1238
1239As there is no way to distinguish between a full STOP and a simple
1240shutdown(SHUT_WR) on the client side, HTTP agents should be conservative and
1241consider that the client might only have closed its output channel while
1242waiting for the response. However, this introduces risks of congestion when
1243lots of users do the same, and is completely useless nowadays because probably
1244no client at all will close the session while waiting for the response. Some
1245HTTP agents support this (Squid, Apache, HAProxy), and others do not (TUX, most
1246hardware-based load balancers). So the probability for a closed input channel
1247to represent a user hitting the 'STOP' button is close to 100%, and it is very
1248tempting to be able to abort the session early without polluting the servers.
1249
1250For this reason, a new option "abortonclose" was introduced in version 1.2.14.
1251By default (without the option) the behaviour is HTTP-compliant. But when the
1252option is specified, a session with an incoming channel closed will be aborted
1253if it's still possible, which means that it's either waiting for a connect() to
1254establish or it is queued waiting for a connection slot. This considerably
1255reduces the queue size and the load on saturated servers when users are tempted
1256to click on STOP, which in turn reduces the response time for other users.
1257
1258Example :
1259---------
1260 listen web_appl 0.0.0.0:80
1261 maxconn 10000
1262 mode http
1263 cookie SERVERID insert nocache indirect
1264 balance roundrobin
1265 server web1 192.168.1.1:80 cookie s1 weight 10 maxconn 100 check
1266 server web2 192.168.1.2:80 cookie s2 weight 10 maxconn 100 check
1267 server web3 192.168.1.3:80 cookie s3 weight 10 maxconn 100 check
1268 server bck1 192.168.2.1:80 cookie s4 check maxconn 200 backup
1269 option abortonclose
1270
1271
willy tarreaueedaa9f2005-12-17 14:08:03 +010012724) Additionnal features
1273=======================
1274
1275Other features are available. They are transparent mode, event logging and
1276header rewriting/filtering.
1277
willy tarreauc5f73ed2005-12-18 01:26:38 +01001278
willy tarreau0174f312005-12-18 01:02:42 +010012794.1) Network features
willy tarreaueedaa9f2005-12-17 14:08:03 +01001280---------------------
willy tarreau0174f312005-12-18 01:02:42 +010012814.1.1) Transparent mode
1282-----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +01001283In HTTP mode, the 'transparent' keyword allows to intercept sessions which are
1284routed through the system hosting the proxy. This mode was implemented as a
1285replacement for the 'dispatch' mode, since connections without cookie will be
1286sent to the original address while known cookies will be sent to the servers.
1287This mode implies that the system can redirect sessions to a local port.
1288
1289Example :
1290---------
1291 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001292 mode http
1293 transparent
1294 cookie SERVERID
1295 server server01 192.168.1.1:80
1296 server server02 192.168.1.2:80
willy tarreaueedaa9f2005-12-17 14:08:03 +01001297
1298 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
1299 --dport 80 -j REDIRECT --to-ports 65000
1300
1301Note :
1302------
1303If the port is left unspecified on the server, the port the client connected to
1304will be used. This allows to relay a full port range without using transparent
1305mode nor thousands of file descriptors, provided that the system can redirect
1306sessions to local ports.
1307
1308Example :
1309---------
1310 # redirect all ports to local port 65000, then forward to the server on the
1311 # original port.
1312 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001313 mode tcp
1314 server server01 192.168.1.1 check port 60000
1315 server server02 192.168.1.2 check port 60000
willy tarreaueedaa9f2005-12-17 14:08:03 +01001316
1317 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
1318 -j REDIRECT --to-ports 65000
1319
willy tarreau0174f312005-12-18 01:02:42 +010013204.1.2) Per-server source address binding
1321----------------------------------------
1322As of versions 1.1.30 and 1.2.3, it is possible to specify a particular source
1323to reach each server. This is useful when reaching backup servers from a
1324different LAN, or to use an alternate path to reach the same server. It is also
1325usable to provide source load-balancing for outgoing connections. Obviously,
1326the same source address is used to send health-checks.
1327
1328Example :
1329---------
1330 # use a particular source to reach both servers
1331 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001332 mode http
1333 balance roundrobin
1334 server server01 192.168.1.1:80 source 192.168.2.13
1335 server server02 192.168.1.2:80 source 192.168.2.13
willy tarreau0174f312005-12-18 01:02:42 +01001336
1337Example :
1338---------
1339 # use a particular source to reach each servers
1340 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001341 mode http
1342 balance roundrobin
1343 server server01 192.168.1.1:80 source 192.168.1.1
1344 server server02 192.168.2.1:80 source 192.168.2.1
willy tarreau0174f312005-12-18 01:02:42 +01001345
1346Example :
1347---------
1348 # provide source load-balancing to reach the same proxy through 2 WAN links
1349 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001350 mode http
1351 balance roundrobin
1352 server remote-proxy-way1 192.168.1.1:3128 source 192.168.2.1
1353 server remote-proxy-way2 192.168.1.1:3128 source 192.168.3.1
willy tarreau0174f312005-12-18 01:02:42 +01001354
1355Example :
1356---------
1357 # force a TCP connection to bind to a specific port
1358 listen http_proxy 0.0.0.0:2000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001359 mode tcp
1360 balance roundrobin
1361 server srv1 192.168.1.1:80 source 192.168.2.1:20
1362 server srv2 192.168.1.2:80 source 192.168.2.1:20
willy tarreau0174f312005-12-18 01:02:42 +01001363
willy tarreaub952e1d2005-12-18 01:31:20 +010013644.1.3) TCP keep-alive
1365---------------------
1366With version 1.2.7, it becomes possible to enable TCP keep-alives on both the
1367client and server sides. This makes it possible to prevent long sessions from
1368expiring on external layer 4 components such as firewalls and load-balancers.
1369It also allows the system to terminate dead sessions when no timeout has been
1370set (not recommanded). The proxy cannot set the keep-alive probes intervals nor
1371maximal count, consult your operating system manual for this. There are 3
1372options to enable TCP keep-alive :
1373
1374 option tcpka # enables keep-alive both on client and server side
1375 option clitcpka # enables keep-alive only on client side
1376 option srvtcpka # enables keep-alive only on server side
1377
willy tarreaueedaa9f2005-12-17 14:08:03 +01001378
13794.2) Event logging
1380------------------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001381
1382HAProxy's strength certainly lies in its precise logs. It probably provides the
1383finest level of information available for such a product, which is very
1384important for troubleshooting complex environments. Standard log information
1385include client ports, TCP/HTTP state timers, precise session state at
1386termination and precise termination cause, information about decisions to
1387direct trafic to a server, and of course the ability to capture arbitrary
1388headers.
1389
1390In order to improve administrators reactivity, it offers a great transparency
1391about encountered problems, both internal and external, and it is possible to
1392send logs to different sources at the same time with different level filters :
1393
1394 - global process-level logs (system errors, start/stop, etc..)
1395 - per-listener system and internal errors (lack of resource, bugs, ...)
1396 - per-listener external troubles (servers up/down, max connections)
1397 - per-listener activity (client connections), either at the establishment or
1398 at the termination.
1399
1400The ability to distribute different levels of logs to different log servers
1401allow several production teams to interact and to fix their problems as soon
1402as possible. For example, the system team might monitor system-wide errors,
1403while the application team might be monitoring the up/down for their servers in
1404real time, and the security team might analyze the activity logs with one hour
1405delay.
1406
willy tarreauc1cae632005-12-17 14:12:23 +010014074.2.1) Log levels
1408-----------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001409TCP and HTTP connections can be logged with informations such as date, time,
1410source IP address, destination address, connection duration, response times,
1411HTTP request, the HTTP return code, number of bytes transmitted, the conditions
1412in which the session ended, and even exchanged cookies values, to track a
1413particular user's problems for example. All messages are sent to up to two
1414syslog servers. Consult section 1.1 for more info about log facilities. The
1415syntax follows :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001416
willy tarreau197e8ec2005-12-17 14:10:59 +01001417 log <address_1> <facility_1> [max_level_1]
1418 log <address_2> <facility_2> [max_level_2]
1419or
willy tarreaueedaa9f2005-12-17 14:08:03 +01001420 log global
1421
willy tarreau197e8ec2005-12-17 14:10:59 +01001422Note :
1423------
1424The particular syntax 'log global' means that the same log configuration as the
1425'global' section will be used.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001426
willy tarreau197e8ec2005-12-17 14:10:59 +01001427Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001428---------
1429 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001430 mode http
1431 log 192.168.2.200 local3
1432 log 192.168.2.201 local4
willy tarreaueedaa9f2005-12-17 14:08:03 +01001433
willy tarreauc1cae632005-12-17 14:12:23 +010014344.2.2) Log format
1435-----------------
1436By default, connections are logged at the TCP level, as soon as the session
1437establishes between the client and the proxy. By enabling the 'tcplog' option,
1438the proxy will wait until the session ends to generate an enhanced log
1439containing more information such as session duration and its state during the
willy tarreau532bb552006-05-13 18:40:37 +02001440disconnection. The number of remaining session after disconnection is also
1441indicated (for the server, the listener, and the process).
willy tarreauc1cae632005-12-17 14:12:23 +01001442
willy tarreauc5f73ed2005-12-18 01:26:38 +01001443Example of TCP logging :
1444------------------------
willy tarreau982249e2005-12-18 00:57:06 +01001445 listen relais-tcp 0.0.0.0:8000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001446 mode tcp
1447 option tcplog
1448 log 192.168.2.200 local3
willy tarreau982249e2005-12-18 00:57:06 +01001449
willy tarreau532bb552006-05-13 18:40:37 +02001450>>> 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 +01001451
willy tarreau532bb552006-05-13 18:40:37 +02001452 Field Format Example
willy tarreauc5f73ed2005-12-18 01:26:38 +01001453
willy tarreau532bb552006-05-13 18:40:37 +02001454 1 process_name '[' pid ']:' haproxy[18989]:
1455 2 client_ip ':' client_port 127.0.0.1:34550
1456 3 '[' date ']' [15/Oct/2003:15:24:28]
1457 4 listener_name relais-tcp
1458 5 server_name Srv1
1459 6 queue_time '/' connect_time '/' total_time 0/0/5007
1460 7 bytes_read 0
1461 8 termination_state --
1462 9 srv_conn '/' listener_conn '/' process_conn 1/1/1
1463 10 position in srv_queue / listener_queue 0/0
1464
willy tarreau982249e2005-12-18 00:57:06 +01001465
willy tarreauc1cae632005-12-17 14:12:23 +01001466Another option, 'httplog', provides more detailed information about HTTP
1467contents, such as the request and some cookies. In the event where an external
1468component would establish frequent connections to check the service, logs may be
1469full of useless lines. So it is possible not to log any session which didn't
1470transfer any data, by the setting of the 'dontlognull' option. This only has
1471effect on sessions which are established then closed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001472
willy tarreauc5f73ed2005-12-18 01:26:38 +01001473Example of HTTP logging :
1474-------------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +01001475 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001476 mode http
1477 option httplog
1478 option dontlognull
1479 log 192.168.2.200 local3
1480
willy tarreau532bb552006-05-13 18:40:37 +02001481>>> 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 +01001482
willy tarreauc5f73ed2005-12-18 01:26:38 +01001483More complete example
willy tarreau532bb552006-05-13 18:40:37 +02001484 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 +01001485
willy tarreau532bb552006-05-13 18:40:37 +02001486 Field Format Example
willy tarreauc5f73ed2005-12-18 01:26:38 +01001487
willy tarreau532bb552006-05-13 18:40:37 +02001488 1 process_name '[' pid ']:' haproxy[18989]:
1489 2 client_ip ':' client_port 10.0.0.1:34552
1490 3 '[' date ']' [15/Oct/2003:15:26:31]
1491 4 listener_name relais-http
1492 5 server_name Srv1
1493 6 Tq '/' Tw '/' Tc '/' Tr '/' Tt 3183/-1/-1/-1/11215
1494 7 HTTP_return_code 503
1495 8 bytes_read 0
1496 9 captured_request_cookie -
1497 10 captured_response_cookie -
1498 11 termination_state SC--
1499 12 srv_conn '/' listener_conn '/' process_conn 137/202/205
1500 13 position in srv_queue / listener_queue 0/0
1501 14 '{' captured_request_headers '}' {w.ods.org|Mozilla}
1502 15 '{' captured_response_headers '}' {}
1503 16 '"' HTTP_request '"' "HEAD / HTTP/1.0"
willy tarreauc5f73ed2005-12-18 01:26:38 +01001504
1505Note for log parsers: the URI is ALWAYS the end of the line starting with the
1506 first double quote '"'.
willy tarreau982249e2005-12-18 00:57:06 +01001507
1508The problem when logging at end of connection is that you have no clue about
1509what is happening during very long sessions. To workaround this problem, a
1510new option 'logasap' has been introduced in 1.1.28/1.2.1. When specified, the
1511proxy will log as soon as possible, just before data transfer begins. This means
1512that in case of TCP, it will still log the connection status to the server, and
1513in case of HTTP, it will log just after processing the server headers. In this
1514case, the number of bytes reported is the number of header bytes sent to the
1515client.
1516
1517In order to avoid confusion with normal logs, the total time field and the
1518number of bytes are prefixed with a '+' sign which mean that real numbers are
1519certainly bigger.
1520
1521Example :
1522---------
1523
1524 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001525 mode http
1526 option httplog
1527 option dontlognull
1528 option logasap
1529 log 192.168.2.200 local3
willy tarreau982249e2005-12-18 00:57:06 +01001530
willy tarreau532bb552006-05-13 18:40:37 +02001531>>> 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 +01001532
willy tarreauc1cae632005-12-17 14:12:23 +010015334.2.3) Timing events
1534--------------------
1535Timers provide a great help in trouble shooting network problems. All values
1536are reported in milliseconds (ms). In HTTP mode, four control points are
willy tarreau532bb552006-05-13 18:40:37 +02001537reported under the form 'Tq/Tw/Tc/Tr/Tt' :
willy tarreauc1cae632005-12-17 14:12:23 +01001538
1539 - Tq: total time to get the client request.
1540 It's the time elapsed between the moment the client connection was accepted
1541 and the moment the proxy received the last HTTP header. The value '-1'
1542 indicates that the end of headers (empty line) has never been seen.
1543
willy tarreau532bb552006-05-13 18:40:37 +02001544 - Tw: total time spent in the queues waiting for a connection slot. It
1545 accounts for listener's queue as well as the server's queue, and depends
1546 on the queue size, and the time needed for the server to complete previous
1547 sessions. The value '-1' means that the request was killed before reaching
1548 the queue.
1549
willy tarreauc1cae632005-12-17 14:12:23 +01001550 - Tc: total time to establish the TCP connection to the server.
1551 It's the time elapsed between the moment the proxy sent the connection
1552 request, and the moment it was acknowledged, or between the TCP SYN packet
1553 and the matching SYN/ACK in return. The value '-1' means that the
1554 connection never established.
1555
1556 - Tr: server response time. It's the time elapsed between the moment the
1557 TCP connection was established to the server and the moment it send its
1558 complete response header. It purely shows its request processing time,
1559 without the network overhead due to the data transmission. The value '-1'
1560 means that the last the response header (empty line) was never seen.
1561
1562 - Tt: total session duration time, between the moment the proxy accepted it
willy tarreau982249e2005-12-18 00:57:06 +01001563 and the moment both ends were closed. The exception is when the 'logasap'
willy tarreau532bb552006-05-13 18:40:37 +02001564 option is specified. In this case, it only equals (Tq+Tw+Tc+Tr), and is
willy tarreau982249e2005-12-18 00:57:06 +01001565 prefixed with a '+' sign. From this field, we can deduce Td, the data
1566 transmission time, by substracting other timers when valid :
willy tarreauc1cae632005-12-17 14:12:23 +01001567
willy tarreau532bb552006-05-13 18:40:37 +02001568 Td = Tt - (Tq + Tw + Tc + Tr)
willy tarreauc1cae632005-12-17 14:12:23 +01001569
1570 Timers with '-1' values have to be excluded from this equation.
1571
willy tarreau532bb552006-05-13 18:40:37 +02001572In TCP mode ('option tcplog'), only Tw, Tc and Tt are reported.
willy tarreauc1cae632005-12-17 14:12:23 +01001573
1574These timers provide precious indications on trouble causes. Since the TCP
1575protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure
1576that timers close to multiples of 3s are nearly always related to packets lost
1577due to network problems (wires or negociation). Moreover, if <Tt> is close to
1578a timeout value specified in the configuration, it often means that a session
1579has been aborted on time-out.
1580
1581Most common cases :
1582
1583 - If Tq is close to 3000, a packet has probably been lost between the client
1584 and the proxy.
1585 - If Tc is close to 3000, a packet has probably been lost between the server
1586 and the proxy during the server connection phase. This one should always be
1587 very low (less than a few tens).
1588 - If Tr is nearly always lower than 3000 except some rare values which seem to
1589 be the average majored by 3000, there are probably some packets lost between
1590 the proxy and the server.
1591 - If Tt is often slightly higher than a time-out, it's often because the
1592 client and the server use HTTP keep-alive and the session is maintained
1593 after the response ends. Se further for how to disable HTTP keep-alive.
1594
1595Other cases ('xx' means any value to be ignored) :
willy tarreau532bb552006-05-13 18:40:37 +02001596 -1/xx/xx/xx/Tt: the client was not able to send its complete request in time,
1597 or that it aborted it too early.
1598 Tq/-1/xx/xx/Tt: it was not possible to process the request, maybe because
1599 servers were out of order.
1600 Tq/Tw/-1/xx/Tt: the connection could not establish on the server. Either it
1601 refused it or it timed out after Tt-(Tq+Tw) ms.
1602 Tq/Tw/Tc/-1/Tt: the server has accepted the connection but did not return a
1603 complete response in time, or it closed its connexion
1604 unexpectedly, after Tt-(Tq+Tw+Tc) ms.
willy tarreauc1cae632005-12-17 14:12:23 +01001605
16064.2.4) Session state at disconnection
1607-------------------------------------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001608TCP and HTTP logs provide a session completion indicator in the
1609<termination_state> field, just before the number of active
1610connections. It is 2-characters long in TCP, and 4-characters long in
1611HTTP, each of which has a special meaning :
1612
willy tarreau197e8ec2005-12-17 14:10:59 +01001613 - On the first character, a code reporting the first event which caused the
1614 session to terminate :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001615
willy tarreauc5f73ed2005-12-18 01:26:38 +01001616 C : the TCP session was unexpectedly aborted by the client.
1617
1618 S : the TCP session was unexpectedly aborted by the server, or the
1619 server explicitly refused it.
1620
1621 P : the session was prematurely aborted by the proxy, because of a
1622 connection limit enforcement, because a DENY filter was matched,
1623 or because of a security check which detected and blocked a
1624 dangerous error in server response which might have caused
1625 information leak (eg: cacheable cookie).
1626
1627 R : a resource on the proxy has been exhausted (memory, sockets, source
1628 ports, ...). Usually, this appears during the connection phase, and
1629 system logs should contain a copy of the precise error.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001630
willy tarreauc5f73ed2005-12-18 01:26:38 +01001631 I : an internal error was identified by the proxy during a self-check.
1632 This should NEVER happen, and you are encouraged to report any log
1633 containing this, because this is a bug.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001634
willy tarreauc5f73ed2005-12-18 01:26:38 +01001635 c : the client-side time-out expired first.
1636
1637 s : the server-side time-out expired first.
1638
1639 - : normal session completion.
1640
1641 - on the second character, the TCP/HTTP session state when it was closed :
1642
1643 R : waiting for complete REQUEST from the client (HTTP only). Nothing
1644 was sent to any server.
1645
willy tarreau532bb552006-05-13 18:40:37 +02001646 Q : waiting in the QUEUE for a connection slot. This can only happen on
1647 servers which have a 'maxconn' parameter set. No connection attempt
1648 was made to any server.
1649
willy tarreauc5f73ed2005-12-18 01:26:38 +01001650 C : waiting for CONNECTION to establish on the server. The server might
1651 at most have noticed a connection attempt.
1652
1653 H : waiting for, receiving and processing server HEADERS (HTTP only).
1654
1655 D : the session was in the DATA phase.
1656
1657 L : the proxy was still transmitting LAST data to the client while the
1658 server had already finished.
1659
1660 - : normal session completion after end of data transfer.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001661
willy tarreau197e8ec2005-12-17 14:10:59 +01001662 - the third character tells whether the persistence cookie was provided by
willy tarreauc1cae632005-12-17 14:12:23 +01001663 the client (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001664
willy tarreauc5f73ed2005-12-18 01:26:38 +01001665 N : the client provided NO cookie. This is usually the case on new
1666 connections.
1667
1668 I : the client provided an INVALID cookie matching no known
1669 server. This might be caused by a recent configuration change,
1670 mixed cookies between HTTP/HTTPS sites, or an attack.
1671
1672 D : the client provided a cookie designating a server which was DOWN,
1673 so either the 'persist' option was used and the client was sent to
1674 this server, or it was not set and the client was redispatched to
1675 another server.
1676
1677 V : the client provided a valid cookie, and was sent to the associated
1678 server.
1679
1680 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001681
willy tarreau197e8ec2005-12-17 14:10:59 +01001682 - the last character reports what operations were performed on the persistence
willy tarreauc1cae632005-12-17 14:12:23 +01001683 cookie returned by the server (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001684
willy tarreauc5f73ed2005-12-18 01:26:38 +01001685 N : NO cookie was provided by the server, and none was inserted either.
1686
1687 I : no cookie was provided by the server, and the proxy INSERTED one.
1688
willy tarreau197e8ec2005-12-17 14:10:59 +01001689 P : a cookie was PROVIDED by the server and transmitted as-is.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001690
willy tarreauc5f73ed2005-12-18 01:26:38 +01001691 R : the cookie provided by the server was REWRITTEN by the proxy.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001692
willy tarreauc5f73ed2005-12-18 01:26:38 +01001693 D : the cookie provided by the server was DELETED by the proxy.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001694
willy tarreauc5f73ed2005-12-18 01:26:38 +01001695 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001696
willy tarreauc5f73ed2005-12-18 01:26:38 +01001697The combination of the two first flags give a lot of information about what was
1698happening when the session terminated. It can be helpful to detect server
1699saturation, network troubles, local system resource starvation, attacks, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01001700
willy tarreauc5f73ed2005-12-18 01:26:38 +01001701The most common termination flags combinations are indicated here.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001702
willy tarreauc5f73ed2005-12-18 01:26:38 +01001703 Flags Reason
1704 CR The client aborted before sending a full request. Most probably the
1705 request was done by hand using a telnet client, and aborted early.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001706
willy tarreauc5f73ed2005-12-18 01:26:38 +01001707 cR The client timed out before sending a full request. This is sometimes
1708 caused by too large TCP MSS values on the client side for PPPoE
1709 networks which cannot transport full-sized packets, or by clients
1710 sending requests by hand and not typing fast enough.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001711
willy tarreauc5f73ed2005-12-18 01:26:38 +01001712 SC The server explicitly refused the connection (the proxy received a
1713 TCP RST or an ICMP in return). Under some circumstances, it can
1714 also be the network stack telling the proxy that the server is
1715 unreachable (eg: no route, or no ARP response on local network).
willy tarreau982249e2005-12-18 00:57:06 +01001716
willy tarreauc5f73ed2005-12-18 01:26:38 +01001717 sC The connection to the server did not complete during contimeout.
willy tarreau982249e2005-12-18 00:57:06 +01001718
willy tarreauc5f73ed2005-12-18 01:26:38 +01001719 PC The proxy refused to establish a connection to the server because the
1720 maxconn limit has been reached. The listener's maxconn parameter may
1721 be increased in the proxy configuration, as well as the global
1722 maxconn parameter.
willy tarreauc1cae632005-12-17 14:12:23 +01001723
willy tarreauc5f73ed2005-12-18 01:26:38 +01001724 RC A local resource has been exhausted (memory, sockets, source ports)
1725 preventing the connection to the server from establishing. The error
1726 logs will tell precisely what was missing. Anyway, this can only be
1727 solved by system tuning.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001728
willy tarreauc5f73ed2005-12-18 01:26:38 +01001729 cH The client timed out during a POST request. This is sometimes caused
1730 by too large TCP MSS values for PPPoE networks which cannot transport
1731 full-sized packets.
willy tarreauc1cae632005-12-17 14:12:23 +01001732
willy tarreau078c79a2006-05-13 12:23:58 +02001733 CH The client aborted while waiting for the server to start responding.
1734 It might be the server taking too long to respond or the client
1735 clicking the 'Stop' button too fast.
1736
1737 CQ The client aborted while its session was queued, waiting for a server
1738 with enough empty slots to accept it. It might be that either all the
1739 servers were saturated or the assigned server taking too long to
1740 respond.
1741
1742 sQ The session spent too much time in queue and has been expired.
1743
willy tarreauc5f73ed2005-12-18 01:26:38 +01001744 SH The server aborted before sending its full headers, or it crashed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001745
willy tarreauc5f73ed2005-12-18 01:26:38 +01001746 sH The server failed to reply during the srvtimeout delay, which
1747 indicates too long transactions, probably caused by back-end
1748 saturation. The only solutions are to fix the problem on the
1749 application or to increase the 'srvtimeout' parameter to support
1750 longer delays (at the risk of the client giving up anyway).
1751
1752 PR The proxy blocked the client's request, either because of an invalid
1753 HTTP syntax, in which case it returned an HTTP 400 error to the
1754 client, or because a deny filter matched, in which case it returned
1755 an HTTP 403 error.
1756
1757 PH The proxy blocked the server's response, because it was invalid,
1758 incomplete, dangerous (cache control), or matched a security filter.
1759 In any case, an HTTP 502 error is sent to the client.
1760
1761 cD The client did not read any data for as long as the clitimeout delay.
1762 This is often caused by network failures on the client side.
1763
1764 CD The client unexpectedly aborted during data transfer. This is either
1765 caused by a browser crash, or by a keep-alive session between the
1766 server and the client terminated first by the client.
1767
1768 sD The server did nothing during the srvtimeout delay. This is often
1769 caused by too short timeouts on L4 equipements before the server
1770 (firewalls, load-balancers, ...).
1771
17724.2.5) Non-printable characters
willy tarreau4302f492005-12-18 01:00:37 +01001773-------------------------------
1774As of version 1.1.29, non-printable characters are not sent as-is into log
1775files, but are converted to their two-digits hexadecimal representation,
1776prefixed by the character '#'. The only characters that can now be logged
1777without being escaped are between 32 and 126 (inclusive). Obviously, the
1778escape character '#' is also encoded to avoid any ambiguity. It is the same for
1779the character '"', as well as '{', '|' and '}' when logging headers.
1780
willy tarreauc5f73ed2005-12-18 01:26:38 +010017814.2.6) Capturing HTTP headers and cookies
1782-----------------------------------------
1783Version 1.1.23 brought cookie capture, and 1.1.29 the header capture. All this
1784is performed using the 'capture' keyword.
1785
1786Cookie capture makes it easy to track a complete user session. The syntax is :
1787
1788 capture cookie <cookie_prefix> len <capture_length>
1789
1790This will enable cookie capture from both requests and responses. This way,
1791it's easy to detect when a user switches to a new session for example, because
1792the server will reassign it a new cookie.
1793
1794The FIRST cookie whose name starts with <cookie_prefix> will be captured, and
1795logged as 'NAME=value', without exceeding <capture_length> characters (64 max).
1796When the cookie name is fixed and known, it's preferable to suffix '=' to it to
1797ensure that no other cookie will be logged.
1798
1799Examples :
1800----------
1801 # capture the first cookie whose name starts with "ASPSESSION"
1802 capture cookie ASPSESSION len 32
1803
1804 # capture the first cookie whose name is exactly "vgnvisitor"
1805 capture cookie vgnvisitor= len 32
1806
1807In the logs, the field preceeding the completion indicator contains the cookie
1808value as sent by the server, preceeded by the cookie value as sent by the
1809client. Each of these field is replaced with '-' when no cookie was seen or
1810when the option is disabled.
1811
1812Header captures have a different goal. They are useful to track unique request
1813identifiers set by a previous proxy, virtual host names, user-agents, POST
1814content-length, referrers, etc. In the response, one can search for information
1815about the response length, how the server asked the cache to behave, or an
1816object location during a redirection. As for cookie captures, it is both
1817possible to include request headers and response headers at the same time. The
1818syntax is :
willy tarreau4302f492005-12-18 01:00:37 +01001819
1820 capture request header <name> len <max length>
1821 capture response header <name> len <max length>
1822
1823Note: Header names are not case-sensitive.
1824
1825Examples:
1826---------
1827 # keep the name of the virtual server
1828 capture request header Host len 20
1829 # keep the amount of data uploaded during a POST
1830 capture request header Content-Length len 10
1831
1832 # note the expected cache behaviour on the response
1833 capture response header Cache-Control len 8
1834 # note the URL location during a redirection
1835 capture response header Location len 20
1836
1837Non-existant headers are logged as empty strings, and if one header appears more
1838than once, only its last occurence will be kept. Request headers are grouped
1839within braces '{' and '}' in the same order as they were declared, and delimited
1840with a vertical bar '|' without any space. Response headers follow the same
1841representation, but are displayed after a space following the request headers
1842block. These blocks are displayed just before the HTTP request in the logs.
willy tarreauc5f73ed2005-12-18 01:26:38 +01001843
willy tarreau4302f492005-12-18 01:00:37 +01001844Example :
1845
willy tarreauc5f73ed2005-12-18 01:26:38 +01001846 Config:
1847
1848 capture request header Host len 20
1849 capture request header Content-Length len 10
1850 capture request header Referer len 20
1851 capture response header Server len 20
1852 capture response header Content-Length len 10
1853 capture response header Cache-Control len 8
1854 capture response header Via len 20
1855 capture response header Location len 20
1856
1857 Log :
1858
willy tarreau532bb552006-05-13 18:40:37 +02001859 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/"
1860 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"
1861 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 +01001862
1863
18644.2.7) Examples of logs
1865-----------------------
willy tarreau532bb552006-05-13 18:40:37 +02001866- 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 +01001867 => long request (6.5s) entered by hand through 'telnet'. The server replied
1868 in 147 ms, and the session ended normally ('----')
1869
willy tarreau532bb552006-05-13 18:40:37 +02001870- 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"
1871 => Idem, but the request was queued in the global queue behind 9 other
1872 requests, and waited there for 1230 ms.
1873
1874- 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 +01001875 => request for a long data transfer. The 'logasap' option was specified, so
1876 the log was produced just before transfering data. The server replied in
1877 14 ms, 243 bytes of headers were sent to the client, and total time from
1878 accept to first data byte is 30 ms.
1879
willy tarreau532bb552006-05-13 18:40:37 +02001880- 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 +01001881 => the proxy blocked a server response either because of an 'rspdeny' or
1882 'rspideny' filter, or because it blocked sensible information which risked
1883 being cached. In this case, the response is replaced with a '502 bad
1884 gateway'.
1885
willy tarreau532bb552006-05-13 18:40:37 +02001886- 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 +01001887 => the client never completed its request and aborted itself ('C---') after
1888 8.5s, while the proxy was waiting for the request headers ('-R--').
1889 Nothing was sent to the server.
1890
willy tarreau532bb552006-05-13 18:40:37 +02001891- 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 +01001892 => The client never completed its request, which was aborted by the time-out
1893 ('c---') after 50s, while the proxy was waiting for the request headers ('-R--').
1894 Nothing was sent to the server, but the proxy could send a 408 return code
1895 to the client.
willy tarreau4302f492005-12-18 01:00:37 +01001896
willy tarreau532bb552006-05-13 18:40:37 +02001897- 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 +01001898 => This is a 'tcplog' entry. Client-side time-out ('c----') occured after 5s.
willy tarreau4302f492005-12-18 01:00:37 +01001899
willy tarreau532bb552006-05-13 18:40:37 +02001900- 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 +01001901 => The request took 3s to complete (probably a network problem), and the
1902 connection to the server failed ('SC--') after 4 attemps of 2 seconds
1903 (config says 'retries 3'), then a 503 error code was sent to the client.
willy tarreau532bb552006-05-13 18:40:37 +02001904 There were 115 connections on this server, 202 connections on this proxy,
1905 and 205 on the global process. It is possible that the server refused the
1906 connection because of too many already established.
willy tarreau4302f492005-12-18 01:00:37 +01001907
willy tarreau4302f492005-12-18 01:00:37 +01001908
willy tarreau197e8ec2005-12-17 14:10:59 +010019094.3) HTTP header manipulation
1910-----------------------------
1911In HTTP mode, it is possible to rewrite, add or delete some of the request and
1912response headers based on regular expressions. It is also possible to block a
1913request or a response if a particular header matches a regular expression,
1914which is enough to stops most elementary protocol attacks, and to protect
1915against information leak from the internal network. But there is a limitation
1916to this : since haproxy's HTTP engine knows nothing about keep-alive, only
1917headers passed during the first request of a TCP session will be seen. All
1918subsequent headers will be considered data only and not analyzed. Furthermore,
1919haproxy doesn't touch data contents, it stops at the end of headers.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001920
willy tarreau197e8ec2005-12-17 14:10:59 +01001921The syntax is :
1922 reqadd <string> to add a header to the request
1923 reqrep <search> <replace> to modify the request
1924 reqirep <search> <replace> same, but ignoring the case
1925 reqdel <search> to delete a header in the request
1926 reqidel <search> same, but ignoring the case
1927 reqallow <search> definitely allow a request if a header matches <search>
1928 reqiallow <search> same, but ignoring the case
1929 reqdeny <search> denies a request if a header matches <search>
1930 reqideny <search> same, but ignoring the case
1931 reqpass <search> ignore a header matching <search>
1932 reqipass <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01001933
willy tarreau197e8ec2005-12-17 14:10:59 +01001934 rspadd <string> to add a header to the response
1935 rsprep <search> <replace> to modify the response
1936 rspirep <search> <replace> same, but ignoring the case
1937 rspdel <search> to delete the response
1938 rspidel <search> same, but ignoring the case
willy tarreau982249e2005-12-18 00:57:06 +01001939 rspdeny <search> replaces a response with a HTTP 502 if a header matches <search>
1940 rspideny <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01001941
1942
willy tarreau197e8ec2005-12-17 14:10:59 +01001943<search> is a POSIX regular expression (regex) which supports grouping through
1944parenthesis (without the backslash). Spaces and other delimiters must be
1945prefixed with a backslash ('\') to avoid confusion with a field delimiter.
1946Other characters may be prefixed with a backslash to change their meaning :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001947
willy tarreau197e8ec2005-12-17 14:10:59 +01001948 \t for a tab
1949 \r for a carriage return (CR)
1950 \n for a new line (LF)
1951 \ to mark a space and differentiate it from a delimiter
1952 \# to mark a sharp and differentiate it from a comment
1953 \\ to use a backslash in a regex
1954 \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy)
1955 \xXX to write the ASCII hex code XX as in the C language
willy tarreaueedaa9f2005-12-17 14:08:03 +01001956
1957
willy tarreau197e8ec2005-12-17 14:10:59 +01001958<replace> containst the string to be used to replace the largest portion of text
1959matching the regex. It can make use of the special characters above, and can
1960reference a substring delimited by parenthesis in the regex, by the group
1961numerical order from 1 to 9. In this case, you would write a backslah ('\')
1962immediately followed by one digit indicating the group position.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001963
willy tarreau197e8ec2005-12-17 14:10:59 +01001964<string> represents the string which will systematically be added after the last
1965header line. It can also use special characters above.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001966
willy tarreau197e8ec2005-12-17 14:10:59 +01001967Notes :
1968-------
1969 - the first line is considered as a header, which makes it possible to rewrite
1970 or filter HTTP requests URIs or response codes.
1971 - 'reqrep' is the equivalent of 'cliexp' in version 1.0, and 'rsprep' is the
1972 equivalent of 'srvexp' in 1.0. Those names are still supported but
1973 deprecated.
1974 - for performances reasons, the number of characters added to a request or to
1975 a response is limited to 4096 since version 1.1.5 (it was 256 before). This
1976 value is easy to modify in the code if needed (#define). If it is too short
1977 on occasional uses, it is possible to gain some space by removing some
1978 useless headers before adding new ones.
willy tarreau982249e2005-12-18 00:57:06 +01001979 - a denied request will generate an "HTTP 403 forbidden" response, while a
1980 denied response will generate an "HTTP 502 Bad gateway" response.
1981
willy tarreaueedaa9f2005-12-17 14:08:03 +01001982
willy tarreau197e8ec2005-12-17 14:10:59 +01001983Examples :
1984----------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001985 ###### a few examples ######
willy tarreau197e8ec2005-12-17 14:10:59 +01001986
willy tarreauc5f73ed2005-12-18 01:26:38 +01001987 # rewrite 'online.fr' instead of 'free.fr' for GET and POST requests
1988 reqrep ^(GET\ .*)(.free.fr)(.*) \1.online.fr\3
1989 reqrep ^(POST\ .*)(.free.fr)(.*) \1.online.fr\3
willy tarreau197e8ec2005-12-17 14:10:59 +01001990
willy tarreauc5f73ed2005-12-18 01:26:38 +01001991 # force proxy connections to close
1992 reqirep ^Proxy-Connection:.* Proxy-Connection:\ close
1993 # rewrite locations
1994 rspirep ^(Location:\ )([^:]*://[^/]*)(.*) \1\3
willy tarreaueedaa9f2005-12-17 14:08:03 +01001995
willy tarreauc5f73ed2005-12-18 01:26:38 +01001996 ###### A full configuration being used on production ######
willy tarreaueedaa9f2005-12-17 14:08:03 +01001997
willy tarreau197e8ec2005-12-17 14:10:59 +01001998 # Every header should end with a colon followed by one space.
willy tarreauc5f73ed2005-12-18 01:26:38 +01001999 reqideny ^[^:\ ]*[\ ]*$
willy tarreaueedaa9f2005-12-17 14:08:03 +01002000
willy tarreau197e8ec2005-12-17 14:10:59 +01002001 # block Apache chunk exploit
willy tarreauc5f73ed2005-12-18 01:26:38 +01002002 reqideny ^Transfer-Encoding:[\ ]*chunked
2003 reqideny ^Host:\ apache-
willy tarreaueedaa9f2005-12-17 14:08:03 +01002004
willy tarreau197e8ec2005-12-17 14:10:59 +01002005 # block annoying worms that fill the logs...
willy tarreauc5f73ed2005-12-18 01:26:38 +01002006 reqideny ^[^:\ ]*\ .*(\.|%2e)(\.|%2e)(%2f|%5c|/|\\\\)
2007 reqideny ^[^:\ ]*\ ([^\ ]*\ [^\ ]*\ |.*%00)
2008 reqideny ^[^:\ ]*\ .*<script
2009 reqideny ^[^:\ ]*\ .*/(root\.exe\?|cmd\.exe\?|default\.ida\?)
willy tarreau197e8ec2005-12-17 14:10:59 +01002010
2011 # allow other syntactically valid requests, and block any other method
willy tarreauc5f73ed2005-12-18 01:26:38 +01002012 reqipass ^(GET|POST|HEAD|OPTIONS)\ /.*\ HTTP/1\.[01]$
2013 reqipass ^OPTIONS\ \\*\ HTTP/1\.[01]$
2014 reqideny ^[^:\ ]*\
willy tarreau197e8ec2005-12-17 14:10:59 +01002015
2016 # force connection:close, thus disabling HTTP keep-alive
willy tarreauc5f73ed2005-12-18 01:26:38 +01002017 option httpclose
willy tarreau197e8ec2005-12-17 14:10:59 +01002018
willy tarreauc5f73ed2005-12-18 01:26:38 +01002019 # change the server name
2020 rspidel ^Server:\
2021 rspadd Server:\ Formilux/0.1.8
willy tarreau197e8ec2005-12-17 14:10:59 +01002022
2023
willy tarreau982249e2005-12-18 00:57:06 +01002024Also, the 'forwardfor' option creates an HTTP 'X-Forwarded-For' header which
willy tarreauc1cae632005-12-17 14:12:23 +01002025contains the client's IP address. This is useful to let the final web server
2026know what the client address was (eg for statistics on domains).
2027
willy tarreau982249e2005-12-18 00:57:06 +01002028Last, the 'httpclose' option removes any 'Connection' header both ways, and
2029adds a 'Connection: close' header in each direction. This makes it easier to
Willy TARREAU767ba712006-03-01 22:40:50 +01002030disable HTTP keep-alive than the previous 4-rules block.
willy tarreau982249e2005-12-18 00:57:06 +01002031
willy tarreauc1cae632005-12-17 14:12:23 +01002032Example :
2033---------
2034 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01002035 mode http
2036 log global
2037 option httplog
2038 option dontlognull
2039 option forwardfor
2040 option httpclose
2041
Willy TARREAU767ba712006-03-01 22:40:50 +01002042Note that some HTTP servers do not necessarily close the connections when they
2043receive the 'Connection: close', and if the client does not close either, then
2044the connection will be maintained up to the time-out. This translates into high
2045number of simultaneous sessions and high global session times in the logs. To
2046workaround this, a new option 'forceclose' appeared in version 1.2.9 to enforce
2047the closing of the outgoing server channel as soon as the server begins to
2048reply and only if the request buffer is empty. Note that this should NOT be
2049used if CONNECT requests are expected between the client and the server. The
2050'forceclose' option implies the 'httpclose' option.
2051
2052Example :
2053---------
2054 listen http_proxy 0.0.0.0:80
2055 mode http
2056 log global
2057 option httplog
2058 option dontlognull
2059 option forwardfor
2060 option forceclose
2061
willy tarreau197e8ec2005-12-17 14:10:59 +01002062
20634.4) Load balancing with persistence
2064------------------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01002065Combining cookie insertion with internal load balancing allows to transparently
2066bring persistence to applications. The principle is quite simple :
2067 - assign a cookie value to each server
2068 - enable the load balancing between servers
2069 - insert a cookie into responses resulting from the balancing algorithm
2070 (indirect accesses), end ensure that no upstream proxy will cache it.
2071 - remove the cookie in the request headers so that the application never sees
2072 it.
2073
2074Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002075---------
2076 listen application 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01002077 mode http
2078 cookie SERVERID insert nocache indirect
2079 balance roundrobin
2080 server srv1 192.168.1.1:80 cookie server01 check
2081 server srv2 192.168.1.2:80 cookie server02 check
willy tarreaueedaa9f2005-12-17 14:08:03 +01002082
willy tarreau0174f312005-12-18 01:02:42 +01002083The other solution brought by versions 1.1.30 and 1.2.3 is to reuse a cookie
2084from the server, and prefix the server's name to it. In this case, don't forget
2085to force "httpclose" mode so that you can be assured that every subsequent
2086request will have its cookie fixed.
2087
2088 listen application 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01002089 mode http
2090 cookie JSESSIONID prefix
2091 balance roundrobin
2092 server srv1 192.168.1.1:80 cookie srv1 check
2093 server srv2 192.168.1.2:80 cookie srv2 check
2094 option httpclose
willy tarreau0174f312005-12-18 01:02:42 +01002095
2096
willy tarreau982249e2005-12-18 00:57:06 +010020974.5) Protection against information leak from the servers
2098---------------------------------------------------------
2099In versions 1.1.28/1.2.1, a new option 'checkcache' was created. It carefully
2100checks 'Cache-control', 'Pragma' and 'Set-cookie' headers in server response
2101to check if there's a risk of caching a cookie on a client-side proxy. When this
2102option is enabled, the only responses which can be delivered to the client are :
2103 - all those without 'Set-Cookie' header ;
2104 - all those with a return code other than 200, 203, 206, 300, 301, 410,
2105 provided that the server has not set a 'Cache-control: public' header ;
2106 - all those that come from a POST request, provided that the server has not
2107 set a 'Cache-Control: public' header ;
2108 - those with a 'Pragma: no-cache' header
2109 - those with a 'Cache-control: private' header
2110 - those with a 'Cache-control: no-store' header
2111 - those with a 'Cache-control: max-age=0' header
2112 - those with a 'Cache-control: s-maxage=0' header
2113 - those with a 'Cache-control: no-cache' header
2114 - those with a 'Cache-control: no-cache="set-cookie"' header
2115 - those with a 'Cache-control: no-cache="set-cookie,' header
2116 (allowing other fields after set-cookie)
willy tarreaueedaa9f2005-12-17 14:08:03 +01002117
willy tarreau982249e2005-12-18 00:57:06 +01002118If a response doesn't respect these requirements, then it will be blocked just
2119as if it was from an 'rspdeny' filter, with an "HTTP 502 bad gateway". The
2120session state shows "PH--" meaning that the proxy blocked the response during
2121headers processing. Additionnaly, an alert will be sent in the logs so that
2122admins are told that there's something to be done.
2123
willy tarreauc5f73ed2005-12-18 01:26:38 +01002124
willy tarreau982249e2005-12-18 00:57:06 +010021254.6) Customizing errors
2126-----------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01002127Some situations can make haproxy return an HTTP error code to the client :
2128 - invalid or too long request => HTTP 400
2129 - request not completely sent in time => HTTP 408
2130 - forbidden request (matches a deny filter) => HTTP 403
2131 - internal error in haproxy => HTTP 500
2132 - the server returned an invalid or incomplete response => HTTP 502
2133 - no server was available to handle the request => HTTP 503
2134 - the server failed to reply in time => HTTP 504
willy tarreaueedaa9f2005-12-17 14:08:03 +01002135
willy tarreau197e8ec2005-12-17 14:10:59 +01002136A succint error message taken from the RFC accompanies these return codes.
2137But depending on the clients knowledge, it may be better to return custom, user
2138friendly, error pages. This is made possible through the use of the 'errorloc'
2139command :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002140
willy tarreau197e8ec2005-12-17 14:10:59 +01002141 errorloc <HTTP_code> <location>
willy tarreaueedaa9f2005-12-17 14:08:03 +01002142
willy tarreau197e8ec2005-12-17 14:10:59 +01002143Instead of generating an HTTP error <HTTP_code> among those above, the proxy
2144will return a temporary redirection code (HTTP 302) towards the address
2145specified in <location>. This address may be either relative to the site or
2146absolute. Since this request will be handled by the client's browser, it's
2147mandatory that the returned address be reachable from the outside.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002148
willy tarreau197e8ec2005-12-17 14:10:59 +01002149Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002150---------
2151 listen application 0.0.0.0:80
2152 errorloc 400 /badrequest.html
2153 errorloc 403 /forbidden.html
2154 errorloc 408 /toolong.html
willy tarreauc5f73ed2005-12-18 01:26:38 +01002155 errorloc 500 http://haproxy.domain.net/bugreport.html
willy tarreaueedaa9f2005-12-17 14:08:03 +01002156 errorloc 502 http://192.168.114.58/error50x.html
2157 errorloc 503 http://192.168.114.58/error50x.html
2158 errorloc 504 http://192.168.114.58/error50x.html
2159
willy tarreauc1f47532005-12-18 01:08:26 +01002160Note: RFC2616 says that a client must reuse the same method to fetch the
2161Location returned by a 302, which causes problems with the POST method.
2162The return code 303 was designed explicitly to force the client to fetch the
2163Location URL with the GET method, but there are some browsers pre-dating
2164HTTP/1.1 which don't support it. Anyway, most browsers still behave with 302 as
willy tarreauc5f73ed2005-12-18 01:26:38 +01002165if it was a 303. In order to allow the user to chose, versions 1.1.31 and 1.2.5
2166bring two new keywords to replace 'errorloc' : 'errorloc302' and 'errorloc303'.
willy tarreauc1f47532005-12-18 01:08:26 +01002167
2168They are preffered over errorloc (which still does 302). Consider using
2169errorloc303 everytime you know that your clients support HTTP 303 responses..
2170
2171
willy tarreau982249e2005-12-18 00:57:06 +010021724.7) Modifying default values
willy tarreau197e8ec2005-12-17 14:10:59 +01002173-----------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01002174Version 1.1.22 introduced the notion of default values, which eliminates the
2175pain of often repeating common parameters between many instances, such as
2176logs, timeouts, modes, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01002177
willy tarreau197e8ec2005-12-17 14:10:59 +01002178Default values are set in a 'defaults' section. Each of these section clears
2179all previously set default parameters, so there may be as many default
2180parameters as needed. Only the last one before a 'listen' section will be
2181used for this section. The 'defaults' section uses the same syntax as the
2182'listen' section, for the supported parameters. The 'defaults' keyword ignores
2183everything on its command line, so that fake instance names can be specified
2184there for better clarity.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002185
willy tarreau982249e2005-12-18 00:57:06 +01002186In version 1.1.28/1.2.1, only those parameters can be preset in the 'default'
willy tarreau197e8ec2005-12-17 14:10:59 +01002187section :
2188 - log (the first and second one)
willy tarreaueedaa9f2005-12-17 14:08:03 +01002189 - mode { tcp, http, health }
2190 - balance { roundrobin }
willy tarreau197e8ec2005-12-17 14:10:59 +01002191 - disabled (to disable every further instances)
2192 - enabled (to enable every further instances, this is the default)
willy tarreaueedaa9f2005-12-17 14:08:03 +01002193 - contimeout, clitimeout, srvtimeout, grace, retries, maxconn
willy tarreau982249e2005-12-18 00:57:06 +01002194 - option { redispatch, transparent, keepalive, forwardfor, logasap, httpclose,
2195 checkcache, httplog, tcplog, dontlognull, persist, httpchk }
willy tarreaueedaa9f2005-12-17 14:08:03 +01002196 - redispatch, redisp, transparent, source { addr:port }
2197 - cookie, capture
2198 - errorloc
2199
willy tarreau197e8ec2005-12-17 14:10:59 +01002200As of 1.1.24, it is not possible to put certain parameters in a 'defaults'
2201section, mainly regular expressions and server configurations :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002202 - dispatch, server,
willy tarreau197e8ec2005-12-17 14:10:59 +01002203 - req*, rsp*
willy tarreaueedaa9f2005-12-17 14:08:03 +01002204
willy tarreau197e8ec2005-12-17 14:10:59 +01002205Last, there's no way yet to change a boolean option from its assigned default
2206value. So if an 'option' statement is set in a 'defaults' section, the only
2207way to flush it is to redefine a new 'defaults' section without this 'option'.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002208
willy tarreau197e8ec2005-12-17 14:10:59 +01002209Examples :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002210----------
2211 defaults applications TCP
willy tarreauc5f73ed2005-12-18 01:26:38 +01002212 log global
2213 mode tcp
2214 balance roundrobin
2215 clitimeout 180000
2216 srvtimeout 180000
2217 contimeout 4000
2218 retries 3
2219 redispatch
willy tarreaueedaa9f2005-12-17 14:08:03 +01002220
2221 listen app_tcp1 10.0.0.1:6000-6063
willy tarreauc5f73ed2005-12-18 01:26:38 +01002222 server srv1 192.168.1.1 check port 6000 inter 10000
2223 server srv2 192.168.1.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01002224
2225 listen app_tcp2 10.0.0.2:6000-6063
willy tarreauc5f73ed2005-12-18 01:26:38 +01002226 server srv1 192.168.2.1 check port 6000 inter 10000
2227 server srv2 192.168.2.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01002228
2229 defaults applications HTTP
willy tarreauc5f73ed2005-12-18 01:26:38 +01002230 log global
2231 mode http
2232 option httplog
2233 option forwardfor
2234 option dontlognull
2235 balance roundrobin
2236 clitimeout 20000
2237 srvtimeout 20000
2238 contimeout 4000
2239 retries 3
willy tarreaueedaa9f2005-12-17 14:08:03 +01002240
2241 listen app_http1 10.0.0.1:80-81
willy tarreauc5f73ed2005-12-18 01:26:38 +01002242 cookie SERVERID postonly insert indirect
2243 capture cookie userid= len 10
2244 server srv1 192.168.1.1:+8000 cookie srv1 check port 8080 inter 1000
2245 server srv1 192.168.1.2:+8000 cookie srv2 check port 8080 inter 1000
willy tarreaueedaa9f2005-12-17 14:08:03 +01002246
2247 defaults
willy tarreauc5f73ed2005-12-18 01:26:38 +01002248 # this empty section voids all default parameters
willy tarreaueedaa9f2005-12-17 14:08:03 +01002249
willy tarreau197e8ec2005-12-17 14:10:59 +01002250=========================
2251| System-specific setup |
2252=========================
willy tarreaueedaa9f2005-12-17 14:08:03 +01002253
willy tarreau197e8ec2005-12-17 14:10:59 +01002254Linux 2.4
2255=========
willy tarreaueedaa9f2005-12-17 14:08:03 +01002256
2257-- cut here --
2258#!/bin/sh
2259# set this to about 256/4M (16384 for 256M machine)
2260MAXFILES=16384
2261echo $MAXFILES > /proc/sys/fs/file-max
2262ulimit -n $MAXFILES
2263
2264if [ -e /proc/sys/net/ipv4/ip_conntrack_max ]; then
willy tarreauc5f73ed2005-12-18 01:26:38 +01002265 echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max
willy tarreaueedaa9f2005-12-17 14:08:03 +01002266fi
2267
2268if [ -e /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait ]; then
willy tarreauc5f73ed2005-12-18 01:26:38 +01002269 # 30 seconds for fin, 15 for time wait
2270 echo 3000 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait
2271 echo 1500 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_time_wait
2272 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_invalid_scale
2273 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_out_of_window
willy tarreaueedaa9f2005-12-17 14:08:03 +01002274fi
2275
2276echo 1024 60999 > /proc/sys/net/ipv4/ip_local_port_range
2277echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
2278echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog
2279echo 262144 > /proc/sys/net/ipv4/tcp_max_tw_buckets
2280echo 262144 > /proc/sys/net/ipv4/tcp_max_orphans
2281echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time
2282echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
2283echo 0 > /proc/sys/net/ipv4/tcp_timestamps
2284echo 0 > /proc/sys/net/ipv4/tcp_ecn
willy tarreauc5f73ed2005-12-18 01:26:38 +01002285echo 1 > /proc/sys/net/ipv4/tcp_sack
willy tarreaueedaa9f2005-12-17 14:08:03 +01002286echo 0 > /proc/sys/net/ipv4/tcp_dsack
2287
2288# auto-tuned on 2.4
2289#echo 262143 > /proc/sys/net/core/rmem_max
2290#echo 262143 > /proc/sys/net/core/rmem_default
2291
2292echo 16384 65536 524288 > /proc/sys/net/ipv4/tcp_rmem
2293echo 16384 349520 699040 > /proc/sys/net/ipv4/tcp_wmem
2294
2295-- cut here --
2296
willy tarreau197e8ec2005-12-17 14:10:59 +01002297
2298FreeBSD
2299=======
2300
2301A FreeBSD port of HA-Proxy is now available and maintained, thanks to
2302Clement Laforet <sheepkiller@cultdeadsheep.org>.
2303
2304For more information :
2305http://www.freebsd.org/cgi/url.cgi?ports/net/haproxy/pkg-descr
2306http://www.freebsd.org/cgi/cvsweb.cgi/ports/net/haproxy/
2307http://www.freshports.org/net/haproxy
2308
2309
2310-- end --