blob: 191f136f5832998169347bb1b6198f6b9a7a85fb [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
willy tarreauf76e6ca2006-05-21 21:09:55 +02001219
1220This was so much efficient at reducing the server's response time that some
1221users wanted to use low values to improve their server's performance. However,
1222they were not able anymore to handle very large loads because it was not
1223possible anymore to saturate the servers. For this reason, version 1.2.14 has
1224brought dynamic limitation with the addition of the parameter 'minconn'. When
1225this parameter is set along with maxconn, it will enable dynamic limitation
1226based on the instance's load. The maximum number of concurrent sessions on a
1227server will be proportionnal to the number of sessions on the instance relative
1228to its maxconn. A minimum of <minconn> will be allowed whatever the load. This
1229will ensure that servers will perform at their best level under normal loads,
1230while still handling surges when needed. The dynamic limit is computed like
1231this :
1232
1233 srv.dyn_limit = max(srv.minconn, srv.maxconn * inst.sess / inst.maxconn)
1234
1235Example :
1236---------
1237 # be nice with P3 which only has 256 MB of RAM.
1238 listen web_appl 0.0.0.0:80
1239 maxconn 10000
1240 mode http
1241 cookie SERVERID insert nocache indirect
1242 balance roundrobin
1243 server pentium3-800 192.168.1.1:80 cookie s1 weight 8 minconn 10 maxconn 100 check
1244 server opteron-2.0G 192.168.1.2:80 cookie s2 weight 20 minconn 30 maxconn 300 check
1245 server opteron-2.4G 192.168.1.3:80 cookie s3 weight 24 minconn 30 maxconn 300 check
1246 server web-backup1 192.168.2.1:80 cookie s4 check maxconn 200 backup
1247 server web-excuse 192.168.3.1:80 check backup
1248
1249In the example above, the server 'pentium3-800' will receive at most 100
1250simultaneous sessions when the proxy instance will reach 10000 sessions, and
1251will receive only 10 simultaneous sessions when the proxy will be under 1000
1252sessions.
1253
willy tarreau532bb552006-05-13 18:40:37 +02001254Notes :
1255-------
1256 - The requests will not stay indefinitely in the queue, they follow the
1257 'contimeout' parameter, and if a request cannot be dequeued within this
1258 timeout because the server is saturated or because the queue is filled,
1259 the session will expire with a 503 error.
1260
willy tarreauf76e6ca2006-05-21 21:09:55 +02001261 - if only <minconn> is specified, it has the same effect as <maxconn>
1262
willy tarreau532bb552006-05-13 18:40:37 +02001263 - setting too low values for maxconn might improve performance but might also
1264 allow slow users to block access to the server for other users.
1265
willy tarreau34f45302006-04-15 21:37:14 +02001266
willy tarreaueedaa9f2005-12-17 14:08:03 +010012674) Additionnal features
1268=======================
1269
1270Other features are available. They are transparent mode, event logging and
1271header rewriting/filtering.
1272
willy tarreauc5f73ed2005-12-18 01:26:38 +01001273
willy tarreau0174f312005-12-18 01:02:42 +010012744.1) Network features
willy tarreaueedaa9f2005-12-17 14:08:03 +01001275---------------------
willy tarreau0174f312005-12-18 01:02:42 +010012764.1.1) Transparent mode
1277-----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +01001278In HTTP mode, the 'transparent' keyword allows to intercept sessions which are
1279routed through the system hosting the proxy. This mode was implemented as a
1280replacement for the 'dispatch' mode, since connections without cookie will be
1281sent to the original address while known cookies will be sent to the servers.
1282This mode implies that the system can redirect sessions to a local port.
1283
1284Example :
1285---------
1286 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001287 mode http
1288 transparent
1289 cookie SERVERID
1290 server server01 192.168.1.1:80
1291 server server02 192.168.1.2:80
willy tarreaueedaa9f2005-12-17 14:08:03 +01001292
1293 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
1294 --dport 80 -j REDIRECT --to-ports 65000
1295
1296Note :
1297------
1298If the port is left unspecified on the server, the port the client connected to
1299will be used. This allows to relay a full port range without using transparent
1300mode nor thousands of file descriptors, provided that the system can redirect
1301sessions to local ports.
1302
1303Example :
1304---------
1305 # redirect all ports to local port 65000, then forward to the server on the
1306 # original port.
1307 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001308 mode tcp
1309 server server01 192.168.1.1 check port 60000
1310 server server02 192.168.1.2 check port 60000
willy tarreaueedaa9f2005-12-17 14:08:03 +01001311
1312 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
1313 -j REDIRECT --to-ports 65000
1314
willy tarreau0174f312005-12-18 01:02:42 +010013154.1.2) Per-server source address binding
1316----------------------------------------
1317As of versions 1.1.30 and 1.2.3, it is possible to specify a particular source
1318to reach each server. This is useful when reaching backup servers from a
1319different LAN, or to use an alternate path to reach the same server. It is also
1320usable to provide source load-balancing for outgoing connections. Obviously,
1321the same source address is used to send health-checks.
1322
1323Example :
1324---------
1325 # use a particular source to reach both servers
1326 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001327 mode http
1328 balance roundrobin
1329 server server01 192.168.1.1:80 source 192.168.2.13
1330 server server02 192.168.1.2:80 source 192.168.2.13
willy tarreau0174f312005-12-18 01:02:42 +01001331
1332Example :
1333---------
1334 # use a particular source to reach each servers
1335 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001336 mode http
1337 balance roundrobin
1338 server server01 192.168.1.1:80 source 192.168.1.1
1339 server server02 192.168.2.1:80 source 192.168.2.1
willy tarreau0174f312005-12-18 01:02:42 +01001340
1341Example :
1342---------
1343 # provide source load-balancing to reach the same proxy through 2 WAN links
1344 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001345 mode http
1346 balance roundrobin
1347 server remote-proxy-way1 192.168.1.1:3128 source 192.168.2.1
1348 server remote-proxy-way2 192.168.1.1:3128 source 192.168.3.1
willy tarreau0174f312005-12-18 01:02:42 +01001349
1350Example :
1351---------
1352 # force a TCP connection to bind to a specific port
1353 listen http_proxy 0.0.0.0:2000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001354 mode tcp
1355 balance roundrobin
1356 server srv1 192.168.1.1:80 source 192.168.2.1:20
1357 server srv2 192.168.1.2:80 source 192.168.2.1:20
willy tarreau0174f312005-12-18 01:02:42 +01001358
willy tarreaub952e1d2005-12-18 01:31:20 +010013594.1.3) TCP keep-alive
1360---------------------
1361With version 1.2.7, it becomes possible to enable TCP keep-alives on both the
1362client and server sides. This makes it possible to prevent long sessions from
1363expiring on external layer 4 components such as firewalls and load-balancers.
1364It also allows the system to terminate dead sessions when no timeout has been
1365set (not recommanded). The proxy cannot set the keep-alive probes intervals nor
1366maximal count, consult your operating system manual for this. There are 3
1367options to enable TCP keep-alive :
1368
1369 option tcpka # enables keep-alive both on client and server side
1370 option clitcpka # enables keep-alive only on client side
1371 option srvtcpka # enables keep-alive only on server side
1372
willy tarreaueedaa9f2005-12-17 14:08:03 +01001373
13744.2) Event logging
1375------------------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001376
1377HAProxy's strength certainly lies in its precise logs. It probably provides the
1378finest level of information available for such a product, which is very
1379important for troubleshooting complex environments. Standard log information
1380include client ports, TCP/HTTP state timers, precise session state at
1381termination and precise termination cause, information about decisions to
1382direct trafic to a server, and of course the ability to capture arbitrary
1383headers.
1384
1385In order to improve administrators reactivity, it offers a great transparency
1386about encountered problems, both internal and external, and it is possible to
1387send logs to different sources at the same time with different level filters :
1388
1389 - global process-level logs (system errors, start/stop, etc..)
1390 - per-listener system and internal errors (lack of resource, bugs, ...)
1391 - per-listener external troubles (servers up/down, max connections)
1392 - per-listener activity (client connections), either at the establishment or
1393 at the termination.
1394
1395The ability to distribute different levels of logs to different log servers
1396allow several production teams to interact and to fix their problems as soon
1397as possible. For example, the system team might monitor system-wide errors,
1398while the application team might be monitoring the up/down for their servers in
1399real time, and the security team might analyze the activity logs with one hour
1400delay.
1401
willy tarreauc1cae632005-12-17 14:12:23 +010014024.2.1) Log levels
1403-----------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001404TCP and HTTP connections can be logged with informations such as date, time,
1405source IP address, destination address, connection duration, response times,
1406HTTP request, the HTTP return code, number of bytes transmitted, the conditions
1407in which the session ended, and even exchanged cookies values, to track a
1408particular user's problems for example. All messages are sent to up to two
1409syslog servers. Consult section 1.1 for more info about log facilities. The
1410syntax follows :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001411
willy tarreau197e8ec2005-12-17 14:10:59 +01001412 log <address_1> <facility_1> [max_level_1]
1413 log <address_2> <facility_2> [max_level_2]
1414or
willy tarreaueedaa9f2005-12-17 14:08:03 +01001415 log global
1416
willy tarreau197e8ec2005-12-17 14:10:59 +01001417Note :
1418------
1419The particular syntax 'log global' means that the same log configuration as the
1420'global' section will be used.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001421
willy tarreau197e8ec2005-12-17 14:10:59 +01001422Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001423---------
1424 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001425 mode http
1426 log 192.168.2.200 local3
1427 log 192.168.2.201 local4
willy tarreaueedaa9f2005-12-17 14:08:03 +01001428
willy tarreauc1cae632005-12-17 14:12:23 +010014294.2.2) Log format
1430-----------------
1431By default, connections are logged at the TCP level, as soon as the session
1432establishes between the client and the proxy. By enabling the 'tcplog' option,
1433the proxy will wait until the session ends to generate an enhanced log
1434containing more information such as session duration and its state during the
willy tarreau532bb552006-05-13 18:40:37 +02001435disconnection. The number of remaining session after disconnection is also
1436indicated (for the server, the listener, and the process).
willy tarreauc1cae632005-12-17 14:12:23 +01001437
willy tarreauc5f73ed2005-12-18 01:26:38 +01001438Example of TCP logging :
1439------------------------
willy tarreau982249e2005-12-18 00:57:06 +01001440 listen relais-tcp 0.0.0.0:8000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001441 mode tcp
1442 option tcplog
1443 log 192.168.2.200 local3
willy tarreau982249e2005-12-18 00:57:06 +01001444
willy tarreau532bb552006-05-13 18:40:37 +02001445>>> 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 +01001446
willy tarreau532bb552006-05-13 18:40:37 +02001447 Field Format Example
willy tarreauc5f73ed2005-12-18 01:26:38 +01001448
willy tarreau532bb552006-05-13 18:40:37 +02001449 1 process_name '[' pid ']:' haproxy[18989]:
1450 2 client_ip ':' client_port 127.0.0.1:34550
1451 3 '[' date ']' [15/Oct/2003:15:24:28]
1452 4 listener_name relais-tcp
1453 5 server_name Srv1
1454 6 queue_time '/' connect_time '/' total_time 0/0/5007
1455 7 bytes_read 0
1456 8 termination_state --
1457 9 srv_conn '/' listener_conn '/' process_conn 1/1/1
1458 10 position in srv_queue / listener_queue 0/0
1459
willy tarreau982249e2005-12-18 00:57:06 +01001460
willy tarreauc1cae632005-12-17 14:12:23 +01001461Another option, 'httplog', provides more detailed information about HTTP
1462contents, such as the request and some cookies. In the event where an external
1463component would establish frequent connections to check the service, logs may be
1464full of useless lines. So it is possible not to log any session which didn't
1465transfer any data, by the setting of the 'dontlognull' option. This only has
1466effect on sessions which are established then closed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001467
willy tarreauc5f73ed2005-12-18 01:26:38 +01001468Example of HTTP logging :
1469-------------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +01001470 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001471 mode http
1472 option httplog
1473 option dontlognull
1474 log 192.168.2.200 local3
1475
willy tarreau532bb552006-05-13 18:40:37 +02001476>>> 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 +01001477
willy tarreauc5f73ed2005-12-18 01:26:38 +01001478More complete example
willy tarreau532bb552006-05-13 18:40:37 +02001479 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 +01001480
willy tarreau532bb552006-05-13 18:40:37 +02001481 Field Format Example
willy tarreauc5f73ed2005-12-18 01:26:38 +01001482
willy tarreau532bb552006-05-13 18:40:37 +02001483 1 process_name '[' pid ']:' haproxy[18989]:
1484 2 client_ip ':' client_port 10.0.0.1:34552
1485 3 '[' date ']' [15/Oct/2003:15:26:31]
1486 4 listener_name relais-http
1487 5 server_name Srv1
1488 6 Tq '/' Tw '/' Tc '/' Tr '/' Tt 3183/-1/-1/-1/11215
1489 7 HTTP_return_code 503
1490 8 bytes_read 0
1491 9 captured_request_cookie -
1492 10 captured_response_cookie -
1493 11 termination_state SC--
1494 12 srv_conn '/' listener_conn '/' process_conn 137/202/205
1495 13 position in srv_queue / listener_queue 0/0
1496 14 '{' captured_request_headers '}' {w.ods.org|Mozilla}
1497 15 '{' captured_response_headers '}' {}
1498 16 '"' HTTP_request '"' "HEAD / HTTP/1.0"
willy tarreauc5f73ed2005-12-18 01:26:38 +01001499
1500Note for log parsers: the URI is ALWAYS the end of the line starting with the
1501 first double quote '"'.
willy tarreau982249e2005-12-18 00:57:06 +01001502
1503The problem when logging at end of connection is that you have no clue about
1504what is happening during very long sessions. To workaround this problem, a
1505new option 'logasap' has been introduced in 1.1.28/1.2.1. When specified, the
1506proxy will log as soon as possible, just before data transfer begins. This means
1507that in case of TCP, it will still log the connection status to the server, and
1508in case of HTTP, it will log just after processing the server headers. In this
1509case, the number of bytes reported is the number of header bytes sent to the
1510client.
1511
1512In order to avoid confusion with normal logs, the total time field and the
1513number of bytes are prefixed with a '+' sign which mean that real numbers are
1514certainly bigger.
1515
1516Example :
1517---------
1518
1519 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001520 mode http
1521 option httplog
1522 option dontlognull
1523 option logasap
1524 log 192.168.2.200 local3
willy tarreau982249e2005-12-18 00:57:06 +01001525
willy tarreau532bb552006-05-13 18:40:37 +02001526>>> 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 +01001527
willy tarreauc1cae632005-12-17 14:12:23 +010015284.2.3) Timing events
1529--------------------
1530Timers provide a great help in trouble shooting network problems. All values
1531are reported in milliseconds (ms). In HTTP mode, four control points are
willy tarreau532bb552006-05-13 18:40:37 +02001532reported under the form 'Tq/Tw/Tc/Tr/Tt' :
willy tarreauc1cae632005-12-17 14:12:23 +01001533
1534 - Tq: total time to get the client request.
1535 It's the time elapsed between the moment the client connection was accepted
1536 and the moment the proxy received the last HTTP header. The value '-1'
1537 indicates that the end of headers (empty line) has never been seen.
1538
willy tarreau532bb552006-05-13 18:40:37 +02001539 - Tw: total time spent in the queues waiting for a connection slot. It
1540 accounts for listener's queue as well as the server's queue, and depends
1541 on the queue size, and the time needed for the server to complete previous
1542 sessions. The value '-1' means that the request was killed before reaching
1543 the queue.
1544
willy tarreauc1cae632005-12-17 14:12:23 +01001545 - Tc: total time to establish the TCP connection to the server.
1546 It's the time elapsed between the moment the proxy sent the connection
1547 request, and the moment it was acknowledged, or between the TCP SYN packet
1548 and the matching SYN/ACK in return. The value '-1' means that the
1549 connection never established.
1550
1551 - Tr: server response time. It's the time elapsed between the moment the
1552 TCP connection was established to the server and the moment it send its
1553 complete response header. It purely shows its request processing time,
1554 without the network overhead due to the data transmission. The value '-1'
1555 means that the last the response header (empty line) was never seen.
1556
1557 - Tt: total session duration time, between the moment the proxy accepted it
willy tarreau982249e2005-12-18 00:57:06 +01001558 and the moment both ends were closed. The exception is when the 'logasap'
willy tarreau532bb552006-05-13 18:40:37 +02001559 option is specified. In this case, it only equals (Tq+Tw+Tc+Tr), and is
willy tarreau982249e2005-12-18 00:57:06 +01001560 prefixed with a '+' sign. From this field, we can deduce Td, the data
1561 transmission time, by substracting other timers when valid :
willy tarreauc1cae632005-12-17 14:12:23 +01001562
willy tarreau532bb552006-05-13 18:40:37 +02001563 Td = Tt - (Tq + Tw + Tc + Tr)
willy tarreauc1cae632005-12-17 14:12:23 +01001564
1565 Timers with '-1' values have to be excluded from this equation.
1566
willy tarreau532bb552006-05-13 18:40:37 +02001567In TCP mode ('option tcplog'), only Tw, Tc and Tt are reported.
willy tarreauc1cae632005-12-17 14:12:23 +01001568
1569These timers provide precious indications on trouble causes. Since the TCP
1570protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure
1571that timers close to multiples of 3s are nearly always related to packets lost
1572due to network problems (wires or negociation). Moreover, if <Tt> is close to
1573a timeout value specified in the configuration, it often means that a session
1574has been aborted on time-out.
1575
1576Most common cases :
1577
1578 - If Tq is close to 3000, a packet has probably been lost between the client
1579 and the proxy.
1580 - If Tc is close to 3000, a packet has probably been lost between the server
1581 and the proxy during the server connection phase. This one should always be
1582 very low (less than a few tens).
1583 - If Tr is nearly always lower than 3000 except some rare values which seem to
1584 be the average majored by 3000, there are probably some packets lost between
1585 the proxy and the server.
1586 - If Tt is often slightly higher than a time-out, it's often because the
1587 client and the server use HTTP keep-alive and the session is maintained
1588 after the response ends. Se further for how to disable HTTP keep-alive.
1589
1590Other cases ('xx' means any value to be ignored) :
willy tarreau532bb552006-05-13 18:40:37 +02001591 -1/xx/xx/xx/Tt: the client was not able to send its complete request in time,
1592 or that it aborted it too early.
1593 Tq/-1/xx/xx/Tt: it was not possible to process the request, maybe because
1594 servers were out of order.
1595 Tq/Tw/-1/xx/Tt: the connection could not establish on the server. Either it
1596 refused it or it timed out after Tt-(Tq+Tw) ms.
1597 Tq/Tw/Tc/-1/Tt: the server has accepted the connection but did not return a
1598 complete response in time, or it closed its connexion
1599 unexpectedly, after Tt-(Tq+Tw+Tc) ms.
willy tarreauc1cae632005-12-17 14:12:23 +01001600
16014.2.4) Session state at disconnection
1602-------------------------------------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001603TCP and HTTP logs provide a session completion indicator in the
1604<termination_state> field, just before the number of active
1605connections. It is 2-characters long in TCP, and 4-characters long in
1606HTTP, each of which has a special meaning :
1607
willy tarreau197e8ec2005-12-17 14:10:59 +01001608 - On the first character, a code reporting the first event which caused the
1609 session to terminate :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001610
willy tarreauc5f73ed2005-12-18 01:26:38 +01001611 C : the TCP session was unexpectedly aborted by the client.
1612
1613 S : the TCP session was unexpectedly aborted by the server, or the
1614 server explicitly refused it.
1615
1616 P : the session was prematurely aborted by the proxy, because of a
1617 connection limit enforcement, because a DENY filter was matched,
1618 or because of a security check which detected and blocked a
1619 dangerous error in server response which might have caused
1620 information leak (eg: cacheable cookie).
1621
1622 R : a resource on the proxy has been exhausted (memory, sockets, source
1623 ports, ...). Usually, this appears during the connection phase, and
1624 system logs should contain a copy of the precise error.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001625
willy tarreauc5f73ed2005-12-18 01:26:38 +01001626 I : an internal error was identified by the proxy during a self-check.
1627 This should NEVER happen, and you are encouraged to report any log
1628 containing this, because this is a bug.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001629
willy tarreauc5f73ed2005-12-18 01:26:38 +01001630 c : the client-side time-out expired first.
1631
1632 s : the server-side time-out expired first.
1633
1634 - : normal session completion.
1635
1636 - on the second character, the TCP/HTTP session state when it was closed :
1637
1638 R : waiting for complete REQUEST from the client (HTTP only). Nothing
1639 was sent to any server.
1640
willy tarreau532bb552006-05-13 18:40:37 +02001641 Q : waiting in the QUEUE for a connection slot. This can only happen on
1642 servers which have a 'maxconn' parameter set. No connection attempt
1643 was made to any server.
1644
willy tarreauc5f73ed2005-12-18 01:26:38 +01001645 C : waiting for CONNECTION to establish on the server. The server might
1646 at most have noticed a connection attempt.
1647
1648 H : waiting for, receiving and processing server HEADERS (HTTP only).
1649
1650 D : the session was in the DATA phase.
1651
1652 L : the proxy was still transmitting LAST data to the client while the
1653 server had already finished.
1654
1655 - : normal session completion after end of data transfer.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001656
willy tarreau197e8ec2005-12-17 14:10:59 +01001657 - the third character tells whether the persistence cookie was provided by
willy tarreauc1cae632005-12-17 14:12:23 +01001658 the client (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001659
willy tarreauc5f73ed2005-12-18 01:26:38 +01001660 N : the client provided NO cookie. This is usually the case on new
1661 connections.
1662
1663 I : the client provided an INVALID cookie matching no known
1664 server. This might be caused by a recent configuration change,
1665 mixed cookies between HTTP/HTTPS sites, or an attack.
1666
1667 D : the client provided a cookie designating a server which was DOWN,
1668 so either the 'persist' option was used and the client was sent to
1669 this server, or it was not set and the client was redispatched to
1670 another server.
1671
1672 V : the client provided a valid cookie, and was sent to the associated
1673 server.
1674
1675 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001676
willy tarreau197e8ec2005-12-17 14:10:59 +01001677 - the last character reports what operations were performed on the persistence
willy tarreauc1cae632005-12-17 14:12:23 +01001678 cookie returned by the server (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001679
willy tarreauc5f73ed2005-12-18 01:26:38 +01001680 N : NO cookie was provided by the server, and none was inserted either.
1681
1682 I : no cookie was provided by the server, and the proxy INSERTED one.
1683
willy tarreau197e8ec2005-12-17 14:10:59 +01001684 P : a cookie was PROVIDED by the server and transmitted as-is.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001685
willy tarreauc5f73ed2005-12-18 01:26:38 +01001686 R : the cookie provided by the server was REWRITTEN by the proxy.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001687
willy tarreauc5f73ed2005-12-18 01:26:38 +01001688 D : the cookie provided by the server was DELETED by the proxy.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001689
willy tarreauc5f73ed2005-12-18 01:26:38 +01001690 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001691
willy tarreauc5f73ed2005-12-18 01:26:38 +01001692The combination of the two first flags give a lot of information about what was
1693happening when the session terminated. It can be helpful to detect server
1694saturation, network troubles, local system resource starvation, attacks, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01001695
willy tarreauc5f73ed2005-12-18 01:26:38 +01001696The most common termination flags combinations are indicated here.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001697
willy tarreauc5f73ed2005-12-18 01:26:38 +01001698 Flags Reason
1699 CR The client aborted before sending a full request. Most probably the
1700 request was done by hand using a telnet client, and aborted early.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001701
willy tarreauc5f73ed2005-12-18 01:26:38 +01001702 cR The client timed out before sending a full request. This is sometimes
1703 caused by too large TCP MSS values on the client side for PPPoE
1704 networks which cannot transport full-sized packets, or by clients
1705 sending requests by hand and not typing fast enough.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001706
willy tarreauc5f73ed2005-12-18 01:26:38 +01001707 SC The server explicitly refused the connection (the proxy received a
1708 TCP RST or an ICMP in return). Under some circumstances, it can
1709 also be the network stack telling the proxy that the server is
1710 unreachable (eg: no route, or no ARP response on local network).
willy tarreau982249e2005-12-18 00:57:06 +01001711
willy tarreauc5f73ed2005-12-18 01:26:38 +01001712 sC The connection to the server did not complete during contimeout.
willy tarreau982249e2005-12-18 00:57:06 +01001713
willy tarreauc5f73ed2005-12-18 01:26:38 +01001714 PC The proxy refused to establish a connection to the server because the
1715 maxconn limit has been reached. The listener's maxconn parameter may
1716 be increased in the proxy configuration, as well as the global
1717 maxconn parameter.
willy tarreauc1cae632005-12-17 14:12:23 +01001718
willy tarreauc5f73ed2005-12-18 01:26:38 +01001719 RC A local resource has been exhausted (memory, sockets, source ports)
1720 preventing the connection to the server from establishing. The error
1721 logs will tell precisely what was missing. Anyway, this can only be
1722 solved by system tuning.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001723
willy tarreauc5f73ed2005-12-18 01:26:38 +01001724 cH The client timed out during a POST request. This is sometimes caused
1725 by too large TCP MSS values for PPPoE networks which cannot transport
1726 full-sized packets.
willy tarreauc1cae632005-12-17 14:12:23 +01001727
willy tarreau078c79a2006-05-13 12:23:58 +02001728 CH The client aborted while waiting for the server to start responding.
1729 It might be the server taking too long to respond or the client
1730 clicking the 'Stop' button too fast.
1731
1732 CQ The client aborted while its session was queued, waiting for a server
1733 with enough empty slots to accept it. It might be that either all the
1734 servers were saturated or the assigned server taking too long to
1735 respond.
1736
1737 sQ The session spent too much time in queue and has been expired.
1738
willy tarreauc5f73ed2005-12-18 01:26:38 +01001739 SH The server aborted before sending its full headers, or it crashed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001740
willy tarreauc5f73ed2005-12-18 01:26:38 +01001741 sH The server failed to reply during the srvtimeout delay, which
1742 indicates too long transactions, probably caused by back-end
1743 saturation. The only solutions are to fix the problem on the
1744 application or to increase the 'srvtimeout' parameter to support
1745 longer delays (at the risk of the client giving up anyway).
1746
1747 PR The proxy blocked the client's request, either because of an invalid
1748 HTTP syntax, in which case it returned an HTTP 400 error to the
1749 client, or because a deny filter matched, in which case it returned
1750 an HTTP 403 error.
1751
1752 PH The proxy blocked the server's response, because it was invalid,
1753 incomplete, dangerous (cache control), or matched a security filter.
1754 In any case, an HTTP 502 error is sent to the client.
1755
1756 cD The client did not read any data for as long as the clitimeout delay.
1757 This is often caused by network failures on the client side.
1758
1759 CD The client unexpectedly aborted during data transfer. This is either
1760 caused by a browser crash, or by a keep-alive session between the
1761 server and the client terminated first by the client.
1762
1763 sD The server did nothing during the srvtimeout delay. This is often
1764 caused by too short timeouts on L4 equipements before the server
1765 (firewalls, load-balancers, ...).
1766
17674.2.5) Non-printable characters
willy tarreau4302f492005-12-18 01:00:37 +01001768-------------------------------
1769As of version 1.1.29, non-printable characters are not sent as-is into log
1770files, but are converted to their two-digits hexadecimal representation,
1771prefixed by the character '#'. The only characters that can now be logged
1772without being escaped are between 32 and 126 (inclusive). Obviously, the
1773escape character '#' is also encoded to avoid any ambiguity. It is the same for
1774the character '"', as well as '{', '|' and '}' when logging headers.
1775
willy tarreauc5f73ed2005-12-18 01:26:38 +010017764.2.6) Capturing HTTP headers and cookies
1777-----------------------------------------
1778Version 1.1.23 brought cookie capture, and 1.1.29 the header capture. All this
1779is performed using the 'capture' keyword.
1780
1781Cookie capture makes it easy to track a complete user session. The syntax is :
1782
1783 capture cookie <cookie_prefix> len <capture_length>
1784
1785This will enable cookie capture from both requests and responses. This way,
1786it's easy to detect when a user switches to a new session for example, because
1787the server will reassign it a new cookie.
1788
1789The FIRST cookie whose name starts with <cookie_prefix> will be captured, and
1790logged as 'NAME=value', without exceeding <capture_length> characters (64 max).
1791When the cookie name is fixed and known, it's preferable to suffix '=' to it to
1792ensure that no other cookie will be logged.
1793
1794Examples :
1795----------
1796 # capture the first cookie whose name starts with "ASPSESSION"
1797 capture cookie ASPSESSION len 32
1798
1799 # capture the first cookie whose name is exactly "vgnvisitor"
1800 capture cookie vgnvisitor= len 32
1801
1802In the logs, the field preceeding the completion indicator contains the cookie
1803value as sent by the server, preceeded by the cookie value as sent by the
1804client. Each of these field is replaced with '-' when no cookie was seen or
1805when the option is disabled.
1806
1807Header captures have a different goal. They are useful to track unique request
1808identifiers set by a previous proxy, virtual host names, user-agents, POST
1809content-length, referrers, etc. In the response, one can search for information
1810about the response length, how the server asked the cache to behave, or an
1811object location during a redirection. As for cookie captures, it is both
1812possible to include request headers and response headers at the same time. The
1813syntax is :
willy tarreau4302f492005-12-18 01:00:37 +01001814
1815 capture request header <name> len <max length>
1816 capture response header <name> len <max length>
1817
1818Note: Header names are not case-sensitive.
1819
1820Examples:
1821---------
1822 # keep the name of the virtual server
1823 capture request header Host len 20
1824 # keep the amount of data uploaded during a POST
1825 capture request header Content-Length len 10
1826
1827 # note the expected cache behaviour on the response
1828 capture response header Cache-Control len 8
1829 # note the URL location during a redirection
1830 capture response header Location len 20
1831
1832Non-existant headers are logged as empty strings, and if one header appears more
1833than once, only its last occurence will be kept. Request headers are grouped
1834within braces '{' and '}' in the same order as they were declared, and delimited
1835with a vertical bar '|' without any space. Response headers follow the same
1836representation, but are displayed after a space following the request headers
1837block. These blocks are displayed just before the HTTP request in the logs.
willy tarreauc5f73ed2005-12-18 01:26:38 +01001838
willy tarreau4302f492005-12-18 01:00:37 +01001839Example :
1840
willy tarreauc5f73ed2005-12-18 01:26:38 +01001841 Config:
1842
1843 capture request header Host len 20
1844 capture request header Content-Length len 10
1845 capture request header Referer len 20
1846 capture response header Server len 20
1847 capture response header Content-Length len 10
1848 capture response header Cache-Control len 8
1849 capture response header Via len 20
1850 capture response header Location len 20
1851
1852 Log :
1853
willy tarreau532bb552006-05-13 18:40:37 +02001854 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/"
1855 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"
1856 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 +01001857
1858
18594.2.7) Examples of logs
1860-----------------------
willy tarreau532bb552006-05-13 18:40:37 +02001861- 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 +01001862 => long request (6.5s) entered by hand through 'telnet'. The server replied
1863 in 147 ms, and the session ended normally ('----')
1864
willy tarreau532bb552006-05-13 18:40:37 +02001865- 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"
1866 => Idem, but the request was queued in the global queue behind 9 other
1867 requests, and waited there for 1230 ms.
1868
1869- 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 +01001870 => request for a long data transfer. The 'logasap' option was specified, so
1871 the log was produced just before transfering data. The server replied in
1872 14 ms, 243 bytes of headers were sent to the client, and total time from
1873 accept to first data byte is 30 ms.
1874
willy tarreau532bb552006-05-13 18:40:37 +02001875- 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 +01001876 => the proxy blocked a server response either because of an 'rspdeny' or
1877 'rspideny' filter, or because it blocked sensible information which risked
1878 being cached. In this case, the response is replaced with a '502 bad
1879 gateway'.
1880
willy tarreau532bb552006-05-13 18:40:37 +02001881- 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 +01001882 => the client never completed its request and aborted itself ('C---') after
1883 8.5s, while the proxy was waiting for the request headers ('-R--').
1884 Nothing was sent to the server.
1885
willy tarreau532bb552006-05-13 18:40:37 +02001886- 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 +01001887 => The client never completed its request, which was aborted by the time-out
1888 ('c---') after 50s, while the proxy was waiting for the request headers ('-R--').
1889 Nothing was sent to the server, but the proxy could send a 408 return code
1890 to the client.
willy tarreau4302f492005-12-18 01:00:37 +01001891
willy tarreau532bb552006-05-13 18:40:37 +02001892- 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 +01001893 => This is a 'tcplog' entry. Client-side time-out ('c----') occured after 5s.
willy tarreau4302f492005-12-18 01:00:37 +01001894
willy tarreau532bb552006-05-13 18:40:37 +02001895- 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 +01001896 => The request took 3s to complete (probably a network problem), and the
1897 connection to the server failed ('SC--') after 4 attemps of 2 seconds
1898 (config says 'retries 3'), then a 503 error code was sent to the client.
willy tarreau532bb552006-05-13 18:40:37 +02001899 There were 115 connections on this server, 202 connections on this proxy,
1900 and 205 on the global process. It is possible that the server refused the
1901 connection because of too many already established.
willy tarreau4302f492005-12-18 01:00:37 +01001902
willy tarreau4302f492005-12-18 01:00:37 +01001903
willy tarreau197e8ec2005-12-17 14:10:59 +010019044.3) HTTP header manipulation
1905-----------------------------
1906In HTTP mode, it is possible to rewrite, add or delete some of the request and
1907response headers based on regular expressions. It is also possible to block a
1908request or a response if a particular header matches a regular expression,
1909which is enough to stops most elementary protocol attacks, and to protect
1910against information leak from the internal network. But there is a limitation
1911to this : since haproxy's HTTP engine knows nothing about keep-alive, only
1912headers passed during the first request of a TCP session will be seen. All
1913subsequent headers will be considered data only and not analyzed. Furthermore,
1914haproxy doesn't touch data contents, it stops at the end of headers.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001915
willy tarreau197e8ec2005-12-17 14:10:59 +01001916The syntax is :
1917 reqadd <string> to add a header to the request
1918 reqrep <search> <replace> to modify the request
1919 reqirep <search> <replace> same, but ignoring the case
1920 reqdel <search> to delete a header in the request
1921 reqidel <search> same, but ignoring the case
1922 reqallow <search> definitely allow a request if a header matches <search>
1923 reqiallow <search> same, but ignoring the case
1924 reqdeny <search> denies a request if a header matches <search>
1925 reqideny <search> same, but ignoring the case
1926 reqpass <search> ignore a header matching <search>
1927 reqipass <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01001928
willy tarreau197e8ec2005-12-17 14:10:59 +01001929 rspadd <string> to add a header to the response
1930 rsprep <search> <replace> to modify the response
1931 rspirep <search> <replace> same, but ignoring the case
1932 rspdel <search> to delete the response
1933 rspidel <search> same, but ignoring the case
willy tarreau982249e2005-12-18 00:57:06 +01001934 rspdeny <search> replaces a response with a HTTP 502 if a header matches <search>
1935 rspideny <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01001936
1937
willy tarreau197e8ec2005-12-17 14:10:59 +01001938<search> is a POSIX regular expression (regex) which supports grouping through
1939parenthesis (without the backslash). Spaces and other delimiters must be
1940prefixed with a backslash ('\') to avoid confusion with a field delimiter.
1941Other characters may be prefixed with a backslash to change their meaning :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001942
willy tarreau197e8ec2005-12-17 14:10:59 +01001943 \t for a tab
1944 \r for a carriage return (CR)
1945 \n for a new line (LF)
1946 \ to mark a space and differentiate it from a delimiter
1947 \# to mark a sharp and differentiate it from a comment
1948 \\ to use a backslash in a regex
1949 \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy)
1950 \xXX to write the ASCII hex code XX as in the C language
willy tarreaueedaa9f2005-12-17 14:08:03 +01001951
1952
willy tarreau197e8ec2005-12-17 14:10:59 +01001953<replace> containst the string to be used to replace the largest portion of text
1954matching the regex. It can make use of the special characters above, and can
1955reference a substring delimited by parenthesis in the regex, by the group
1956numerical order from 1 to 9. In this case, you would write a backslah ('\')
1957immediately followed by one digit indicating the group position.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001958
willy tarreau197e8ec2005-12-17 14:10:59 +01001959<string> represents the string which will systematically be added after the last
1960header line. It can also use special characters above.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001961
willy tarreau197e8ec2005-12-17 14:10:59 +01001962Notes :
1963-------
1964 - the first line is considered as a header, which makes it possible to rewrite
1965 or filter HTTP requests URIs or response codes.
1966 - 'reqrep' is the equivalent of 'cliexp' in version 1.0, and 'rsprep' is the
1967 equivalent of 'srvexp' in 1.0. Those names are still supported but
1968 deprecated.
1969 - for performances reasons, the number of characters added to a request or to
1970 a response is limited to 4096 since version 1.1.5 (it was 256 before). This
1971 value is easy to modify in the code if needed (#define). If it is too short
1972 on occasional uses, it is possible to gain some space by removing some
1973 useless headers before adding new ones.
willy tarreau982249e2005-12-18 00:57:06 +01001974 - a denied request will generate an "HTTP 403 forbidden" response, while a
1975 denied response will generate an "HTTP 502 Bad gateway" response.
1976
willy tarreaueedaa9f2005-12-17 14:08:03 +01001977
willy tarreau197e8ec2005-12-17 14:10:59 +01001978Examples :
1979----------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001980 ###### a few examples ######
willy tarreau197e8ec2005-12-17 14:10:59 +01001981
willy tarreauc5f73ed2005-12-18 01:26:38 +01001982 # rewrite 'online.fr' instead of 'free.fr' for GET and POST requests
1983 reqrep ^(GET\ .*)(.free.fr)(.*) \1.online.fr\3
1984 reqrep ^(POST\ .*)(.free.fr)(.*) \1.online.fr\3
willy tarreau197e8ec2005-12-17 14:10:59 +01001985
willy tarreauc5f73ed2005-12-18 01:26:38 +01001986 # force proxy connections to close
1987 reqirep ^Proxy-Connection:.* Proxy-Connection:\ close
1988 # rewrite locations
1989 rspirep ^(Location:\ )([^:]*://[^/]*)(.*) \1\3
willy tarreaueedaa9f2005-12-17 14:08:03 +01001990
willy tarreauc5f73ed2005-12-18 01:26:38 +01001991 ###### A full configuration being used on production ######
willy tarreaueedaa9f2005-12-17 14:08:03 +01001992
willy tarreau197e8ec2005-12-17 14:10:59 +01001993 # Every header should end with a colon followed by one space.
willy tarreauc5f73ed2005-12-18 01:26:38 +01001994 reqideny ^[^:\ ]*[\ ]*$
willy tarreaueedaa9f2005-12-17 14:08:03 +01001995
willy tarreau197e8ec2005-12-17 14:10:59 +01001996 # block Apache chunk exploit
willy tarreauc5f73ed2005-12-18 01:26:38 +01001997 reqideny ^Transfer-Encoding:[\ ]*chunked
1998 reqideny ^Host:\ apache-
willy tarreaueedaa9f2005-12-17 14:08:03 +01001999
willy tarreau197e8ec2005-12-17 14:10:59 +01002000 # block annoying worms that fill the logs...
willy tarreauc5f73ed2005-12-18 01:26:38 +01002001 reqideny ^[^:\ ]*\ .*(\.|%2e)(\.|%2e)(%2f|%5c|/|\\\\)
2002 reqideny ^[^:\ ]*\ ([^\ ]*\ [^\ ]*\ |.*%00)
2003 reqideny ^[^:\ ]*\ .*<script
2004 reqideny ^[^:\ ]*\ .*/(root\.exe\?|cmd\.exe\?|default\.ida\?)
willy tarreau197e8ec2005-12-17 14:10:59 +01002005
2006 # allow other syntactically valid requests, and block any other method
willy tarreauc5f73ed2005-12-18 01:26:38 +01002007 reqipass ^(GET|POST|HEAD|OPTIONS)\ /.*\ HTTP/1\.[01]$
2008 reqipass ^OPTIONS\ \\*\ HTTP/1\.[01]$
2009 reqideny ^[^:\ ]*\
willy tarreau197e8ec2005-12-17 14:10:59 +01002010
2011 # force connection:close, thus disabling HTTP keep-alive
willy tarreauc5f73ed2005-12-18 01:26:38 +01002012 option httpclose
willy tarreau197e8ec2005-12-17 14:10:59 +01002013
willy tarreauc5f73ed2005-12-18 01:26:38 +01002014 # change the server name
2015 rspidel ^Server:\
2016 rspadd Server:\ Formilux/0.1.8
willy tarreau197e8ec2005-12-17 14:10:59 +01002017
2018
willy tarreau982249e2005-12-18 00:57:06 +01002019Also, the 'forwardfor' option creates an HTTP 'X-Forwarded-For' header which
willy tarreauc1cae632005-12-17 14:12:23 +01002020contains the client's IP address. This is useful to let the final web server
2021know what the client address was (eg for statistics on domains).
2022
willy tarreau982249e2005-12-18 00:57:06 +01002023Last, the 'httpclose' option removes any 'Connection' header both ways, and
2024adds a 'Connection: close' header in each direction. This makes it easier to
Willy TARREAU767ba712006-03-01 22:40:50 +01002025disable HTTP keep-alive than the previous 4-rules block.
willy tarreau982249e2005-12-18 00:57:06 +01002026
willy tarreauc1cae632005-12-17 14:12:23 +01002027Example :
2028---------
2029 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01002030 mode http
2031 log global
2032 option httplog
2033 option dontlognull
2034 option forwardfor
2035 option httpclose
2036
Willy TARREAU767ba712006-03-01 22:40:50 +01002037Note that some HTTP servers do not necessarily close the connections when they
2038receive the 'Connection: close', and if the client does not close either, then
2039the connection will be maintained up to the time-out. This translates into high
2040number of simultaneous sessions and high global session times in the logs. To
2041workaround this, a new option 'forceclose' appeared in version 1.2.9 to enforce
2042the closing of the outgoing server channel as soon as the server begins to
2043reply and only if the request buffer is empty. Note that this should NOT be
2044used if CONNECT requests are expected between the client and the server. The
2045'forceclose' option implies the 'httpclose' option.
2046
2047Example :
2048---------
2049 listen http_proxy 0.0.0.0:80
2050 mode http
2051 log global
2052 option httplog
2053 option dontlognull
2054 option forwardfor
2055 option forceclose
2056
willy tarreau197e8ec2005-12-17 14:10:59 +01002057
20584.4) Load balancing with persistence
2059------------------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01002060Combining cookie insertion with internal load balancing allows to transparently
2061bring persistence to applications. The principle is quite simple :
2062 - assign a cookie value to each server
2063 - enable the load balancing between servers
2064 - insert a cookie into responses resulting from the balancing algorithm
2065 (indirect accesses), end ensure that no upstream proxy will cache it.
2066 - remove the cookie in the request headers so that the application never sees
2067 it.
2068
2069Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002070---------
2071 listen application 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01002072 mode http
2073 cookie SERVERID insert nocache indirect
2074 balance roundrobin
2075 server srv1 192.168.1.1:80 cookie server01 check
2076 server srv2 192.168.1.2:80 cookie server02 check
willy tarreaueedaa9f2005-12-17 14:08:03 +01002077
willy tarreau0174f312005-12-18 01:02:42 +01002078The other solution brought by versions 1.1.30 and 1.2.3 is to reuse a cookie
2079from the server, and prefix the server's name to it. In this case, don't forget
2080to force "httpclose" mode so that you can be assured that every subsequent
2081request will have its cookie fixed.
2082
2083 listen application 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01002084 mode http
2085 cookie JSESSIONID prefix
2086 balance roundrobin
2087 server srv1 192.168.1.1:80 cookie srv1 check
2088 server srv2 192.168.1.2:80 cookie srv2 check
2089 option httpclose
willy tarreau0174f312005-12-18 01:02:42 +01002090
2091
willy tarreau982249e2005-12-18 00:57:06 +010020924.5) Protection against information leak from the servers
2093---------------------------------------------------------
2094In versions 1.1.28/1.2.1, a new option 'checkcache' was created. It carefully
2095checks 'Cache-control', 'Pragma' and 'Set-cookie' headers in server response
2096to check if there's a risk of caching a cookie on a client-side proxy. When this
2097option is enabled, the only responses which can be delivered to the client are :
2098 - all those without 'Set-Cookie' header ;
2099 - all those with a return code other than 200, 203, 206, 300, 301, 410,
2100 provided that the server has not set a 'Cache-control: public' header ;
2101 - all those that come from a POST request, provided that the server has not
2102 set a 'Cache-Control: public' header ;
2103 - those with a 'Pragma: no-cache' header
2104 - those with a 'Cache-control: private' header
2105 - those with a 'Cache-control: no-store' header
2106 - those with a 'Cache-control: max-age=0' header
2107 - those with a 'Cache-control: s-maxage=0' header
2108 - those with a 'Cache-control: no-cache' header
2109 - those with a 'Cache-control: no-cache="set-cookie"' header
2110 - those with a 'Cache-control: no-cache="set-cookie,' header
2111 (allowing other fields after set-cookie)
willy tarreaueedaa9f2005-12-17 14:08:03 +01002112
willy tarreau982249e2005-12-18 00:57:06 +01002113If a response doesn't respect these requirements, then it will be blocked just
2114as if it was from an 'rspdeny' filter, with an "HTTP 502 bad gateway". The
2115session state shows "PH--" meaning that the proxy blocked the response during
2116headers processing. Additionnaly, an alert will be sent in the logs so that
2117admins are told that there's something to be done.
2118
willy tarreauc5f73ed2005-12-18 01:26:38 +01002119
willy tarreau982249e2005-12-18 00:57:06 +010021204.6) Customizing errors
2121-----------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01002122Some situations can make haproxy return an HTTP error code to the client :
2123 - invalid or too long request => HTTP 400
2124 - request not completely sent in time => HTTP 408
2125 - forbidden request (matches a deny filter) => HTTP 403
2126 - internal error in haproxy => HTTP 500
2127 - the server returned an invalid or incomplete response => HTTP 502
2128 - no server was available to handle the request => HTTP 503
2129 - the server failed to reply in time => HTTP 504
willy tarreaueedaa9f2005-12-17 14:08:03 +01002130
willy tarreau197e8ec2005-12-17 14:10:59 +01002131A succint error message taken from the RFC accompanies these return codes.
2132But depending on the clients knowledge, it may be better to return custom, user
2133friendly, error pages. This is made possible through the use of the 'errorloc'
2134command :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002135
willy tarreau197e8ec2005-12-17 14:10:59 +01002136 errorloc <HTTP_code> <location>
willy tarreaueedaa9f2005-12-17 14:08:03 +01002137
willy tarreau197e8ec2005-12-17 14:10:59 +01002138Instead of generating an HTTP error <HTTP_code> among those above, the proxy
2139will return a temporary redirection code (HTTP 302) towards the address
2140specified in <location>. This address may be either relative to the site or
2141absolute. Since this request will be handled by the client's browser, it's
2142mandatory that the returned address be reachable from the outside.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002143
willy tarreau197e8ec2005-12-17 14:10:59 +01002144Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002145---------
2146 listen application 0.0.0.0:80
2147 errorloc 400 /badrequest.html
2148 errorloc 403 /forbidden.html
2149 errorloc 408 /toolong.html
willy tarreauc5f73ed2005-12-18 01:26:38 +01002150 errorloc 500 http://haproxy.domain.net/bugreport.html
willy tarreaueedaa9f2005-12-17 14:08:03 +01002151 errorloc 502 http://192.168.114.58/error50x.html
2152 errorloc 503 http://192.168.114.58/error50x.html
2153 errorloc 504 http://192.168.114.58/error50x.html
2154
willy tarreauc1f47532005-12-18 01:08:26 +01002155Note: RFC2616 says that a client must reuse the same method to fetch the
2156Location returned by a 302, which causes problems with the POST method.
2157The return code 303 was designed explicitly to force the client to fetch the
2158Location URL with the GET method, but there are some browsers pre-dating
2159HTTP/1.1 which don't support it. Anyway, most browsers still behave with 302 as
willy tarreauc5f73ed2005-12-18 01:26:38 +01002160if it was a 303. In order to allow the user to chose, versions 1.1.31 and 1.2.5
2161bring two new keywords to replace 'errorloc' : 'errorloc302' and 'errorloc303'.
willy tarreauc1f47532005-12-18 01:08:26 +01002162
2163They are preffered over errorloc (which still does 302). Consider using
2164errorloc303 everytime you know that your clients support HTTP 303 responses..
2165
2166
willy tarreau982249e2005-12-18 00:57:06 +010021674.7) Modifying default values
willy tarreau197e8ec2005-12-17 14:10:59 +01002168-----------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01002169Version 1.1.22 introduced the notion of default values, which eliminates the
2170pain of often repeating common parameters between many instances, such as
2171logs, timeouts, modes, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01002172
willy tarreau197e8ec2005-12-17 14:10:59 +01002173Default values are set in a 'defaults' section. Each of these section clears
2174all previously set default parameters, so there may be as many default
2175parameters as needed. Only the last one before a 'listen' section will be
2176used for this section. The 'defaults' section uses the same syntax as the
2177'listen' section, for the supported parameters. The 'defaults' keyword ignores
2178everything on its command line, so that fake instance names can be specified
2179there for better clarity.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002180
willy tarreau982249e2005-12-18 00:57:06 +01002181In version 1.1.28/1.2.1, only those parameters can be preset in the 'default'
willy tarreau197e8ec2005-12-17 14:10:59 +01002182section :
2183 - log (the first and second one)
willy tarreaueedaa9f2005-12-17 14:08:03 +01002184 - mode { tcp, http, health }
2185 - balance { roundrobin }
willy tarreau197e8ec2005-12-17 14:10:59 +01002186 - disabled (to disable every further instances)
2187 - enabled (to enable every further instances, this is the default)
willy tarreaueedaa9f2005-12-17 14:08:03 +01002188 - contimeout, clitimeout, srvtimeout, grace, retries, maxconn
willy tarreau982249e2005-12-18 00:57:06 +01002189 - option { redispatch, transparent, keepalive, forwardfor, logasap, httpclose,
2190 checkcache, httplog, tcplog, dontlognull, persist, httpchk }
willy tarreaueedaa9f2005-12-17 14:08:03 +01002191 - redispatch, redisp, transparent, source { addr:port }
2192 - cookie, capture
2193 - errorloc
2194
willy tarreau197e8ec2005-12-17 14:10:59 +01002195As of 1.1.24, it is not possible to put certain parameters in a 'defaults'
2196section, mainly regular expressions and server configurations :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002197 - dispatch, server,
willy tarreau197e8ec2005-12-17 14:10:59 +01002198 - req*, rsp*
willy tarreaueedaa9f2005-12-17 14:08:03 +01002199
willy tarreau197e8ec2005-12-17 14:10:59 +01002200Last, there's no way yet to change a boolean option from its assigned default
2201value. So if an 'option' statement is set in a 'defaults' section, the only
2202way to flush it is to redefine a new 'defaults' section without this 'option'.
willy tarreaueedaa9f2005-12-17 14:08:03 +01002203
willy tarreau197e8ec2005-12-17 14:10:59 +01002204Examples :
willy tarreaueedaa9f2005-12-17 14:08:03 +01002205----------
2206 defaults applications TCP
willy tarreauc5f73ed2005-12-18 01:26:38 +01002207 log global
2208 mode tcp
2209 balance roundrobin
2210 clitimeout 180000
2211 srvtimeout 180000
2212 contimeout 4000
2213 retries 3
2214 redispatch
willy tarreaueedaa9f2005-12-17 14:08:03 +01002215
2216 listen app_tcp1 10.0.0.1:6000-6063
willy tarreauc5f73ed2005-12-18 01:26:38 +01002217 server srv1 192.168.1.1 check port 6000 inter 10000
2218 server srv2 192.168.1.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01002219
2220 listen app_tcp2 10.0.0.2:6000-6063
willy tarreauc5f73ed2005-12-18 01:26:38 +01002221 server srv1 192.168.2.1 check port 6000 inter 10000
2222 server srv2 192.168.2.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01002223
2224 defaults applications HTTP
willy tarreauc5f73ed2005-12-18 01:26:38 +01002225 log global
2226 mode http
2227 option httplog
2228 option forwardfor
2229 option dontlognull
2230 balance roundrobin
2231 clitimeout 20000
2232 srvtimeout 20000
2233 contimeout 4000
2234 retries 3
willy tarreaueedaa9f2005-12-17 14:08:03 +01002235
2236 listen app_http1 10.0.0.1:80-81
willy tarreauc5f73ed2005-12-18 01:26:38 +01002237 cookie SERVERID postonly insert indirect
2238 capture cookie userid= len 10
2239 server srv1 192.168.1.1:+8000 cookie srv1 check port 8080 inter 1000
2240 server srv1 192.168.1.2:+8000 cookie srv2 check port 8080 inter 1000
willy tarreaueedaa9f2005-12-17 14:08:03 +01002241
2242 defaults
willy tarreauc5f73ed2005-12-18 01:26:38 +01002243 # this empty section voids all default parameters
willy tarreaueedaa9f2005-12-17 14:08:03 +01002244
willy tarreau197e8ec2005-12-17 14:10:59 +01002245=========================
2246| System-specific setup |
2247=========================
willy tarreaueedaa9f2005-12-17 14:08:03 +01002248
willy tarreau197e8ec2005-12-17 14:10:59 +01002249Linux 2.4
2250=========
willy tarreaueedaa9f2005-12-17 14:08:03 +01002251
2252-- cut here --
2253#!/bin/sh
2254# set this to about 256/4M (16384 for 256M machine)
2255MAXFILES=16384
2256echo $MAXFILES > /proc/sys/fs/file-max
2257ulimit -n $MAXFILES
2258
2259if [ -e /proc/sys/net/ipv4/ip_conntrack_max ]; then
willy tarreauc5f73ed2005-12-18 01:26:38 +01002260 echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max
willy tarreaueedaa9f2005-12-17 14:08:03 +01002261fi
2262
2263if [ -e /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait ]; then
willy tarreauc5f73ed2005-12-18 01:26:38 +01002264 # 30 seconds for fin, 15 for time wait
2265 echo 3000 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait
2266 echo 1500 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_time_wait
2267 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_invalid_scale
2268 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_out_of_window
willy tarreaueedaa9f2005-12-17 14:08:03 +01002269fi
2270
2271echo 1024 60999 > /proc/sys/net/ipv4/ip_local_port_range
2272echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
2273echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog
2274echo 262144 > /proc/sys/net/ipv4/tcp_max_tw_buckets
2275echo 262144 > /proc/sys/net/ipv4/tcp_max_orphans
2276echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time
2277echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
2278echo 0 > /proc/sys/net/ipv4/tcp_timestamps
2279echo 0 > /proc/sys/net/ipv4/tcp_ecn
willy tarreauc5f73ed2005-12-18 01:26:38 +01002280echo 1 > /proc/sys/net/ipv4/tcp_sack
willy tarreaueedaa9f2005-12-17 14:08:03 +01002281echo 0 > /proc/sys/net/ipv4/tcp_dsack
2282
2283# auto-tuned on 2.4
2284#echo 262143 > /proc/sys/net/core/rmem_max
2285#echo 262143 > /proc/sys/net/core/rmem_default
2286
2287echo 16384 65536 524288 > /proc/sys/net/ipv4/tcp_rmem
2288echo 16384 349520 699040 > /proc/sys/net/ipv4/tcp_wmem
2289
2290-- cut here --
2291
willy tarreau197e8ec2005-12-17 14:10:59 +01002292
2293FreeBSD
2294=======
2295
2296A FreeBSD port of HA-Proxy is now available and maintained, thanks to
2297Clement Laforet <sheepkiller@cultdeadsheep.org>.
2298
2299For more information :
2300http://www.freebsd.org/cgi/url.cgi?ports/net/haproxy/pkg-descr
2301http://www.freebsd.org/cgi/cvsweb.cgi/ports/net/haproxy/
2302http://www.freshports.org/net/haproxy
2303
2304
2305-- end --