blob: 1df3488f54141cb98da25806c49d3b2ceb91bc29 [file] [log] [blame]
willy tarreau0174f312005-12-18 01:02:42 +01001 -------------------
2 H A - P r o x y
3 Reference Manual
4 -------------------
willy tarreaub952e1d2005-12-18 01:31:20 +01005 version 1.2.7
willy tarreauc5f73ed2005-12-18 01:26:38 +01006 willy tarreau
willy tarreaub952e1d2005-12-18 01:31:20 +01007 2005/10/09
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 ;
23
24It needs very little resource. Its event-driven architecture allows it to easily
25handle thousands of simultaneous connections on hundreds of instances without
26risking the system's stability.
27
28====================
29| Start parameters |
30====================
31
32There are only a few command line options :
33
34 -f <configuration file>
35 -n <high limit for the total number of simultaneous connections>
36 -N <high limit for the per-proxy number of simultaneous connections>
37 -d starts in foregreound with debugging mode enabled
38 -D starts in daemon mode
willy tarreau982249e2005-12-18 00:57:06 +010039 -q disable messages on output
40 -V displays messages on output even when -q or 'quiet' are specified.
41 -c only checks config file and exits with code 0 if no error was found, or
42 exits with code 1 if a syntax error was found.
willy tarreaufe2c5c12005-12-17 14:14:34 +010043 -p <pidfile> asks the process to write down each of its children's
44 pids to this file in daemon mode.
willy tarreaueedaa9f2005-12-17 14:08:03 +010045 -s shows statistics (only if compiled in)
46 -l shows even more statistics (implies '-s')
willy tarreau64a3cc32005-12-18 01:13:11 +010047 -de disables use of epoll()
48 -dp disables use of poll()
willy tarreaueedaa9f2005-12-17 14:08:03 +010049
50
51The maximal number of connections per proxy is used as the default parameter for
52each instance for which the 'maxconn' paramter is not set in the 'listen' section.
53
54The maximal number of total connections limits the number of connections used by
55the whole process if the 'maxconn' parameter is not set in the 'global' section.
56
57The debugging mode has the same effect as the 'debug' option in the 'global'
58section. When the proxy runs in this mode, it dumps every connections,
59disconnections, timestamps, and HTTP headers to stdout. This should NEVER
60be used in an init script since it will prevent the system from starting up.
61
62Statistics are only available if compiled in with the 'STATTIME' option. It's
63only used during code optimization phases.
64
65======================
66| Configuration file |
67======================
68
69Structure
70=========
71
72The configuration file parser ignores empty lines, spaces, tabs. Anything
73between a sharp ('#') not following a backslash ('\'), and the end of a line
74constitutes a comment and is ignored too.
75
76The configuration file is segmented in sections. A section begins whenever
77one of these 3 keywords are encountered :
78
79 - 'global'
80 - 'listen'
81 - 'defaults'
82
83Every parameter refer to the section beginning at the last one of these 3
84keywords.
85
86
871) Global parameters
88====================
89
90Global parameters affect the whole process behaviour. They are all set in the
91'global' section. There may be several 'global' sections if needed, but their
92parameters will only be merged. Allowed parameters in 'global' section include
93the following ones :
94
95 - log <address> <facility> [max_level]
96 - maxconn <number>
97 - uid <user id>
98 - gid <group id>
99 - chroot <directory>
100 - nbproc <number>
101 - daemon
102 - debug
willy tarreau64a3cc32005-12-18 01:13:11 +0100103 - noepoll
104 - nopoll
willy tarreaueedaa9f2005-12-17 14:08:03 +0100105 - quiet
willy tarreaufe2c5c12005-12-17 14:14:34 +0100106 - pidfile <file>
willy tarreauc5f73ed2005-12-18 01:26:38 +0100107 - ulimit-n <number>
willy tarreau598da412005-12-18 01:07:29 +0100108 - stats
willy tarreaueedaa9f2005-12-17 14:08:03 +0100109
willy tarreauc5f73ed2005-12-18 01:26:38 +0100110
willy tarreaueedaa9f2005-12-17 14:08:03 +01001111.1) Event logging
112------------------
113Most events are logged : start, stop, servers going up and down, connections and
114errors. Each event generates a syslog message which can be sent to up to 2
115servers. The syntax is :
116
117 log <ip_address> <facility> [max_level]
118
119Connections are logged at level "info". Services initialization and servers
120going up are logged at level "notice", termination signals are logged at
121"warning", and definitive service termination, as well as loss of servers are
122logged at level "alert". The optional parameter <max_level> specifies above
123what level messages should be sent. Level can take one of these 8 values :
124
125 emerg, alert, crit, err, warning, notice, info, debug
126
127For backwards compatibility with versions 1.1.16 and earlier, the default level
128value is "debug" if not specified.
129
130Permitted facilities are :
131 kern, user, mail, daemon, auth, syslog, lpr, news,
132 uucp, cron, auth2, ftp, ntp, audit, alert, cron2,
133 local0, local1, local2, local3, local4, local5, local6, local7
134
135According to RFC3164, messages are truncated to 1024 bytes before being emitted.
136
137Example :
138---------
139 global
willy tarreauc5f73ed2005-12-18 01:26:38 +0100140 log 192.168.2.200 local3
141 log 127.0.0.1 local4 notice
142
willy tarreaueedaa9f2005-12-17 14:08:03 +0100143
1441.2) limiting the number of connections
145---------------------------------------
146It is possible and recommended to limit the global number of per-process
willy tarreauc5f73ed2005-12-18 01:26:38 +0100147connections using the 'maxconn' global keyword. Since one connection includes
148both a client and a server, it means that the max number of TCP sessions will
149be about the double of this number. It's important to understand this when
150trying to find best values for 'ulimit -n' before starting the proxy. To
151anticipate the number of sockets needed, all these parameters must be counted :
willy tarreaueedaa9f2005-12-17 14:08:03 +0100152
153 - 1 socket per incoming connection
154 - 1 socket per outgoing connection
155 - 1 socket per address/port/proxy tuple.
156 - 1 socket per server being health-checked
157 - 1 socket for all logs
158
159In simple configurations where each proxy only listens one one address/port,
willy tarreauc5f73ed2005-12-18 01:26:38 +0100160set the limit of file descriptors (ulimit -n) to
161(2 * maxconn + nbproxies + nbservers + 1). Starting with versions 1.1.32/1.2.6,
162it is now possible to set the limit in the configuration using the 'ulimit-n'
163global keyword, provided the proxy is started as root. This puts an end to the
164recurrent problem of ensuring that the system limits are adapted to the proxy
165values. Note that these limits are per-process.
166
167Example :
168---------
169 global
170 maxconn 32000
171 ulimit-n 65536
172
willy tarreaueedaa9f2005-12-17 14:08:03 +0100173
1741.3) Drop of priviledges
175------------------------
176In order to reduce the risk and consequences of attacks, in the event where a
177yet non-identified vulnerability would be successfully exploited, it's possible
178to lower the process priviledges and even isolate it in a riskless directory.
179
180In the 'global' section, the 'uid' parameter sets a numerical user identifier
181which the process will switch to after binding its listening sockets. The value
182'0', which normally represents the super-user, here indicates that the UID must
183not change during startup. It's the default behaviour. The 'gid' parameter does
184the same for the group identifier. It's particularly advised against use of
185generic accounts such as 'nobody' because it has the same consequences as using
186'root' if other services use them.
187
188The 'chroot' parameter makes the process isolate itself in an empty directory
189just before switching its UID. This type of isolation (chroot) can sometimes
190be worked around on certain OS (Linux, Solaris), provided that the attacker
191has gained 'root' priviledges and has the ability to use or create a directory.
192For this reason, it's capital to use a dedicated directory and not to share one
193between several services of different nature. To make isolation more resistant,
194it's recommended to use an empty directory without any right, and to change the
195UID of the process so that it cannot do anything there.
196
197Note: in the event where such a vulnerability would be exploited, it's most
198likely that first attempts would kill the process due to 'Segmentation Fault',
199'Bus Error' or 'Illegal Instruction' signals. Eventhough it's true that
200isolating the server reduces the risks of intrusion, it's sometimes useful to
201find why a process dies, via the analysis of a 'core' file, although very rare
202(the last bug of this sort was fixed in 1.1.9). For security reasons, most
203systems disable the generation of core file when a process changes its UID. So
204the two workarounds are either to start the process from a restricted user
205account, which will not be able to chroot itself, or start it as root and not
206change the UID. In both cases the core will be either in the start or the chroot
207directories. Do not forget to allow core dumps prior to start the process :
208
209# ulimit -c unlimited
210
211Example :
212---------
213
214 global
willy tarreauc5f73ed2005-12-18 01:26:38 +0100215 uid 30000
216 gid 30000
217 chroot /var/chroot/haproxy
218
willy tarreaueedaa9f2005-12-17 14:08:03 +0100219
2201.4) Startup modes
221------------------
222The service can start in several different :
223 - foreground / background
224 - quiet / normal / debug
225
226The default mode is normal, foreground, which means that the program doesn't
227return once started. NEVER EVER use this mode in a system startup script, or
228the system won't boot. It needs to be started in background, so that it
229returns immediately after forking. That's accomplished by the 'daemon' option
230in the 'global' section, which is the equivalent of the '-D' command line
231argument.
232
233Moreover, certain alert messages are still sent to the standard output even
234in 'daemon' mode. To make them disappear, simply add the 'quiet' option in the
235'global' section. This option has no command-line equivalent.
236
237Last, the 'debug' mode, enabled with the 'debug' option in the 'global' section,
238and which is equivalent of the '-d' option, allows deep TCP/HTTP analysis, with
239timestamped display of each connection, disconnection, and HTTP headers for both
240ways. This mode is incompatible with 'daemon' and 'quiet' modes for obvious
241reasons.
242
willy tarreauc5f73ed2005-12-18 01:26:38 +0100243
willy tarreaueedaa9f2005-12-17 14:08:03 +01002441.5) Increasing the overall processing power
245--------------------------------------------
246On multi-processor systems, it may seem to be a shame to use only one processor,
willy tarreau982249e2005-12-18 00:57:06 +0100247eventhough the load needed to saturate a recent processor is far above common
willy tarreaueedaa9f2005-12-17 14:08:03 +0100248usage. Anyway, for very specific needs, the proxy can start several processes
249between which the operating system will spread the incoming connections. The
250number of processes is controlled by the 'nbproc' parameter in the 'global'
willy tarreau4302f492005-12-18 01:00:37 +0100251section. It defaults to 1, and obviously works only in 'daemon' mode. One
252typical usage of this parameter has been to workaround the default per-process
253file-descriptor limit that Solaris imposes to user processes.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100254
255Example :
256---------
257
258 global
willy tarreauc5f73ed2005-12-18 01:26:38 +0100259 daemon
260 quiet
261 nbproc 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100262
263
willy tarreaufe2c5c12005-12-17 14:14:34 +01002641.6) Helping process management
265-------------------------------
266Haproxy now supports the notion of pidfile. If the '-p' command line argument,
267or the 'pidfile' global option is followed with a file name, this file will be
268removed, then filled with all children's pids, one per line (only in daemon
269mode). This file is NOT within the chroot, which allows to work with a readonly
270 chroot. It will be owned by the user starting the process, and will have
271permissions 0644.
272
273Example :
274---------
275
276 global
277 daemon
278 quiet
willy tarreauc5f73ed2005-12-18 01:26:38 +0100279 nbproc 2
willy tarreaufe2c5c12005-12-17 14:14:34 +0100280 pidfile /var/run/haproxy-private.pid
281
282 # to stop only those processes among others :
283 # kill $(</var/run/haproxy-private.pid)
284
285
willy tarreau64a3cc32005-12-18 01:13:11 +01002861.7) Polling mechanisms
287-----------------------
288Starting from version 1.2.5, haproxy supports the poll() and epoll() polling
289mechanisms. On systems where select() is limited by FD_SETSIZE (like Solaris),
290poll() can be an interesting alternative. Performance tests show that Solaris'
291poll() performance does not decay as fast as the numbers of sockets increase,
292making it a safe solution for high loads. However, Solaris already uses poll()
293to emulate select(), so as long as the number of sockets has no reason to go
294higher than FD_SETSIZE, poll() should not provide any better performance. On
295Linux systems with the epoll() patch (or any 2.6 version), haproxy will use
296epoll() which is extremely fast and non dependant on the number of sockets.
297Tests have shown constant performance from 1 to 20000 simultaneous sessions.
298
299Haproxy will use epoll() when available, and will fall back to poll(), then to
300select(). However, if for any reason you need to disable epoll() or poll() (eg.
301because of a bug or just to compare performance), two new global options have
302been created for this matter : 'noepoll' and 'nopoll'.
303
304Example :
305---------
306
307 global
308 # use only select()
309 noepoll
310 nopoll
311
312Note :
313------
314For the sake of configuration file portability, these options are accepted but
315ignored if the poll() or epoll() mechanisms have not been enabled at compile
316time.
317
318To make debugging easier, the '-de' runtime argument disables epoll support and
319the '-dp' argument disables poll support. They are respectively equivalent to
320'noepoll' and 'nopoll'.
321
322
willy tarreaueedaa9f2005-12-17 14:08:03 +01003232) Declaration of a listening service
324=====================================
325
326Service sections start with the 'listen' keyword :
327
328 listen <instance_name> [ <IP_address>:<port_range>[,...] ]
329
330- <instance_name> is the name of the instance. This name will be reported in
331 logs, so it is good to have it reflect the proxied service. No unicity test
332 is done on this name, and it's not mandatory for it to be unique, but highly
333 recommended.
334
335- <IP_address> is the IP address the proxy binds to. Empty address, '*' and
336 '0.0.0.0' all mean that the proxy listens to all valid addresses on the
337 system.
338
339- <port_range> is either a unique port, or a port range for which the proxy will
340 accept connections for the IP address specified above. This range can be :
341 - a numerical port (ex: '80')
342 - a dash-delimited ports range explicitly stating the lower and upper bounds
343 (ex: '2000-2100') which are included in the range.
344
345 Particular care must be taken against port ranges, because every <addr:port>
346 couple consumes one socket (=a file descriptor), so it's easy to eat lots of
347 descriptors with a simple range. The <addr:port> couple must be used only once
348 among all instances running on a same system. Please note that attaching to
349 ports lower than 1024 need particular priviledges to start the program, which
350 are independant of the 'uid' parameter.
351
352- the <IP_address>:<port_range> couple may be repeated indefinitely to require
353 the proxy to listen to other addresses and/or ports. To achieve this, simply
354 separate them with a coma.
355
356Examples :
357---------
358 listen http_proxy :80
359 listen x11_proxy 127.0.0.1:6000-6009
360 listen smtp_proxy 127.0.0.1:25,127.0.0.1:587
361 listen ldap_proxy :389,:663
362
363In the event that all addresses do not fit line width, it's preferable to
364detach secondary addresses on other lines with the 'bind' keyword. If this
365keyword is used, it's not even necessary to specify the first address on the
366'listen' line, which sometimes makes multiple configuration handling easier :
367
368 bind [ <IP_address>:<port_range>[,...] ]
369
370Examples :
371----------
372 listen http_proxy
373 bind :80,:443
willy tarreauc5f73ed2005-12-18 01:26:38 +0100374 bind 10.0.0.1:10080,10.0.0.1:10443
375
willy tarreaueedaa9f2005-12-17 14:08:03 +0100376
3772.1) Inhibiting a service
378-------------------------
379A service may be disabled for maintenance reasons, without needing to comment
380out the whole section, simply by specifying the 'disabled' keyword in the
381section to be disabled :
382
383 listen smtp_proxy 0.0.0.0:25
willy tarreauc5f73ed2005-12-18 01:26:38 +0100384 disabled
willy tarreaueedaa9f2005-12-17 14:08:03 +0100385
386Note: the 'enabled' keyword allows to enable a service which has been disabled
387 previously by a default configuration.
388
willy tarreauc5f73ed2005-12-18 01:26:38 +0100389
willy tarreaueedaa9f2005-12-17 14:08:03 +01003902.2) Modes of operation
391-----------------------
392A service can work in 3 different distinct modes :
393 - TCP
394 - HTTP
395 - monitoring
396
397TCP mode
398--------
399In this mode, the service relays TCP connections as soon as they're established,
400towards one or several servers. No processing is done on the stream. It's only
401an association of source(addr:port) -> destination(addr:port). To use this mode,
402you must specify 'mode tcp' in the 'listen' section. This is the default mode.
403
404Example :
405---------
406 listen smtp_proxy 0.0.0.0:25
willy tarreauc5f73ed2005-12-18 01:26:38 +0100407 mode tcp
willy tarreaueedaa9f2005-12-17 14:08:03 +0100408
409HTTP mode
410---------
411In this mode, the service relays TCP connections towards one or several servers,
412when it has enough informations to decide, which normally means that all HTTP
413headers have been read. Some of them may be scanned for a cookie or a pattern
414matching a regex. To use this mode, specify 'mode http' in the 'listen' section.
415
416Example :
417---------
418 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100419 mode http
willy tarreaueedaa9f2005-12-17 14:08:03 +0100420
421Health-checking mode
422--------------------
423This mode provides a way for external components to check the proxy's health.
424It is meant to be used with intelligent load-balancers which can use send/expect
425scripts to check for all of their servers' availability. This one simply accepts
willy tarreau197e8ec2005-12-17 14:10:59 +0100426the connection, returns the word 'OK' and closes it. If the 'option httpchk' is
427set, then the reply will be 'HTTP/1.0 200 OK' with no data, so that it can be
428tested from a tool which supports HTTP health-checks. To enable it, simply
willy tarreaueedaa9f2005-12-17 14:08:03 +0100429specify 'health' as the working mode :
430
431Example :
432---------
willy tarreau197e8ec2005-12-17 14:10:59 +0100433 # simple response : 'OK'
willy tarreaueedaa9f2005-12-17 14:08:03 +0100434 listen health_check 0.0.0.0:60000
willy tarreauc5f73ed2005-12-18 01:26:38 +0100435 mode health
willy tarreaueedaa9f2005-12-17 14:08:03 +0100436
willy tarreau197e8ec2005-12-17 14:10:59 +0100437 # HTTP response : 'HTTP/1.0 200 OK'
438 listen http_health_check 0.0.0.0:60001
willy tarreauc5f73ed2005-12-18 01:26:38 +0100439 mode health
440 option httpchk
441
442Monitoring
443----------
444Versions 1.1.32 and 1.2.6 provide a new solution to check the proxy's
445availability without perturbating the service. The 'monitor-net' keyword was
446created to specify a network of equipments which CANNOT use the service for
447anything but health-checks. This is particularly suited to TCP proxies, because
448it prevents the proxy from relaying the monitor's connection to the remote
449server.
450
451When used with TCP, the connection is accepted then closed and nothing is
452logged. This is enough for a front-end load-balancer to detect the service as
453available.
willy tarreau197e8ec2005-12-17 14:10:59 +0100454
willy tarreauc5f73ed2005-12-18 01:26:38 +0100455When used with HTTP, the connection is accepted, nothing is logged, the
456following response is sent, then the session is closed : "HTTP/1.0 200 OK".
457This is normally enough for any front-end HTTP load-balancer to detect the
458service as available too, both with TCP and HTTP checks.
459
460Proxies using the "monitor-net" keyword can remove the "option dontlognull", as
461it will make them log empty connections from hosts outside the monitoring
462network.
463
464Example :
465---------
466
467 listen tse-proxy
468 bind :3389,:1494,:5900 # TSE, ICA and VNC at once.
469 mode tcp
470 balance roundrobin
471 server tse-farm 192.168.1.10
472 monitor-net 192.168.1.252/31 # L4 load-balancers on .252 and .253
473
willy tarreaueedaa9f2005-12-17 14:08:03 +0100474
4752.3) Limiting the number of simultaneous connections
476----------------------------------------------------
477The 'maxconn' parameter allows a proxy to refuse connections above a certain
478amount of simultaneous ones. When the limit is reached, it simply stops
479listening, but the system may still be accepting them because of the back log
willy tarreau982249e2005-12-18 00:57:06 +0100480queue. These connections will be processed later when other ones have freed
willy tarreaueedaa9f2005-12-17 14:08:03 +0100481some slots. This provides a serialization effect which helps very fragile
482servers resist to high loads. Se further for system limitations.
483
484Example :
485---------
486 listen tiny_server 0.0.0.0:80
487 maxconn 10
488
489
4902.4) Soft stop
491--------------
492It is possible to stop services without breaking existing connections by the
willy tarreau22739ef2006-01-20 20:43:32 +0100493sending of the SIGUSR1 signal to the process. All services are then put into
willy tarreaueedaa9f2005-12-17 14:08:03 +0100494soft-stop state, which means that they will refuse to accept new connections,
495except for those which have a non-zero value in the 'grace' parameter, in which
496case they will still accept connections for the specified amount of time, in
willy tarreau22739ef2006-01-20 20:43:32 +0100497milliseconds. This makes it possible to tell a load-balancer that the service
498is failing, while still doing the job during the time it needs to detect it.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100499
500Note: active connections are never killed. In the worst case, the user will have
501to wait for all of them to close or to time-out, or simply kill the process
willy tarreau22739ef2006-01-20 20:43:32 +0100502normally (SIGTERM). The default 'grace' value is '0'.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100503
504Example :
505---------
506 # enter soft stop after 'killall -USR1 haproxy'
507 # the service will still run 10 seconds after the signal
508 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100509 mode http
510 grace 10000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100511
512 # this port is dedicated to a load-balancer, and must fail immediately
513 listen health_check 0.0.0.0:60000
willy tarreauc5f73ed2005-12-18 01:26:38 +0100514 mode health
515 grace 0
willy tarreaueedaa9f2005-12-17 14:08:03 +0100516
517
willy tarreau39df2dc2006-01-29 21:56:05 +0100518As of version 1.2.8, a new soft-reconfiguration mechanism has been introduced.
willy tarreau22739ef2006-01-20 20:43:32 +0100519It is now possible to "pause" all the proxies by sending a SIGTTOU signal to
520the processes. This will disable the listening socket without breaking existing
521connections. After that, sending a SIGTTIN signal to those processes enables
522the listening sockets again. This is very useful to try to load a new
523configuration or even a new version of haproxy without breaking existing
524connections. If the load succeeds, then simply send a SIGUSR1 which will make
525the previous proxies exit immediately once their sessions are closed ; and if
526the load fails, then simply send a SIGTTIN to restore the service immediately.
527Please note that the 'grace' parameter is ignored for SIGTTOU, as well as for
528SIGUSR1 when the process was in the pause mode. Please also note that it would
529be useful to save the pidfile before starting a new instance.
530
531
willy tarreaueedaa9f2005-12-17 14:08:03 +01005322.5) Connections expiration time
533--------------------------------
534It is possible (and recommended) to configure several time-outs on TCP
535connections. Three independant timers are adjustable with values specified
536in milliseconds. A session will be terminated if either one of these timers
537expire.
538
539 - the time we accept to wait for data from the client, or for the client to
540 accept data : 'clitimeout' :
541
willy tarreauc5f73ed2005-12-18 01:26:38 +0100542 # client time-out set to 2mn30.
543 clitimeout 150000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100544
545 - the time we accept to wait for data from the server, or for the server to
546 accept data : 'srvtimeout' :
547
willy tarreauc5f73ed2005-12-18 01:26:38 +0100548 # server time-out set to 30s.
549 srvtimeout 30000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100550
551 - the time we accept to wait for a connection to establish on a server :
552 'contimeout' :
553
554 # we give up if the connection does not complete within 4 seconds
willy tarreauc5f73ed2005-12-18 01:26:38 +0100555 contimeout 4000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100556
557Notes :
558-------
559 - 'contimeout' and 'srvtimeout' have no sense on 'health' mode servers ;
560 - under high loads, or with a saturated or defective network, it's possible
561 that some packets get lost. Since the first TCP retransmit only happens
562 after 3 seconds, a time-out equal to, or lower than 3 seconds cannot
563 compensate for a packet loss. A 4 seconds time-out seems a reasonable
564 minimum which will considerably reduce connection failures.
565
willy tarreauc5f73ed2005-12-18 01:26:38 +0100566
willy tarreaueedaa9f2005-12-17 14:08:03 +01005672.6) Attempts to reconnect
568--------------------------
569After a connection failure to a server, it is possible to retry, potentially
570on another server. This is useful if health-checks are too rare and you don't
571want the clients to see the failures. The number of attempts to reconnect is
572set by the 'retries' paramter.
573
574Example :
575---------
willy tarreauc5f73ed2005-12-18 01:26:38 +0100576 # we can retry 3 times max after a failure
577 retries 3
willy tarreaueedaa9f2005-12-17 14:08:03 +0100578
579
5802.7) Address of the dispatch server (deprecated)
581------------------------------------------------
582The server which will be sent all new connections is defined by the 'dispatch'
583parameter, in the form <address>:<port>. It generally is dedicated to unknown
584connections and will assign them a cookie, in case of HTTP persistence mode,
585or simply is a single server in case of generic TCP proxy. This old mode is only
586provided for backwards compatibility, but doesn't allow to check remote servers
587state, and has a rather limited usage. All new setups should switch to 'balance'
588mode. The principle of the dispatcher is to be able to perform the load
589balancing itself, but work only on new clients so that the server doesn't need
590to be a big machine.
591
592Example :
593---------
willy tarreauc5f73ed2005-12-18 01:26:38 +0100594 # all new connections go there
595 dispatch 192.168.1.2:80
willy tarreaueedaa9f2005-12-17 14:08:03 +0100596
597Note :
598------
599This parameter has no sense for 'health' servers, and is incompatible with
600'balance' mode.
601
602
6032.8) Outgoing source address
604----------------------------
605It is often necessary to bind to a particular address when connecting to some
606remote hosts. This is done via the 'source' parameter which is a per-proxy
607parameter. A newer version may allow to fix different sources to reach different
608servers. The syntax is 'source <address>[:<port>]', where <address> is a valid
609local address (or '0.0.0.0' or '*' or empty to let the system choose), and
610<port> is an optional parameter allowing the user to force the source port for
611very specific needs. If the port is not specified or is '0', the system will
612choose a free port. Note that as of version 1.1.18, the servers health checks
613are also performed from the same source.
614
615Examples :
616----------
617 listen http_proxy *:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100618 # all connections take 192.168.1.200 as source address
619 source 192.168.1.200:0
willy tarreaueedaa9f2005-12-17 14:08:03 +0100620
621 listen rlogin_proxy *:513
willy tarreauc5f73ed2005-12-18 01:26:38 +0100622 # use address 192.168.1.200 and the reserved port 900 (needs to be root)
623 source 192.168.1.200:900
willy tarreaueedaa9f2005-12-17 14:08:03 +0100624
625
6262.9) Setting the cookie name
627----------------------------
628In HTTP mode, it is possible to look for a particular cookie which will contain
629a server identifier which should handle the connection. The cookie name is set
630via the 'cookie' parameter.
631
632Example :
633---------
634 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100635 mode http
636 cookie SERVERID
willy tarreaueedaa9f2005-12-17 14:08:03 +0100637
638It is possible to change the cookie behaviour to get a smarter persistence,
639depending on applications. It is notably possible to delete or modify a cookie
640emitted by a server, insert a cookie identifying the server in an HTTP response
641and even add a header to tell upstream caches not to cache this response.
642
643Examples :
644----------
645
646To remove the cookie for direct accesses (ie when the server matches the one
647which was specified in the client cookie) :
648
willy tarreauc5f73ed2005-12-18 01:26:38 +0100649 cookie SERVERID indirect
willy tarreaueedaa9f2005-12-17 14:08:03 +0100650
651To replace the cookie value with the one assigned to the server if any (no
652cookie will be created if the server does not provide one, nor if the
653configuration does not provide one). This lets the application put the cookie
654exactly on certain pages (eg: successful authentication) :
655
willy tarreauc5f73ed2005-12-18 01:26:38 +0100656 cookie SERVERID rewrite
willy tarreaueedaa9f2005-12-17 14:08:03 +0100657
658To create a new cookie and assign the server identifier to it (in this case, all
659servers should be associated with a valid cookie, since no cookie will simply
660delete the cookie from the client's browser) :
661
willy tarreauc5f73ed2005-12-18 01:26:38 +0100662 cookie SERVERID insert
willy tarreaueedaa9f2005-12-17 14:08:03 +0100663
willy tarreau0174f312005-12-18 01:02:42 +0100664To reuse an existing application cookie and prefix it with the server's
665identifier, and remove it in the request, use the 'prefix' option. This allows
666to insert a haproxy in front of an application without risking to break clients
667which does not support more than one cookie :
668
willy tarreauc5f73ed2005-12-18 01:26:38 +0100669 cookie JSESSIONID prefix
willy tarreau0174f312005-12-18 01:02:42 +0100670
willy tarreaueedaa9f2005-12-17 14:08:03 +0100671To insert a cookie and ensure that no upstream cache will store it, add the
672'nocache' option :
673
willy tarreauc5f73ed2005-12-18 01:26:38 +0100674 cookie SERVERID insert nocache
willy tarreaueedaa9f2005-12-17 14:08:03 +0100675
676To insert a cookie only after a POST request, add 'postonly' after 'insert'.
677This has the advantage that there's no risk of caching, and that all pages
678seen before the POST one can still be cached :
679
willy tarreauc5f73ed2005-12-18 01:26:38 +0100680 cookie SERVERID insert postonly
willy tarreaueedaa9f2005-12-17 14:08:03 +0100681
682Notes :
683-----------
684- it is possible to combine 'insert' with 'indirect' or 'rewrite' to adapt to
685 applications which already generate the cookie with an invalid content.
686
687- in the case where 'insert' and 'indirect' are both specified, the cookie is
willy tarreau0174f312005-12-18 01:02:42 +0100688 never transmitted to the server, since it wouldn't understand it. This is the
689 most application-transparent mode.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100690
691- it is particularly recommended to use 'nocache' in 'insert' mode if any
692 upstream HTTP/1.0 cache is susceptible to cache the result, because this may
693 lead to many clients going to the same server, or even worse, some clients
694 having their server changed while retrieving a page from the cache.
695
willy tarreau0174f312005-12-18 01:02:42 +0100696- the 'prefix' mode normally does not need 'indirect', 'nocache', nor
697 'postonly', because just as in the 'rewrite' mode, it relies on the
698 application to know when a cookie can be emitted. However, since it has to
699 fix the cookie name in every subsequent requests, you must ensure that the
700 proxy will be used without any "HTTP keep-alive". Use option "httpclose" if
701 unsure.
702
willy tarreaueedaa9f2005-12-17 14:08:03 +0100703- when the application is well known and controlled, the best method is to
704 only add the persistence cookie on a POST form because it's up to the
willy tarreau0174f312005-12-18 01:02:42 +0100705 application to select which page it wants the upstream servers to cache. In
706 this case, you would use 'insert postonly indirect'.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100707
willy tarreauc5f73ed2005-12-18 01:26:38 +0100708
willy tarreaueedaa9f2005-12-17 14:08:03 +01007092.10) Associating a cookie value with a server
710----------------------------------------------
711In HTTP mode, it's possible to associate a cookie value to each server. This
712was initially used in combination with 'dispatch' mode to handle direct accesses
713but it is now the standard way of doing the load balancing. The syntax is :
714
715 server <identifier> <address>:<port> cookie <value>
716
717- <identifier> is any name which can be used to identify the server in the logs.
718- <address>:<port> specifies where the server is bound.
719- <value> is the value to put in or to read from the cookie.
720
721Example : the 'SERVERID' cookie can be either 'server01' or 'server02'
722---------
723 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100724 mode http
725 cookie SERVERID
726 dispatch 192.168.1.100:80
727 server web1 192.168.1.1:80 cookie server01
728 server web2 192.168.1.2:80 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100729
730Warning : the syntax has changed since version 1.0 !
731---------
732
willy tarreauc5f73ed2005-12-18 01:26:38 +0100733
willy tarreau598da412005-12-18 01:07:29 +01007342.11) Application Cookies
735-------------------------
736Since 1.2.4 it is possible to catch the cookie that comes from an
737application server in order to apply "application session stickyness".
738The server's response is searched for 'appsession' cookie, the first
739'len' bytes are used for matching and it is stored for a period of
740'timeout'.
741The syntax is:
742
743 appsession <SESSIONCOOKIE> len <MATCHLENGTH> timeout <HOLDTIME>
744
745- <SESSIONCOOKIE> is the cookie, the server uses for it's session-handling
746- <MATCHLENGTH> how many bytes/characters should be used for matching equal
747 sessions
748- <HOLDTIME> after this inactivaty time, in ms, the cookie will be deleted
749 from the sessionstore
750
751The appsession is only per 'listen' section possible.
752
753Example :
754---------
755 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100756 mode http
willy tarreau598da412005-12-18 01:07:29 +0100757 appsession JSESSIONID len 52 timeout 300000
758 .
759 .
760
willy tarreauc5f73ed2005-12-18 01:26:38 +0100761
willy tarreaueedaa9f2005-12-17 14:08:03 +01007623) Autonomous load balancer
763===========================
764
765The proxy can perform the load-balancing itself, both in TCP and in HTTP modes.
766This is the most interesting mode which obsoletes the old 'dispatch' mode
767described above. It has advantages such as server health monitoring, multiple
768port binding and port mapping. To use this mode, the 'balance' keyword is used,
769followed by the selected algorithm. As of version 1.1.23, only 'roundrobin' is
770available, which is also the default value if unspecified. In this mode, there
771will be no dispatch address, but the proxy needs at least one server.
772
773Example : same as the last one, with internal load balancer
774---------
775
776 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100777 mode http
778 cookie SERVERID
779 balance roundrobin
780 server web1 192.168.1.1:80 cookie server01
781 server web2 192.168.1.2:80 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100782
783
784Since version 1.1.22, it is possible to automatically determine on which port
785the server will get the connection, depending on the port the client connected
786to. Indeed, there now are 4 possible combinations for the server's <port> field:
787
788 - unspecified or '0' :
789 the connection will be sent to the same port as the one on which the proxy
790 received the client connection itself.
791
792 - numerical value (the only one supported in versions earlier than 1.1.22) :
793 the connection will always be sent to the specified port.
794
795 - '+' followed by a numerical value :
796 the connection will be sent to the same port as the one on which the proxy
797 received the connection, plus this value.
798
799 - '-' followed by a numerical value :
800 the connection will be sent to the same port as the one on which the proxy
801 received the connection, minus this value.
802
803Examples :
804----------
805
806# same as previous example
807
808 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100809 mode http
810 cookie SERVERID
811 balance roundrobin
812 server web1 192.168.1.1 cookie server01
813 server web2 192.168.1.2 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100814
815# simultaneous relaying of ports 80, 81 and 8080-8089
816
817 listen http_proxy :80,:81,:8080-8089
willy tarreauc5f73ed2005-12-18 01:26:38 +0100818 mode http
819 cookie SERVERID
820 balance roundrobin
821 server web1 192.168.1.1 cookie server01
822 server web2 192.168.1.2 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100823
824# relaying of TCP ports 25, 389 and 663 to ports 1025, 1389 and 1663
825
826 listen http_proxy :25,:389,:663
willy tarreauc5f73ed2005-12-18 01:26:38 +0100827 mode tcp
828 balance roundrobin
829 server srv1 192.168.1.1:+1000
830 server srv2 192.168.1.2:+1000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100831
832
willy tarreau197e8ec2005-12-17 14:10:59 +01008333.1) Server monitoring
834----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +0100835It is possible to check the servers status by trying to establish TCP
836connections or even sending HTTP requests to them. A server which fails to
837reply to health checks as expected will not be used by the load balancing
838algorithms. To enable monitoring, add the 'check' keyword on a server line.
839It is possible to specify the interval between tests (in milliseconds) with
840the 'inter' parameter, the number of failures supported before declaring that
841the server has fallen down with the 'fall' parameter, and the number of valid
842checks needed for the server to fully get up with the 'rise' parameter. Since
843version 1.1.22, it is also possible to send checks to a different port
844(mandatory when none is specified) with the 'port' parameter. The default
845values are the following ones :
846
847 - inter : 2000
848 - rise : 2
849 - fall : 3
850 - port : default server port
851
852The default mode consists in establishing TCP connections only. But in certain
853types of application failures, it is often that the server continues to accept
854connections because the system does it itself while the application is running
855an endless loop, or is completely stuck. So in version 1.1.16 were introduced
856HTTP health checks which only performed simple lightweight requests and analysed
857the response. Now, as of version 1.1.23, it is possible to change the HTTP
858method, the URI, and the HTTP version string (which even allows to send headers
859with a dirty trick). To enable HTTP health-checks, use 'option httpchk'.
860
861By default, requests use the 'OPTIONS' method because it's very light and easy
862to filter from logs, and does it on '/'. Only HTTP responses 2xx and 3xx are
863considered valid ones, and only if they come before the time to send a new
864request is reached ('inter' parameter). If some servers block this type of
865request, 3 other forms help to forge a request :
866
867 - option httpchk -> OPTIONS / HTTP/1.0
868 - option httpchk URI -> OPTIONS <URI> HTTP/1.0
869 - option httpchk METH URI -> <METH> <URI> HTTP/1.0
870 - option httpchk METH URI VER -> <METH> <URI> <VER>
871
872See examples below.
873
874Since version 1.1.17, it is possible to specify backup servers. These servers
875are only sollicited when no other server is available. This may only be useful
876to serve a maintenance page, or define one active and one backup server (seldom
877used in TCP mode). To make a server a backup one, simply add the 'backup' option
878on its line. These servers also support cookies, so if a cookie is specified for
879a backup server, clients assigned to this server will stick to it even when the
880other ones come back. Conversely, if no cookie is assigned to such a server,
881the clients will get their cookies removed (empty cookie = removal), and will
882be balanced against other servers once they come back. Please note that there
883is no load-balancing among backup servers. If there are several backup servers,
884the second one will only be used when the first one dies, and so on.
885
886Since version 1.1.17, it is also possible to visually check the status of all
887servers at once. For this, you just have to send a SIGHUP signal to the proxy.
888The servers status will be dumped into the logs at the 'notice' level, as well
889as on <stderr> if not closed. For this reason, it's always a good idea to have
890one local log server at the 'notice' level.
891
willy tarreau982249e2005-12-18 00:57:06 +0100892Since version 1.1.28 and 1.2.1, if an instance loses all its servers, an
willy tarreau0174f312005-12-18 01:02:42 +0100893emergency message will be sent in the logs to inform the administator that an
willy tarreau982249e2005-12-18 00:57:06 +0100894immediate action must be taken.
895
willy tarreau0174f312005-12-18 01:02:42 +0100896Since version 1.1.30 and 1.2.3, several servers can share the same cookie
897value. This is particularly useful in backup mode, to select alternate paths
898for a given server for example, to provide soft-stop, or to direct the clients
899to a temporary page during an application restart. The principle is that when
900a server is dead, the proxy will first look for another server which shares the
901same cookie value for every client which presents the cookie. If there is no
902standard server for this cookie, it will then look for a backup server which
903shares the same name. Please consult the architecture guide for more information.
willy tarreau982249e2005-12-18 00:57:06 +0100904
willy tarreaueedaa9f2005-12-17 14:08:03 +0100905Examples :
906----------
907# same setup as in paragraph 3) with TCP monitoring
908 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100909 mode http
910 cookie SERVERID
911 balance roundrobin
912 server web1 192.168.1.1:80 cookie server01 check
913 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100914
915# same with HTTP monitoring via 'OPTIONS / HTTP/1.0'
916 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100917 mode http
918 cookie SERVERID
919 balance roundrobin
920 option httpchk
921 server web1 192.168.1.1:80 cookie server01 check
922 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100923
924# same with HTTP monitoring via 'OPTIONS /index.html HTTP/1.0'
925 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100926 mode http
927 cookie SERVERID
928 balance roundrobin
929 option httpchk /index.html
930 server web1 192.168.1.1:80 cookie server01 check
931 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100932
933# same with HTTP monitoring via 'HEAD /index.jsp? HTTP/1.1\r\nHost: www'
934 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100935 mode http
936 cookie SERVERID
937 balance roundrobin
938 option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www
939 server web1 192.168.1.1:80 cookie server01 check
940 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100941
willy tarreau0174f312005-12-18 01:02:42 +0100942# Load-balancing with 'prefixed cookie' persistence, and soft-stop using an
943# alternate port 81 on the server for health-checks.
944 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100945 mode http
946 cookie JSESSIONID prefix
947 balance roundrobin
948 option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www
949 server web1-norm 192.168.1.1:80 cookie s1 check port 81
950 server web2-norm 192.168.1.2:80 cookie s2 check port 81
951 server web1-stop 192.168.1.1:80 cookie s1 check port 80 backup
952 server web2-stop 192.168.1.2:80 cookie s2 check port 80 backup
willy tarreau0174f312005-12-18 01:02:42 +0100953
willy tarreaueedaa9f2005-12-17 14:08:03 +0100954# automatic insertion of a cookie in the server's response, and automatic
955# deletion of the cookie in the client request, while asking upstream caches
956# not to cache replies.
957 listen web_appl 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100958 mode http
959 cookie SERVERID insert nocache indirect
960 balance roundrobin
961 server web1 192.168.1.1:80 cookie server01 check
962 server web2 192.168.1.2:80 cookie server02 check
willy tarreaueedaa9f2005-12-17 14:08:03 +0100963
964# same with off-site application backup and local error pages server
965 listen web_appl 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100966 mode http
967 cookie SERVERID insert nocache indirect
968 balance roundrobin
969 server web1 192.168.1.1:80 cookie server01 check
970 server web2 192.168.1.2:80 cookie server02 check
971 server web-backup 192.168.2.1:80 cookie server03 check backup
972 server web-excuse 192.168.3.1:80 check backup
willy tarreaueedaa9f2005-12-17 14:08:03 +0100973
willy tarreauc5f73ed2005-12-18 01:26:38 +0100974# SMTP+TLS relaying with health-checks and backup servers
willy tarreaueedaa9f2005-12-17 14:08:03 +0100975
976 listen http_proxy :25,:587
willy tarreauc5f73ed2005-12-18 01:26:38 +0100977 mode tcp
978 balance roundrobin
979 server srv1 192.168.1.1 check port 25 inter 30000 rise 1 fall 2
980 server srv2 192.168.1.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +0100981
982
9833.2) Redistribute connections in case of failure
984------------------------------------------------
985In HTTP mode, if a server designated by a cookie does not respond, the clients
986may definitely stick to it because they cannot flush the cookie, so they will
987not be able to access the service anymore. Specifying 'redispatch' will allow
988the proxy to break their persistence and redistribute them to working servers.
989
990Example :
991---------
992 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100993 mode http
994 cookie SERVERID
995 dispatch 192.168.1.100:80
996 server web1 192.168.1.1:80 cookie server01
997 server web2 192.168.1.2:80 cookie server02
998 redispatch # send back to dispatch in case of connection failure
willy tarreaueedaa9f2005-12-17 14:08:03 +0100999
1000Up to, and including version 1.1.16, this parameter only applied to connection
1001failures. Since version 1.1.17, it also applies to servers which have been
1002detected as failed by the health check mechanism. Indeed, a server may be broken
1003but still accepting connections, which would not solve every case. But it is
1004possible to conserve the old behaviour, that is, make a client insist on trying
1005to connect to a server even if it is said to be down, by setting the 'persist'
1006option :
1007
1008 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001009 mode http
1010 option persist
1011 cookie SERVERID
1012 dispatch 192.168.1.100:80
1013 server web1 192.168.1.1:80 cookie server01
1014 server web2 192.168.1.2:80 cookie server02
1015 redispatch # send back to dispatch in case of connection failure
willy tarreaueedaa9f2005-12-17 14:08:03 +01001016
1017
10184) Additionnal features
1019=======================
1020
1021Other features are available. They are transparent mode, event logging and
1022header rewriting/filtering.
1023
willy tarreauc5f73ed2005-12-18 01:26:38 +01001024
willy tarreau0174f312005-12-18 01:02:42 +010010254.1) Network features
willy tarreaueedaa9f2005-12-17 14:08:03 +01001026---------------------
willy tarreau0174f312005-12-18 01:02:42 +010010274.1.1) Transparent mode
1028-----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +01001029In HTTP mode, the 'transparent' keyword allows to intercept sessions which are
1030routed through the system hosting the proxy. This mode was implemented as a
1031replacement for the 'dispatch' mode, since connections without cookie will be
1032sent to the original address while known cookies will be sent to the servers.
1033This mode implies that the system can redirect sessions to a local port.
1034
1035Example :
1036---------
1037 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001038 mode http
1039 transparent
1040 cookie SERVERID
1041 server server01 192.168.1.1:80
1042 server server02 192.168.1.2:80
willy tarreaueedaa9f2005-12-17 14:08:03 +01001043
1044 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
1045 --dport 80 -j REDIRECT --to-ports 65000
1046
1047Note :
1048------
1049If the port is left unspecified on the server, the port the client connected to
1050will be used. This allows to relay a full port range without using transparent
1051mode nor thousands of file descriptors, provided that the system can redirect
1052sessions to local ports.
1053
1054Example :
1055---------
1056 # redirect all ports to local port 65000, then forward to the server on the
1057 # original port.
1058 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001059 mode tcp
1060 server server01 192.168.1.1 check port 60000
1061 server server02 192.168.1.2 check port 60000
willy tarreaueedaa9f2005-12-17 14:08:03 +01001062
1063 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
1064 -j REDIRECT --to-ports 65000
1065
willy tarreau0174f312005-12-18 01:02:42 +010010664.1.2) Per-server source address binding
1067----------------------------------------
1068As of versions 1.1.30 and 1.2.3, it is possible to specify a particular source
1069to reach each server. This is useful when reaching backup servers from a
1070different LAN, or to use an alternate path to reach the same server. It is also
1071usable to provide source load-balancing for outgoing connections. Obviously,
1072the same source address is used to send health-checks.
1073
1074Example :
1075---------
1076 # use a particular source to reach both servers
1077 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001078 mode http
1079 balance roundrobin
1080 server server01 192.168.1.1:80 source 192.168.2.13
1081 server server02 192.168.1.2:80 source 192.168.2.13
willy tarreau0174f312005-12-18 01:02:42 +01001082
1083Example :
1084---------
1085 # use a particular source to reach each servers
1086 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001087 mode http
1088 balance roundrobin
1089 server server01 192.168.1.1:80 source 192.168.1.1
1090 server server02 192.168.2.1:80 source 192.168.2.1
willy tarreau0174f312005-12-18 01:02:42 +01001091
1092Example :
1093---------
1094 # provide source load-balancing to reach the same proxy through 2 WAN links
1095 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001096 mode http
1097 balance roundrobin
1098 server remote-proxy-way1 192.168.1.1:3128 source 192.168.2.1
1099 server remote-proxy-way2 192.168.1.1:3128 source 192.168.3.1
willy tarreau0174f312005-12-18 01:02:42 +01001100
1101Example :
1102---------
1103 # force a TCP connection to bind to a specific port
1104 listen http_proxy 0.0.0.0:2000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001105 mode tcp
1106 balance roundrobin
1107 server srv1 192.168.1.1:80 source 192.168.2.1:20
1108 server srv2 192.168.1.2:80 source 192.168.2.1:20
willy tarreau0174f312005-12-18 01:02:42 +01001109
willy tarreaub952e1d2005-12-18 01:31:20 +010011104.1.3) TCP keep-alive
1111---------------------
1112With version 1.2.7, it becomes possible to enable TCP keep-alives on both the
1113client and server sides. This makes it possible to prevent long sessions from
1114expiring on external layer 4 components such as firewalls and load-balancers.
1115It also allows the system to terminate dead sessions when no timeout has been
1116set (not recommanded). The proxy cannot set the keep-alive probes intervals nor
1117maximal count, consult your operating system manual for this. There are 3
1118options to enable TCP keep-alive :
1119
1120 option tcpka # enables keep-alive both on client and server side
1121 option clitcpka # enables keep-alive only on client side
1122 option srvtcpka # enables keep-alive only on server side
1123
willy tarreaueedaa9f2005-12-17 14:08:03 +01001124
11254.2) Event logging
1126------------------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001127
1128HAProxy's strength certainly lies in its precise logs. It probably provides the
1129finest level of information available for such a product, which is very
1130important for troubleshooting complex environments. Standard log information
1131include client ports, TCP/HTTP state timers, precise session state at
1132termination and precise termination cause, information about decisions to
1133direct trafic to a server, and of course the ability to capture arbitrary
1134headers.
1135
1136In order to improve administrators reactivity, it offers a great transparency
1137about encountered problems, both internal and external, and it is possible to
1138send logs to different sources at the same time with different level filters :
1139
1140 - global process-level logs (system errors, start/stop, etc..)
1141 - per-listener system and internal errors (lack of resource, bugs, ...)
1142 - per-listener external troubles (servers up/down, max connections)
1143 - per-listener activity (client connections), either at the establishment or
1144 at the termination.
1145
1146The ability to distribute different levels of logs to different log servers
1147allow several production teams to interact and to fix their problems as soon
1148as possible. For example, the system team might monitor system-wide errors,
1149while the application team might be monitoring the up/down for their servers in
1150real time, and the security team might analyze the activity logs with one hour
1151delay.
1152
willy tarreauc1cae632005-12-17 14:12:23 +010011534.2.1) Log levels
1154-----------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001155TCP and HTTP connections can be logged with informations such as date, time,
1156source IP address, destination address, connection duration, response times,
1157HTTP request, the HTTP return code, number of bytes transmitted, the conditions
1158in which the session ended, and even exchanged cookies values, to track a
1159particular user's problems for example. All messages are sent to up to two
1160syslog servers. Consult section 1.1 for more info about log facilities. The
1161syntax follows :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001162
willy tarreau197e8ec2005-12-17 14:10:59 +01001163 log <address_1> <facility_1> [max_level_1]
1164 log <address_2> <facility_2> [max_level_2]
1165or
willy tarreaueedaa9f2005-12-17 14:08:03 +01001166 log global
1167
willy tarreau197e8ec2005-12-17 14:10:59 +01001168Note :
1169------
1170The particular syntax 'log global' means that the same log configuration as the
1171'global' section will be used.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001172
willy tarreau197e8ec2005-12-17 14:10:59 +01001173Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001174---------
1175 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001176 mode http
1177 log 192.168.2.200 local3
1178 log 192.168.2.201 local4
willy tarreaueedaa9f2005-12-17 14:08:03 +01001179
willy tarreauc1cae632005-12-17 14:12:23 +010011804.2.2) Log format
1181-----------------
1182By default, connections are logged at the TCP level, as soon as the session
1183establishes between the client and the proxy. By enabling the 'tcplog' option,
1184the proxy will wait until the session ends to generate an enhanced log
1185containing more information such as session duration and its state during the
1186disconnection.
1187
willy tarreauc5f73ed2005-12-18 01:26:38 +01001188Example of TCP logging :
1189------------------------
willy tarreau982249e2005-12-18 00:57:06 +01001190 listen relais-tcp 0.0.0.0:8000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001191 mode tcp
1192 option tcplog
1193 log 192.168.2.200 local3
willy tarreau982249e2005-12-18 00:57:06 +01001194
willy tarreauc5f73ed2005-12-18 01:26:38 +01001195>>> haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28] relais-tcp Srv1 0/5007 0 -- 1/1
1196
1197 Field Format Example
1198
1199 1 process_name '[' pid ']:' haproxy[18989]:
1200 2 client_ip ':' client_port 127.0.0.1:34550
1201 3 '[' date ']' [15/Oct/2003:15:24:28]
1202 4 listener_name relais-tcp
1203 5 server_name Srv1
1204 6 connect_time '/' total_time 0/5007
1205 7 bytes_read 0
1206 8 termination_state --
1207 9 listener_conns '/' process_conns 1/1
1208
willy tarreau982249e2005-12-18 00:57:06 +01001209
willy tarreauc1cae632005-12-17 14:12:23 +01001210Another option, 'httplog', provides more detailed information about HTTP
1211contents, such as the request and some cookies. In the event where an external
1212component would establish frequent connections to check the service, logs may be
1213full of useless lines. So it is possible not to log any session which didn't
1214transfer any data, by the setting of the 'dontlognull' option. This only has
1215effect on sessions which are established then closed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001216
willy tarreauc5f73ed2005-12-18 01:26:38 +01001217Example of HTTP logging :
1218-------------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +01001219 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001220 mode http
1221 option httplog
1222 option dontlognull
1223 log 192.168.2.200 local3
1224
1225>>> haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57] relais-http Srv1 9/7/147/723 200 243 - - ---- 3/3 "HEAD / HTTP/1.0"
willy tarreaueedaa9f2005-12-17 14:08:03 +01001226
willy tarreauc5f73ed2005-12-18 01:26:38 +01001227More complete example
1228 haproxy[18989]: 10.0.0.1:34552 [15/Oct/2003:15:26:31] relais-http Srv1 3183/-1/-1/11215 503 0 - - SC-- 202/205 {w.ods.org|Mozilla} {} "HEAD / HTTP/1.0"
1229
1230 Field Format Example
1231
1232 1 process_name '[' pid ']:' haproxy[18989]:
1233 2 client_ip ':' client_port 10.0.0.1:34552
1234 3 '[' date ']' [15/Oct/2003:15:26:31]
1235 4 listener_name relais-http
1236 5 server_name Srv1
1237 6 Tq '/' Tc '/' Tr '/' Tt 3183/-1/-1/11215
1238 7 HTTP_return_code 503
1239 8 bytes_read 0
1240 9 captured_request_cookie -
1241 10 captured_response_cookie -
1242 11 termination_state SC--
1243 12 listener_conns '/' process_conns 202/205
1244 13 '{' captured_request_headers '}' {w.ods.org|Mozilla}
1245 14 '{' captured_response_headers '}' {}
1246 15 '"' HTTP_request '"' "HEAD / HTTP/1.0"
1247
1248Note for log parsers: the URI is ALWAYS the end of the line starting with the
1249 first double quote '"'.
willy tarreau982249e2005-12-18 00:57:06 +01001250
1251The problem when logging at end of connection is that you have no clue about
1252what is happening during very long sessions. To workaround this problem, a
1253new option 'logasap' has been introduced in 1.1.28/1.2.1. When specified, the
1254proxy will log as soon as possible, just before data transfer begins. This means
1255that in case of TCP, it will still log the connection status to the server, and
1256in case of HTTP, it will log just after processing the server headers. In this
1257case, the number of bytes reported is the number of header bytes sent to the
1258client.
1259
1260In order to avoid confusion with normal logs, the total time field and the
1261number of bytes are prefixed with a '+' sign which mean that real numbers are
1262certainly bigger.
1263
1264Example :
1265---------
1266
1267 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001268 mode http
1269 option httplog
1270 option dontlognull
1271 option logasap
1272 log 192.168.2.200 local3
willy tarreau982249e2005-12-18 00:57:06 +01001273
willy tarreauc5f73ed2005-12-18 01:26:38 +01001274>>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17] relais-http Srv1 9/7/14/+30 200 +243 - - ---- 3/3 "GET /image.iso HTTP/1.0"
willy tarreau982249e2005-12-18 00:57:06 +01001275
willy tarreauc1cae632005-12-17 14:12:23 +010012764.2.3) Timing events
1277--------------------
1278Timers provide a great help in trouble shooting network problems. All values
1279are reported in milliseconds (ms). In HTTP mode, four control points are
1280reported under the form 'Tq/Tc/Tr/Tt' :
1281
1282 - Tq: total time to get the client request.
1283 It's the time elapsed between the moment the client connection was accepted
1284 and the moment the proxy received the last HTTP header. The value '-1'
1285 indicates that the end of headers (empty line) has never been seen.
1286
1287 - Tc: total time to establish the TCP connection to the server.
1288 It's the time elapsed between the moment the proxy sent the connection
1289 request, and the moment it was acknowledged, or between the TCP SYN packet
1290 and the matching SYN/ACK in return. The value '-1' means that the
1291 connection never established.
1292
1293 - Tr: server response time. It's the time elapsed between the moment the
1294 TCP connection was established to the server and the moment it send its
1295 complete response header. It purely shows its request processing time,
1296 without the network overhead due to the data transmission. The value '-1'
1297 means that the last the response header (empty line) was never seen.
1298
1299 - Tt: total session duration time, between the moment the proxy accepted it
willy tarreau982249e2005-12-18 00:57:06 +01001300 and the moment both ends were closed. The exception is when the 'logasap'
1301 option is specified. In this case, it only equals (Tq+Tc+Tr), and is
1302 prefixed with a '+' sign. From this field, we can deduce Td, the data
1303 transmission time, by substracting other timers when valid :
willy tarreauc1cae632005-12-17 14:12:23 +01001304
1305 Td = Tt - (Tq + Tc + Tr)
1306
1307 Timers with '-1' values have to be excluded from this equation.
1308
1309In TCP mode ('option tcplog'), only Tc and Tt are reported.
1310
1311These timers provide precious indications on trouble causes. Since the TCP
1312protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure
1313that timers close to multiples of 3s are nearly always related to packets lost
1314due to network problems (wires or negociation). Moreover, if <Tt> is close to
1315a timeout value specified in the configuration, it often means that a session
1316has been aborted on time-out.
1317
1318Most common cases :
1319
1320 - If Tq is close to 3000, a packet has probably been lost between the client
1321 and the proxy.
1322 - If Tc is close to 3000, a packet has probably been lost between the server
1323 and the proxy during the server connection phase. This one should always be
1324 very low (less than a few tens).
1325 - If Tr is nearly always lower than 3000 except some rare values which seem to
1326 be the average majored by 3000, there are probably some packets lost between
1327 the proxy and the server.
1328 - If Tt is often slightly higher than a time-out, it's often because the
1329 client and the server use HTTP keep-alive and the session is maintained
1330 after the response ends. Se further for how to disable HTTP keep-alive.
1331
1332Other cases ('xx' means any value to be ignored) :
1333 -1/xx/xx/Tt : the client was not able to send its complete request in time,
willy tarreauc5f73ed2005-12-18 01:26:38 +01001334 or that it aborted it too early.
willy tarreauc1cae632005-12-17 14:12:23 +01001335 Tq/-1/xx/Tt : the connection could not establish on the server. Either it
willy tarreauc5f73ed2005-12-18 01:26:38 +01001336 refused it or it timed out after Tt-Tq ms.
willy tarreauc1cae632005-12-17 14:12:23 +01001337 Tq/Tc/-1/Tt : the server has accepted the connection but did not return a
willy tarreauc5f73ed2005-12-18 01:26:38 +01001338 complete response in time, or it closed its connexion
1339 unexpectedly, after Tt-(Tq+Tc) ms.
willy tarreauc1cae632005-12-17 14:12:23 +01001340
13414.2.4) Session state at disconnection
1342-------------------------------------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001343TCP and HTTP logs provide a session completion indicator in the
1344<termination_state> field, just before the number of active
1345connections. It is 2-characters long in TCP, and 4-characters long in
1346HTTP, each of which has a special meaning :
1347
willy tarreau197e8ec2005-12-17 14:10:59 +01001348 - On the first character, a code reporting the first event which caused the
1349 session to terminate :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001350
willy tarreauc5f73ed2005-12-18 01:26:38 +01001351 C : the TCP session was unexpectedly aborted by the client.
1352
1353 S : the TCP session was unexpectedly aborted by the server, or the
1354 server explicitly refused it.
1355
1356 P : the session was prematurely aborted by the proxy, because of a
1357 connection limit enforcement, because a DENY filter was matched,
1358 or because of a security check which detected and blocked a
1359 dangerous error in server response which might have caused
1360 information leak (eg: cacheable cookie).
1361
1362 R : a resource on the proxy has been exhausted (memory, sockets, source
1363 ports, ...). Usually, this appears during the connection phase, and
1364 system logs should contain a copy of the precise error.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001365
willy tarreauc5f73ed2005-12-18 01:26:38 +01001366 I : an internal error was identified by the proxy during a self-check.
1367 This should NEVER happen, and you are encouraged to report any log
1368 containing this, because this is a bug.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001369
willy tarreauc5f73ed2005-12-18 01:26:38 +01001370 c : the client-side time-out expired first.
1371
1372 s : the server-side time-out expired first.
1373
1374 - : normal session completion.
1375
1376 - on the second character, the TCP/HTTP session state when it was closed :
1377
1378 R : waiting for complete REQUEST from the client (HTTP only). Nothing
1379 was sent to any server.
1380
1381 C : waiting for CONNECTION to establish on the server. The server might
1382 at most have noticed a connection attempt.
1383
1384 H : waiting for, receiving and processing server HEADERS (HTTP only).
1385
1386 D : the session was in the DATA phase.
1387
1388 L : the proxy was still transmitting LAST data to the client while the
1389 server had already finished.
1390
1391 - : normal session completion after end of data transfer.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001392
willy tarreau197e8ec2005-12-17 14:10:59 +01001393 - the third character tells whether the persistence cookie was provided by
willy tarreauc1cae632005-12-17 14:12:23 +01001394 the client (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001395
willy tarreauc5f73ed2005-12-18 01:26:38 +01001396 N : the client provided NO cookie. This is usually the case on new
1397 connections.
1398
1399 I : the client provided an INVALID cookie matching no known
1400 server. This might be caused by a recent configuration change,
1401 mixed cookies between HTTP/HTTPS sites, or an attack.
1402
1403 D : the client provided a cookie designating a server which was DOWN,
1404 so either the 'persist' option was used and the client was sent to
1405 this server, or it was not set and the client was redispatched to
1406 another server.
1407
1408 V : the client provided a valid cookie, and was sent to the associated
1409 server.
1410
1411 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001412
willy tarreau197e8ec2005-12-17 14:10:59 +01001413 - the last character reports what operations were performed on the persistence
willy tarreauc1cae632005-12-17 14:12:23 +01001414 cookie returned by the server (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001415
willy tarreauc5f73ed2005-12-18 01:26:38 +01001416 N : NO cookie was provided by the server, and none was inserted either.
1417
1418 I : no cookie was provided by the server, and the proxy INSERTED one.
1419
willy tarreau197e8ec2005-12-17 14:10:59 +01001420 P : a cookie was PROVIDED by the server and transmitted as-is.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001421
willy tarreauc5f73ed2005-12-18 01:26:38 +01001422 R : the cookie provided by the server was REWRITTEN by the proxy.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001423
willy tarreauc5f73ed2005-12-18 01:26:38 +01001424 D : the cookie provided by the server was DELETED by the proxy.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001425
willy tarreauc5f73ed2005-12-18 01:26:38 +01001426 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001427
willy tarreauc5f73ed2005-12-18 01:26:38 +01001428The combination of the two first flags give a lot of information about what was
1429happening when the session terminated. It can be helpful to detect server
1430saturation, network troubles, local system resource starvation, attacks, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01001431
willy tarreauc5f73ed2005-12-18 01:26:38 +01001432The most common termination flags combinations are indicated here.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001433
willy tarreauc5f73ed2005-12-18 01:26:38 +01001434 Flags Reason
1435 CR The client aborted before sending a full request. Most probably the
1436 request was done by hand using a telnet client, and aborted early.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001437
willy tarreauc5f73ed2005-12-18 01:26:38 +01001438 cR The client timed out before sending a full request. This is sometimes
1439 caused by too large TCP MSS values on the client side for PPPoE
1440 networks which cannot transport full-sized packets, or by clients
1441 sending requests by hand and not typing fast enough.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001442
willy tarreauc5f73ed2005-12-18 01:26:38 +01001443 SC The server explicitly refused the connection (the proxy received a
1444 TCP RST or an ICMP in return). Under some circumstances, it can
1445 also be the network stack telling the proxy that the server is
1446 unreachable (eg: no route, or no ARP response on local network).
willy tarreau982249e2005-12-18 00:57:06 +01001447
willy tarreauc5f73ed2005-12-18 01:26:38 +01001448 sC The connection to the server did not complete during contimeout.
willy tarreau982249e2005-12-18 00:57:06 +01001449
willy tarreauc5f73ed2005-12-18 01:26:38 +01001450 PC The proxy refused to establish a connection to the server because the
1451 maxconn limit has been reached. The listener's maxconn parameter may
1452 be increased in the proxy configuration, as well as the global
1453 maxconn parameter.
willy tarreauc1cae632005-12-17 14:12:23 +01001454
willy tarreauc5f73ed2005-12-18 01:26:38 +01001455 RC A local resource has been exhausted (memory, sockets, source ports)
1456 preventing the connection to the server from establishing. The error
1457 logs will tell precisely what was missing. Anyway, this can only be
1458 solved by system tuning.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001459
willy tarreauc5f73ed2005-12-18 01:26:38 +01001460 cH The client timed out during a POST request. This is sometimes caused
1461 by too large TCP MSS values for PPPoE networks which cannot transport
1462 full-sized packets.
willy tarreauc1cae632005-12-17 14:12:23 +01001463
willy tarreauc5f73ed2005-12-18 01:26:38 +01001464 SH The server aborted before sending its full headers, or it crashed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001465
willy tarreauc5f73ed2005-12-18 01:26:38 +01001466 sH The server failed to reply during the srvtimeout delay, which
1467 indicates too long transactions, probably caused by back-end
1468 saturation. The only solutions are to fix the problem on the
1469 application or to increase the 'srvtimeout' parameter to support
1470 longer delays (at the risk of the client giving up anyway).
1471
1472 PR The proxy blocked the client's request, either because of an invalid
1473 HTTP syntax, in which case it returned an HTTP 400 error to the
1474 client, or because a deny filter matched, in which case it returned
1475 an HTTP 403 error.
1476
1477 PH The proxy blocked the server's response, because it was invalid,
1478 incomplete, dangerous (cache control), or matched a security filter.
1479 In any case, an HTTP 502 error is sent to the client.
1480
1481 cD The client did not read any data for as long as the clitimeout delay.
1482 This is often caused by network failures on the client side.
1483
1484 CD The client unexpectedly aborted during data transfer. This is either
1485 caused by a browser crash, or by a keep-alive session between the
1486 server and the client terminated first by the client.
1487
1488 sD The server did nothing during the srvtimeout delay. This is often
1489 caused by too short timeouts on L4 equipements before the server
1490 (firewalls, load-balancers, ...).
1491
14924.2.5) Non-printable characters
willy tarreau4302f492005-12-18 01:00:37 +01001493-------------------------------
1494As of version 1.1.29, non-printable characters are not sent as-is into log
1495files, but are converted to their two-digits hexadecimal representation,
1496prefixed by the character '#'. The only characters that can now be logged
1497without being escaped are between 32 and 126 (inclusive). Obviously, the
1498escape character '#' is also encoded to avoid any ambiguity. It is the same for
1499the character '"', as well as '{', '|' and '}' when logging headers.
1500
willy tarreauc5f73ed2005-12-18 01:26:38 +010015014.2.6) Capturing HTTP headers and cookies
1502-----------------------------------------
1503Version 1.1.23 brought cookie capture, and 1.1.29 the header capture. All this
1504is performed using the 'capture' keyword.
1505
1506Cookie capture makes it easy to track a complete user session. The syntax is :
1507
1508 capture cookie <cookie_prefix> len <capture_length>
1509
1510This will enable cookie capture from both requests and responses. This way,
1511it's easy to detect when a user switches to a new session for example, because
1512the server will reassign it a new cookie.
1513
1514The FIRST cookie whose name starts with <cookie_prefix> will be captured, and
1515logged as 'NAME=value', without exceeding <capture_length> characters (64 max).
1516When the cookie name is fixed and known, it's preferable to suffix '=' to it to
1517ensure that no other cookie will be logged.
1518
1519Examples :
1520----------
1521 # capture the first cookie whose name starts with "ASPSESSION"
1522 capture cookie ASPSESSION len 32
1523
1524 # capture the first cookie whose name is exactly "vgnvisitor"
1525 capture cookie vgnvisitor= len 32
1526
1527In the logs, the field preceeding the completion indicator contains the cookie
1528value as sent by the server, preceeded by the cookie value as sent by the
1529client. Each of these field is replaced with '-' when no cookie was seen or
1530when the option is disabled.
1531
1532Header captures have a different goal. They are useful to track unique request
1533identifiers set by a previous proxy, virtual host names, user-agents, POST
1534content-length, referrers, etc. In the response, one can search for information
1535about the response length, how the server asked the cache to behave, or an
1536object location during a redirection. As for cookie captures, it is both
1537possible to include request headers and response headers at the same time. The
1538syntax is :
willy tarreau4302f492005-12-18 01:00:37 +01001539
1540 capture request header <name> len <max length>
1541 capture response header <name> len <max length>
1542
1543Note: Header names are not case-sensitive.
1544
1545Examples:
1546---------
1547 # keep the name of the virtual server
1548 capture request header Host len 20
1549 # keep the amount of data uploaded during a POST
1550 capture request header Content-Length len 10
1551
1552 # note the expected cache behaviour on the response
1553 capture response header Cache-Control len 8
1554 # note the URL location during a redirection
1555 capture response header Location len 20
1556
1557Non-existant headers are logged as empty strings, and if one header appears more
1558than once, only its last occurence will be kept. Request headers are grouped
1559within braces '{' and '}' in the same order as they were declared, and delimited
1560with a vertical bar '|' without any space. Response headers follow the same
1561representation, but are displayed after a space following the request headers
1562block. These blocks are displayed just before the HTTP request in the logs.
willy tarreauc5f73ed2005-12-18 01:26:38 +01001563
willy tarreau4302f492005-12-18 01:00:37 +01001564Example :
1565
willy tarreauc5f73ed2005-12-18 01:26:38 +01001566 Config:
1567
1568 capture request header Host len 20
1569 capture request header Content-Length len 10
1570 capture request header Referer len 20
1571 capture response header Server len 20
1572 capture response header Content-Length len 10
1573 capture response header Cache-Control len 8
1574 capture response header Via len 20
1575 capture response header Location len 20
1576
1577 Log :
1578
1579 Aug 9 20:26:09 localhost haproxy[2022]: 127.0.0.1:34014 [09/Aug/2004:20:26:09] relais-http netcache 0/0/162/+162 200 +350 - - ---- {fr.adserver.yahoo.co||http://fr.f416.mail.} {|864|private||} "GET http://fr.adserver.yahoo.com/"
1580 Aug 9 20:30:46 localhost haproxy[2022]: 127.0.0.1:34020 [09/Aug/2004:20:30:46] relais-http netcache 0/0/182/+182 200 +279 - - ---- {w.ods.org||} {Formilux/0.1.8|3495|||} "GET http://w.ods.org/sytadin.html HTTP/1.1"
1581 Aug 9 20:30:46 localhost haproxy[2022]: 127.0.0.1:34028 [09/Aug/2004:20:30:46] relais-http netcache 0/2/126/+128 200 +223 - - ---- {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"
1582
1583
15844.2.7) Examples of logs
1585-----------------------
1586- haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57] relais-http Srv1 6559/7/147/6723 200 243 - - ---- 3/5 "HEAD / HTTP/1.0"
1587 => long request (6.5s) entered by hand through 'telnet'. The server replied
1588 in 147 ms, and the session ended normally ('----')
1589
1590- haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17] relais-http Srv1 9/7/14/+30 200 +243 - - ---- 3/3 "GET /image.iso HTTP/1.0"
1591 => request for a long data transfer. The 'logasap' option was specified, so
1592 the log was produced just before transfering data. The server replied in
1593 14 ms, 243 bytes of headers were sent to the client, and total time from
1594 accept to first data byte is 30 ms.
1595
1596- haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17] relais-http Srv1 9/7/14/30 502 243 - - PH-- 2/3 "GET /cgi-bin/bug.cgi? HTTP/1.0"
1597 => the proxy blocked a server response either because of an 'rspdeny' or
1598 'rspideny' filter, or because it blocked sensible information which risked
1599 being cached. In this case, the response is replaced with a '502 bad
1600 gateway'.
1601
1602- haproxy[18113]: 127.0.0.1:34548 [15/Oct/2003:15:18:55] relais-http <NOSRV> -1/-1/-1/8490 -1 0 - - CR-- 2/2 ""
1603 => the client never completed its request and aborted itself ('C---') after
1604 8.5s, while the proxy was waiting for the request headers ('-R--').
1605 Nothing was sent to the server.
1606
1607- haproxy[18113]: 127.0.0.1:34549 [15/Oct/2003:15:19:06] relais-http <NOSRV> -1/-1/-1/50001 408 0 - - cR-- 2/2 ""
1608 => The client never completed its request, which was aborted by the time-out
1609 ('c---') after 50s, while the proxy was waiting for the request headers ('-R--').
1610 Nothing was sent to the server, but the proxy could send a 408 return code
1611 to the client.
willy tarreau4302f492005-12-18 01:00:37 +01001612
willy tarreauc5f73ed2005-12-18 01:26:38 +01001613- haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28] relais-tcp Srv1 0/5007 0 cD
1614 => This is a 'tcplog' entry. Client-side time-out ('c----') occured after 5s.
willy tarreau4302f492005-12-18 01:00:37 +01001615
willy tarreauc5f73ed2005-12-18 01:26:38 +01001616- haproxy[18989]: 10.0.0.1:34552 [15/Oct/2003:15:26:31] relais-http Srv1 3183/-1/-1/11215 503 0 - - SC-- 202/205 "HEAD / HTTP/1.0"
1617 => The request took 3s to complete (probably a network problem), and the
1618 connection to the server failed ('SC--') after 4 attemps of 2 seconds
1619 (config says 'retries 3'), then a 503 error code was sent to the client.
1620 There were 202 connections on this proxy, and 205 on the global process.
1621 It is possible that the server refused the connection because of too many
1622 already established.
willy tarreau4302f492005-12-18 01:00:37 +01001623
willy tarreau4302f492005-12-18 01:00:37 +01001624
willy tarreau197e8ec2005-12-17 14:10:59 +010016254.3) HTTP header manipulation
1626-----------------------------
1627In HTTP mode, it is possible to rewrite, add or delete some of the request and
1628response headers based on regular expressions. It is also possible to block a
1629request or a response if a particular header matches a regular expression,
1630which is enough to stops most elementary protocol attacks, and to protect
1631against information leak from the internal network. But there is a limitation
1632to this : since haproxy's HTTP engine knows nothing about keep-alive, only
1633headers passed during the first request of a TCP session will be seen. All
1634subsequent headers will be considered data only and not analyzed. Furthermore,
1635haproxy doesn't touch data contents, it stops at the end of headers.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001636
willy tarreau197e8ec2005-12-17 14:10:59 +01001637The syntax is :
1638 reqadd <string> to add a header to the request
1639 reqrep <search> <replace> to modify the request
1640 reqirep <search> <replace> same, but ignoring the case
1641 reqdel <search> to delete a header in the request
1642 reqidel <search> same, but ignoring the case
1643 reqallow <search> definitely allow a request if a header matches <search>
1644 reqiallow <search> same, but ignoring the case
1645 reqdeny <search> denies a request if a header matches <search>
1646 reqideny <search> same, but ignoring the case
1647 reqpass <search> ignore a header matching <search>
1648 reqipass <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01001649
willy tarreau197e8ec2005-12-17 14:10:59 +01001650 rspadd <string> to add a header to the response
1651 rsprep <search> <replace> to modify the response
1652 rspirep <search> <replace> same, but ignoring the case
1653 rspdel <search> to delete the response
1654 rspidel <search> same, but ignoring the case
willy tarreau982249e2005-12-18 00:57:06 +01001655 rspdeny <search> replaces a response with a HTTP 502 if a header matches <search>
1656 rspideny <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01001657
1658
willy tarreau197e8ec2005-12-17 14:10:59 +01001659<search> is a POSIX regular expression (regex) which supports grouping through
1660parenthesis (without the backslash). Spaces and other delimiters must be
1661prefixed with a backslash ('\') to avoid confusion with a field delimiter.
1662Other characters may be prefixed with a backslash to change their meaning :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001663
willy tarreau197e8ec2005-12-17 14:10:59 +01001664 \t for a tab
1665 \r for a carriage return (CR)
1666 \n for a new line (LF)
1667 \ to mark a space and differentiate it from a delimiter
1668 \# to mark a sharp and differentiate it from a comment
1669 \\ to use a backslash in a regex
1670 \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy)
1671 \xXX to write the ASCII hex code XX as in the C language
willy tarreaueedaa9f2005-12-17 14:08:03 +01001672
1673
willy tarreau197e8ec2005-12-17 14:10:59 +01001674<replace> containst the string to be used to replace the largest portion of text
1675matching the regex. It can make use of the special characters above, and can
1676reference a substring delimited by parenthesis in the regex, by the group
1677numerical order from 1 to 9. In this case, you would write a backslah ('\')
1678immediately followed by one digit indicating the group position.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001679
willy tarreau197e8ec2005-12-17 14:10:59 +01001680<string> represents the string which will systematically be added after the last
1681header line. It can also use special characters above.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001682
willy tarreau197e8ec2005-12-17 14:10:59 +01001683Notes :
1684-------
1685 - the first line is considered as a header, which makes it possible to rewrite
1686 or filter HTTP requests URIs or response codes.
1687 - 'reqrep' is the equivalent of 'cliexp' in version 1.0, and 'rsprep' is the
1688 equivalent of 'srvexp' in 1.0. Those names are still supported but
1689 deprecated.
1690 - for performances reasons, the number of characters added to a request or to
1691 a response is limited to 4096 since version 1.1.5 (it was 256 before). This
1692 value is easy to modify in the code if needed (#define). If it is too short
1693 on occasional uses, it is possible to gain some space by removing some
1694 useless headers before adding new ones.
willy tarreau982249e2005-12-18 00:57:06 +01001695 - a denied request will generate an "HTTP 403 forbidden" response, while a
1696 denied response will generate an "HTTP 502 Bad gateway" response.
1697
willy tarreaueedaa9f2005-12-17 14:08:03 +01001698
willy tarreau197e8ec2005-12-17 14:10:59 +01001699Examples :
1700----------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001701 ###### a few examples ######
willy tarreau197e8ec2005-12-17 14:10:59 +01001702
willy tarreauc5f73ed2005-12-18 01:26:38 +01001703 # rewrite 'online.fr' instead of 'free.fr' for GET and POST requests
1704 reqrep ^(GET\ .*)(.free.fr)(.*) \1.online.fr\3
1705 reqrep ^(POST\ .*)(.free.fr)(.*) \1.online.fr\3
willy tarreau197e8ec2005-12-17 14:10:59 +01001706
willy tarreauc5f73ed2005-12-18 01:26:38 +01001707 # force proxy connections to close
1708 reqirep ^Proxy-Connection:.* Proxy-Connection:\ close
1709 # rewrite locations
1710 rspirep ^(Location:\ )([^:]*://[^/]*)(.*) \1\3
willy tarreaueedaa9f2005-12-17 14:08:03 +01001711
willy tarreauc5f73ed2005-12-18 01:26:38 +01001712 ###### A full configuration being used on production ######
willy tarreaueedaa9f2005-12-17 14:08:03 +01001713
willy tarreau197e8ec2005-12-17 14:10:59 +01001714 # Every header should end with a colon followed by one space.
willy tarreauc5f73ed2005-12-18 01:26:38 +01001715 reqideny ^[^:\ ]*[\ ]*$
willy tarreaueedaa9f2005-12-17 14:08:03 +01001716
willy tarreau197e8ec2005-12-17 14:10:59 +01001717 # block Apache chunk exploit
willy tarreauc5f73ed2005-12-18 01:26:38 +01001718 reqideny ^Transfer-Encoding:[\ ]*chunked
1719 reqideny ^Host:\ apache-
willy tarreaueedaa9f2005-12-17 14:08:03 +01001720
willy tarreau197e8ec2005-12-17 14:10:59 +01001721 # block annoying worms that fill the logs...
willy tarreauc5f73ed2005-12-18 01:26:38 +01001722 reqideny ^[^:\ ]*\ .*(\.|%2e)(\.|%2e)(%2f|%5c|/|\\\\)
1723 reqideny ^[^:\ ]*\ ([^\ ]*\ [^\ ]*\ |.*%00)
1724 reqideny ^[^:\ ]*\ .*<script
1725 reqideny ^[^:\ ]*\ .*/(root\.exe\?|cmd\.exe\?|default\.ida\?)
willy tarreau197e8ec2005-12-17 14:10:59 +01001726
1727 # allow other syntactically valid requests, and block any other method
willy tarreauc5f73ed2005-12-18 01:26:38 +01001728 reqipass ^(GET|POST|HEAD|OPTIONS)\ /.*\ HTTP/1\.[01]$
1729 reqipass ^OPTIONS\ \\*\ HTTP/1\.[01]$
1730 reqideny ^[^:\ ]*\
willy tarreau197e8ec2005-12-17 14:10:59 +01001731
1732 # force connection:close, thus disabling HTTP keep-alive
willy tarreauc5f73ed2005-12-18 01:26:38 +01001733 option httpclose
willy tarreau197e8ec2005-12-17 14:10:59 +01001734
willy tarreauc5f73ed2005-12-18 01:26:38 +01001735 # change the server name
1736 rspidel ^Server:\
1737 rspadd Server:\ Formilux/0.1.8
willy tarreau197e8ec2005-12-17 14:10:59 +01001738
1739
willy tarreau982249e2005-12-18 00:57:06 +01001740Also, the 'forwardfor' option creates an HTTP 'X-Forwarded-For' header which
willy tarreauc1cae632005-12-17 14:12:23 +01001741contains the client's IP address. This is useful to let the final web server
1742know what the client address was (eg for statistics on domains).
1743
willy tarreau982249e2005-12-18 00:57:06 +01001744Last, the 'httpclose' option removes any 'Connection' header both ways, and
1745adds a 'Connection: close' header in each direction. This makes it easier to
1746disable HTTP keep-alive than the previous 4-rules block..
1747
willy tarreauc1cae632005-12-17 14:12:23 +01001748Example :
1749---------
1750 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001751 mode http
1752 log global
1753 option httplog
1754 option dontlognull
1755 option forwardfor
1756 option httpclose
1757
willy tarreau197e8ec2005-12-17 14:10:59 +01001758
17594.4) Load balancing with persistence
1760------------------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001761Combining cookie insertion with internal load balancing allows to transparently
1762bring persistence to applications. The principle is quite simple :
1763 - assign a cookie value to each server
1764 - enable the load balancing between servers
1765 - insert a cookie into responses resulting from the balancing algorithm
1766 (indirect accesses), end ensure that no upstream proxy will cache it.
1767 - remove the cookie in the request headers so that the application never sees
1768 it.
1769
1770Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001771---------
1772 listen application 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001773 mode http
1774 cookie SERVERID insert nocache indirect
1775 balance roundrobin
1776 server srv1 192.168.1.1:80 cookie server01 check
1777 server srv2 192.168.1.2:80 cookie server02 check
willy tarreaueedaa9f2005-12-17 14:08:03 +01001778
willy tarreau0174f312005-12-18 01:02:42 +01001779The other solution brought by versions 1.1.30 and 1.2.3 is to reuse a cookie
1780from the server, and prefix the server's name to it. In this case, don't forget
1781to force "httpclose" mode so that you can be assured that every subsequent
1782request will have its cookie fixed.
1783
1784 listen application 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001785 mode http
1786 cookie JSESSIONID prefix
1787 balance roundrobin
1788 server srv1 192.168.1.1:80 cookie srv1 check
1789 server srv2 192.168.1.2:80 cookie srv2 check
1790 option httpclose
willy tarreau0174f312005-12-18 01:02:42 +01001791
1792
willy tarreau982249e2005-12-18 00:57:06 +010017934.5) Protection against information leak from the servers
1794---------------------------------------------------------
1795In versions 1.1.28/1.2.1, a new option 'checkcache' was created. It carefully
1796checks 'Cache-control', 'Pragma' and 'Set-cookie' headers in server response
1797to check if there's a risk of caching a cookie on a client-side proxy. When this
1798option is enabled, the only responses which can be delivered to the client are :
1799 - all those without 'Set-Cookie' header ;
1800 - all those with a return code other than 200, 203, 206, 300, 301, 410,
1801 provided that the server has not set a 'Cache-control: public' header ;
1802 - all those that come from a POST request, provided that the server has not
1803 set a 'Cache-Control: public' header ;
1804 - those with a 'Pragma: no-cache' header
1805 - those with a 'Cache-control: private' header
1806 - those with a 'Cache-control: no-store' header
1807 - those with a 'Cache-control: max-age=0' header
1808 - those with a 'Cache-control: s-maxage=0' header
1809 - those with a 'Cache-control: no-cache' header
1810 - those with a 'Cache-control: no-cache="set-cookie"' header
1811 - those with a 'Cache-control: no-cache="set-cookie,' header
1812 (allowing other fields after set-cookie)
willy tarreaueedaa9f2005-12-17 14:08:03 +01001813
willy tarreau982249e2005-12-18 00:57:06 +01001814If a response doesn't respect these requirements, then it will be blocked just
1815as if it was from an 'rspdeny' filter, with an "HTTP 502 bad gateway". The
1816session state shows "PH--" meaning that the proxy blocked the response during
1817headers processing. Additionnaly, an alert will be sent in the logs so that
1818admins are told that there's something to be done.
1819
willy tarreauc5f73ed2005-12-18 01:26:38 +01001820
willy tarreau982249e2005-12-18 00:57:06 +010018214.6) Customizing errors
1822-----------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001823Some situations can make haproxy return an HTTP error code to the client :
1824 - invalid or too long request => HTTP 400
1825 - request not completely sent in time => HTTP 408
1826 - forbidden request (matches a deny filter) => HTTP 403
1827 - internal error in haproxy => HTTP 500
1828 - the server returned an invalid or incomplete response => HTTP 502
1829 - no server was available to handle the request => HTTP 503
1830 - the server failed to reply in time => HTTP 504
willy tarreaueedaa9f2005-12-17 14:08:03 +01001831
willy tarreau197e8ec2005-12-17 14:10:59 +01001832A succint error message taken from the RFC accompanies these return codes.
1833But depending on the clients knowledge, it may be better to return custom, user
1834friendly, error pages. This is made possible through the use of the 'errorloc'
1835command :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001836
willy tarreau197e8ec2005-12-17 14:10:59 +01001837 errorloc <HTTP_code> <location>
willy tarreaueedaa9f2005-12-17 14:08:03 +01001838
willy tarreau197e8ec2005-12-17 14:10:59 +01001839Instead of generating an HTTP error <HTTP_code> among those above, the proxy
1840will return a temporary redirection code (HTTP 302) towards the address
1841specified in <location>. This address may be either relative to the site or
1842absolute. Since this request will be handled by the client's browser, it's
1843mandatory that the returned address be reachable from the outside.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001844
willy tarreau197e8ec2005-12-17 14:10:59 +01001845Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001846---------
1847 listen application 0.0.0.0:80
1848 errorloc 400 /badrequest.html
1849 errorloc 403 /forbidden.html
1850 errorloc 408 /toolong.html
willy tarreauc5f73ed2005-12-18 01:26:38 +01001851 errorloc 500 http://haproxy.domain.net/bugreport.html
willy tarreaueedaa9f2005-12-17 14:08:03 +01001852 errorloc 502 http://192.168.114.58/error50x.html
1853 errorloc 503 http://192.168.114.58/error50x.html
1854 errorloc 504 http://192.168.114.58/error50x.html
1855
willy tarreauc1f47532005-12-18 01:08:26 +01001856Note: RFC2616 says that a client must reuse the same method to fetch the
1857Location returned by a 302, which causes problems with the POST method.
1858The return code 303 was designed explicitly to force the client to fetch the
1859Location URL with the GET method, but there are some browsers pre-dating
1860HTTP/1.1 which don't support it. Anyway, most browsers still behave with 302 as
willy tarreauc5f73ed2005-12-18 01:26:38 +01001861if it was a 303. In order to allow the user to chose, versions 1.1.31 and 1.2.5
1862bring two new keywords to replace 'errorloc' : 'errorloc302' and 'errorloc303'.
willy tarreauc1f47532005-12-18 01:08:26 +01001863
1864They are preffered over errorloc (which still does 302). Consider using
1865errorloc303 everytime you know that your clients support HTTP 303 responses..
1866
1867
willy tarreau982249e2005-12-18 00:57:06 +010018684.7) Modifying default values
willy tarreau197e8ec2005-12-17 14:10:59 +01001869-----------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001870Version 1.1.22 introduced the notion of default values, which eliminates the
1871pain of often repeating common parameters between many instances, such as
1872logs, timeouts, modes, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01001873
willy tarreau197e8ec2005-12-17 14:10:59 +01001874Default values are set in a 'defaults' section. Each of these section clears
1875all previously set default parameters, so there may be as many default
1876parameters as needed. Only the last one before a 'listen' section will be
1877used for this section. The 'defaults' section uses the same syntax as the
1878'listen' section, for the supported parameters. The 'defaults' keyword ignores
1879everything on its command line, so that fake instance names can be specified
1880there for better clarity.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001881
willy tarreau982249e2005-12-18 00:57:06 +01001882In version 1.1.28/1.2.1, only those parameters can be preset in the 'default'
willy tarreau197e8ec2005-12-17 14:10:59 +01001883section :
1884 - log (the first and second one)
willy tarreaueedaa9f2005-12-17 14:08:03 +01001885 - mode { tcp, http, health }
1886 - balance { roundrobin }
willy tarreau197e8ec2005-12-17 14:10:59 +01001887 - disabled (to disable every further instances)
1888 - enabled (to enable every further instances, this is the default)
willy tarreaueedaa9f2005-12-17 14:08:03 +01001889 - contimeout, clitimeout, srvtimeout, grace, retries, maxconn
willy tarreau982249e2005-12-18 00:57:06 +01001890 - option { redispatch, transparent, keepalive, forwardfor, logasap, httpclose,
1891 checkcache, httplog, tcplog, dontlognull, persist, httpchk }
willy tarreaueedaa9f2005-12-17 14:08:03 +01001892 - redispatch, redisp, transparent, source { addr:port }
1893 - cookie, capture
1894 - errorloc
1895
willy tarreau197e8ec2005-12-17 14:10:59 +01001896As of 1.1.24, it is not possible to put certain parameters in a 'defaults'
1897section, mainly regular expressions and server configurations :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001898 - dispatch, server,
willy tarreau197e8ec2005-12-17 14:10:59 +01001899 - req*, rsp*
willy tarreaueedaa9f2005-12-17 14:08:03 +01001900
willy tarreau197e8ec2005-12-17 14:10:59 +01001901Last, there's no way yet to change a boolean option from its assigned default
1902value. So if an 'option' statement is set in a 'defaults' section, the only
1903way to flush it is to redefine a new 'defaults' section without this 'option'.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001904
willy tarreau197e8ec2005-12-17 14:10:59 +01001905Examples :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001906----------
1907 defaults applications TCP
willy tarreauc5f73ed2005-12-18 01:26:38 +01001908 log global
1909 mode tcp
1910 balance roundrobin
1911 clitimeout 180000
1912 srvtimeout 180000
1913 contimeout 4000
1914 retries 3
1915 redispatch
willy tarreaueedaa9f2005-12-17 14:08:03 +01001916
1917 listen app_tcp1 10.0.0.1:6000-6063
willy tarreauc5f73ed2005-12-18 01:26:38 +01001918 server srv1 192.168.1.1 check port 6000 inter 10000
1919 server srv2 192.168.1.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01001920
1921 listen app_tcp2 10.0.0.2:6000-6063
willy tarreauc5f73ed2005-12-18 01:26:38 +01001922 server srv1 192.168.2.1 check port 6000 inter 10000
1923 server srv2 192.168.2.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01001924
1925 defaults applications HTTP
willy tarreauc5f73ed2005-12-18 01:26:38 +01001926 log global
1927 mode http
1928 option httplog
1929 option forwardfor
1930 option dontlognull
1931 balance roundrobin
1932 clitimeout 20000
1933 srvtimeout 20000
1934 contimeout 4000
1935 retries 3
willy tarreaueedaa9f2005-12-17 14:08:03 +01001936
1937 listen app_http1 10.0.0.1:80-81
willy tarreauc5f73ed2005-12-18 01:26:38 +01001938 cookie SERVERID postonly insert indirect
1939 capture cookie userid= len 10
1940 server srv1 192.168.1.1:+8000 cookie srv1 check port 8080 inter 1000
1941 server srv1 192.168.1.2:+8000 cookie srv2 check port 8080 inter 1000
willy tarreaueedaa9f2005-12-17 14:08:03 +01001942
1943 defaults
willy tarreauc5f73ed2005-12-18 01:26:38 +01001944 # this empty section voids all default parameters
willy tarreaueedaa9f2005-12-17 14:08:03 +01001945
willy tarreau197e8ec2005-12-17 14:10:59 +01001946=========================
1947| System-specific setup |
1948=========================
willy tarreaueedaa9f2005-12-17 14:08:03 +01001949
willy tarreau197e8ec2005-12-17 14:10:59 +01001950Linux 2.4
1951=========
willy tarreaueedaa9f2005-12-17 14:08:03 +01001952
1953-- cut here --
1954#!/bin/sh
1955# set this to about 256/4M (16384 for 256M machine)
1956MAXFILES=16384
1957echo $MAXFILES > /proc/sys/fs/file-max
1958ulimit -n $MAXFILES
1959
1960if [ -e /proc/sys/net/ipv4/ip_conntrack_max ]; then
willy tarreauc5f73ed2005-12-18 01:26:38 +01001961 echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max
willy tarreaueedaa9f2005-12-17 14:08:03 +01001962fi
1963
1964if [ -e /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait ]; then
willy tarreauc5f73ed2005-12-18 01:26:38 +01001965 # 30 seconds for fin, 15 for time wait
1966 echo 3000 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait
1967 echo 1500 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_time_wait
1968 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_invalid_scale
1969 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_out_of_window
willy tarreaueedaa9f2005-12-17 14:08:03 +01001970fi
1971
1972echo 1024 60999 > /proc/sys/net/ipv4/ip_local_port_range
1973echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
1974echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog
1975echo 262144 > /proc/sys/net/ipv4/tcp_max_tw_buckets
1976echo 262144 > /proc/sys/net/ipv4/tcp_max_orphans
1977echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time
1978echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
1979echo 0 > /proc/sys/net/ipv4/tcp_timestamps
1980echo 0 > /proc/sys/net/ipv4/tcp_ecn
willy tarreauc5f73ed2005-12-18 01:26:38 +01001981echo 1 > /proc/sys/net/ipv4/tcp_sack
willy tarreaueedaa9f2005-12-17 14:08:03 +01001982echo 0 > /proc/sys/net/ipv4/tcp_dsack
1983
1984# auto-tuned on 2.4
1985#echo 262143 > /proc/sys/net/core/rmem_max
1986#echo 262143 > /proc/sys/net/core/rmem_default
1987
1988echo 16384 65536 524288 > /proc/sys/net/ipv4/tcp_rmem
1989echo 16384 349520 699040 > /proc/sys/net/ipv4/tcp_wmem
1990
1991-- cut here --
1992
willy tarreau197e8ec2005-12-17 14:10:59 +01001993
1994FreeBSD
1995=======
1996
1997A FreeBSD port of HA-Proxy is now available and maintained, thanks to
1998Clement Laforet <sheepkiller@cultdeadsheep.org>.
1999
2000For more information :
2001http://www.freebsd.org/cgi/url.cgi?ports/net/haproxy/pkg-descr
2002http://www.freebsd.org/cgi/cvsweb.cgi/ports/net/haproxy/
2003http://www.freshports.org/net/haproxy
2004
2005
2006-- end --