blob: 5e932eb0bbc3004a8aa576619c4e5039c9839a49 [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
493sending of the SIG_USR1 signal to the process. All services are then put into
494soft-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
497milliseconds. This allows to tell a load-balancer that the service is failing,
498while still doing the job during the time it needs to detect it.
499
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
502normally (SIG_TERM). The default 'grace' value is '0'.
503
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
5182.5) Connections expiration time
519--------------------------------
520It is possible (and recommended) to configure several time-outs on TCP
521connections. Three independant timers are adjustable with values specified
522in milliseconds. A session will be terminated if either one of these timers
523expire.
524
525 - the time we accept to wait for data from the client, or for the client to
526 accept data : 'clitimeout' :
527
willy tarreauc5f73ed2005-12-18 01:26:38 +0100528 # client time-out set to 2mn30.
529 clitimeout 150000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100530
531 - the time we accept to wait for data from the server, or for the server to
532 accept data : 'srvtimeout' :
533
willy tarreauc5f73ed2005-12-18 01:26:38 +0100534 # server time-out set to 30s.
535 srvtimeout 30000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100536
537 - the time we accept to wait for a connection to establish on a server :
538 'contimeout' :
539
540 # we give up if the connection does not complete within 4 seconds
willy tarreauc5f73ed2005-12-18 01:26:38 +0100541 contimeout 4000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100542
543Notes :
544-------
545 - 'contimeout' and 'srvtimeout' have no sense on 'health' mode servers ;
546 - under high loads, or with a saturated or defective network, it's possible
547 that some packets get lost. Since the first TCP retransmit only happens
548 after 3 seconds, a time-out equal to, or lower than 3 seconds cannot
549 compensate for a packet loss. A 4 seconds time-out seems a reasonable
550 minimum which will considerably reduce connection failures.
551
willy tarreauc5f73ed2005-12-18 01:26:38 +0100552
willy tarreaueedaa9f2005-12-17 14:08:03 +01005532.6) Attempts to reconnect
554--------------------------
555After a connection failure to a server, it is possible to retry, potentially
556on another server. This is useful if health-checks are too rare and you don't
557want the clients to see the failures. The number of attempts to reconnect is
558set by the 'retries' paramter.
559
560Example :
561---------
willy tarreauc5f73ed2005-12-18 01:26:38 +0100562 # we can retry 3 times max after a failure
563 retries 3
willy tarreaueedaa9f2005-12-17 14:08:03 +0100564
565
5662.7) Address of the dispatch server (deprecated)
567------------------------------------------------
568The server which will be sent all new connections is defined by the 'dispatch'
569parameter, in the form <address>:<port>. It generally is dedicated to unknown
570connections and will assign them a cookie, in case of HTTP persistence mode,
571or simply is a single server in case of generic TCP proxy. This old mode is only
572provided for backwards compatibility, but doesn't allow to check remote servers
573state, and has a rather limited usage. All new setups should switch to 'balance'
574mode. The principle of the dispatcher is to be able to perform the load
575balancing itself, but work only on new clients so that the server doesn't need
576to be a big machine.
577
578Example :
579---------
willy tarreauc5f73ed2005-12-18 01:26:38 +0100580 # all new connections go there
581 dispatch 192.168.1.2:80
willy tarreaueedaa9f2005-12-17 14:08:03 +0100582
583Note :
584------
585This parameter has no sense for 'health' servers, and is incompatible with
586'balance' mode.
587
588
5892.8) Outgoing source address
590----------------------------
591It is often necessary to bind to a particular address when connecting to some
592remote hosts. This is done via the 'source' parameter which is a per-proxy
593parameter. A newer version may allow to fix different sources to reach different
594servers. The syntax is 'source <address>[:<port>]', where <address> is a valid
595local address (or '0.0.0.0' or '*' or empty to let the system choose), and
596<port> is an optional parameter allowing the user to force the source port for
597very specific needs. If the port is not specified or is '0', the system will
598choose a free port. Note that as of version 1.1.18, the servers health checks
599are also performed from the same source.
600
601Examples :
602----------
603 listen http_proxy *:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100604 # all connections take 192.168.1.200 as source address
605 source 192.168.1.200:0
willy tarreaueedaa9f2005-12-17 14:08:03 +0100606
607 listen rlogin_proxy *:513
willy tarreauc5f73ed2005-12-18 01:26:38 +0100608 # use address 192.168.1.200 and the reserved port 900 (needs to be root)
609 source 192.168.1.200:900
willy tarreaueedaa9f2005-12-17 14:08:03 +0100610
611
6122.9) Setting the cookie name
613----------------------------
614In HTTP mode, it is possible to look for a particular cookie which will contain
615a server identifier which should handle the connection. The cookie name is set
616via the 'cookie' parameter.
617
618Example :
619---------
620 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100621 mode http
622 cookie SERVERID
willy tarreaueedaa9f2005-12-17 14:08:03 +0100623
624It is possible to change the cookie behaviour to get a smarter persistence,
625depending on applications. It is notably possible to delete or modify a cookie
626emitted by a server, insert a cookie identifying the server in an HTTP response
627and even add a header to tell upstream caches not to cache this response.
628
629Examples :
630----------
631
632To remove the cookie for direct accesses (ie when the server matches the one
633which was specified in the client cookie) :
634
willy tarreauc5f73ed2005-12-18 01:26:38 +0100635 cookie SERVERID indirect
willy tarreaueedaa9f2005-12-17 14:08:03 +0100636
637To replace the cookie value with the one assigned to the server if any (no
638cookie will be created if the server does not provide one, nor if the
639configuration does not provide one). This lets the application put the cookie
640exactly on certain pages (eg: successful authentication) :
641
willy tarreauc5f73ed2005-12-18 01:26:38 +0100642 cookie SERVERID rewrite
willy tarreaueedaa9f2005-12-17 14:08:03 +0100643
644To create a new cookie and assign the server identifier to it (in this case, all
645servers should be associated with a valid cookie, since no cookie will simply
646delete the cookie from the client's browser) :
647
willy tarreauc5f73ed2005-12-18 01:26:38 +0100648 cookie SERVERID insert
willy tarreaueedaa9f2005-12-17 14:08:03 +0100649
willy tarreau0174f312005-12-18 01:02:42 +0100650To reuse an existing application cookie and prefix it with the server's
651identifier, and remove it in the request, use the 'prefix' option. This allows
652to insert a haproxy in front of an application without risking to break clients
653which does not support more than one cookie :
654
willy tarreauc5f73ed2005-12-18 01:26:38 +0100655 cookie JSESSIONID prefix
willy tarreau0174f312005-12-18 01:02:42 +0100656
willy tarreaueedaa9f2005-12-17 14:08:03 +0100657To insert a cookie and ensure that no upstream cache will store it, add the
658'nocache' option :
659
willy tarreauc5f73ed2005-12-18 01:26:38 +0100660 cookie SERVERID insert nocache
willy tarreaueedaa9f2005-12-17 14:08:03 +0100661
662To insert a cookie only after a POST request, add 'postonly' after 'insert'.
663This has the advantage that there's no risk of caching, and that all pages
664seen before the POST one can still be cached :
665
willy tarreauc5f73ed2005-12-18 01:26:38 +0100666 cookie SERVERID insert postonly
willy tarreaueedaa9f2005-12-17 14:08:03 +0100667
668Notes :
669-----------
670- it is possible to combine 'insert' with 'indirect' or 'rewrite' to adapt to
671 applications which already generate the cookie with an invalid content.
672
673- in the case where 'insert' and 'indirect' are both specified, the cookie is
willy tarreau0174f312005-12-18 01:02:42 +0100674 never transmitted to the server, since it wouldn't understand it. This is the
675 most application-transparent mode.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100676
677- it is particularly recommended to use 'nocache' in 'insert' mode if any
678 upstream HTTP/1.0 cache is susceptible to cache the result, because this may
679 lead to many clients going to the same server, or even worse, some clients
680 having their server changed while retrieving a page from the cache.
681
willy tarreau0174f312005-12-18 01:02:42 +0100682- the 'prefix' mode normally does not need 'indirect', 'nocache', nor
683 'postonly', because just as in the 'rewrite' mode, it relies on the
684 application to know when a cookie can be emitted. However, since it has to
685 fix the cookie name in every subsequent requests, you must ensure that the
686 proxy will be used without any "HTTP keep-alive". Use option "httpclose" if
687 unsure.
688
willy tarreaueedaa9f2005-12-17 14:08:03 +0100689- when the application is well known and controlled, the best method is to
690 only add the persistence cookie on a POST form because it's up to the
willy tarreau0174f312005-12-18 01:02:42 +0100691 application to select which page it wants the upstream servers to cache. In
692 this case, you would use 'insert postonly indirect'.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100693
willy tarreauc5f73ed2005-12-18 01:26:38 +0100694
willy tarreaueedaa9f2005-12-17 14:08:03 +01006952.10) Associating a cookie value with a server
696----------------------------------------------
697In HTTP mode, it's possible to associate a cookie value to each server. This
698was initially used in combination with 'dispatch' mode to handle direct accesses
699but it is now the standard way of doing the load balancing. The syntax is :
700
701 server <identifier> <address>:<port> cookie <value>
702
703- <identifier> is any name which can be used to identify the server in the logs.
704- <address>:<port> specifies where the server is bound.
705- <value> is the value to put in or to read from the cookie.
706
707Example : the 'SERVERID' cookie can be either 'server01' or 'server02'
708---------
709 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100710 mode http
711 cookie SERVERID
712 dispatch 192.168.1.100:80
713 server web1 192.168.1.1:80 cookie server01
714 server web2 192.168.1.2:80 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100715
716Warning : the syntax has changed since version 1.0 !
717---------
718
willy tarreauc5f73ed2005-12-18 01:26:38 +0100719
willy tarreau598da412005-12-18 01:07:29 +01007202.11) Application Cookies
721-------------------------
722Since 1.2.4 it is possible to catch the cookie that comes from an
723application server in order to apply "application session stickyness".
724The server's response is searched for 'appsession' cookie, the first
725'len' bytes are used for matching and it is stored for a period of
726'timeout'.
727The syntax is:
728
729 appsession <SESSIONCOOKIE> len <MATCHLENGTH> timeout <HOLDTIME>
730
731- <SESSIONCOOKIE> is the cookie, the server uses for it's session-handling
732- <MATCHLENGTH> how many bytes/characters should be used for matching equal
733 sessions
734- <HOLDTIME> after this inactivaty time, in ms, the cookie will be deleted
735 from the sessionstore
736
737The appsession is only per 'listen' section possible.
738
739Example :
740---------
741 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100742 mode http
willy tarreau598da412005-12-18 01:07:29 +0100743 appsession JSESSIONID len 52 timeout 300000
744 .
745 .
746
willy tarreauc5f73ed2005-12-18 01:26:38 +0100747
willy tarreaueedaa9f2005-12-17 14:08:03 +01007483) Autonomous load balancer
749===========================
750
751The proxy can perform the load-balancing itself, both in TCP and in HTTP modes.
752This is the most interesting mode which obsoletes the old 'dispatch' mode
753described above. It has advantages such as server health monitoring, multiple
754port binding and port mapping. To use this mode, the 'balance' keyword is used,
755followed by the selected algorithm. As of version 1.1.23, only 'roundrobin' is
756available, which is also the default value if unspecified. In this mode, there
757will be no dispatch address, but the proxy needs at least one server.
758
759Example : same as the last one, with internal load balancer
760---------
761
762 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100763 mode http
764 cookie SERVERID
765 balance roundrobin
766 server web1 192.168.1.1:80 cookie server01
767 server web2 192.168.1.2:80 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100768
769
770Since version 1.1.22, it is possible to automatically determine on which port
771the server will get the connection, depending on the port the client connected
772to. Indeed, there now are 4 possible combinations for the server's <port> field:
773
774 - unspecified or '0' :
775 the connection will be sent to the same port as the one on which the proxy
776 received the client connection itself.
777
778 - numerical value (the only one supported in versions earlier than 1.1.22) :
779 the connection will always be sent to the specified port.
780
781 - '+' followed by a numerical value :
782 the connection will be sent to the same port as the one on which the proxy
783 received the connection, plus this value.
784
785 - '-' followed by a numerical value :
786 the connection will be sent to the same port as the one on which the proxy
787 received the connection, minus this value.
788
789Examples :
790----------
791
792# same as previous example
793
794 listen http_proxy :80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100795 mode http
796 cookie SERVERID
797 balance roundrobin
798 server web1 192.168.1.1 cookie server01
799 server web2 192.168.1.2 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100800
801# simultaneous relaying of ports 80, 81 and 8080-8089
802
803 listen http_proxy :80,:81,:8080-8089
willy tarreauc5f73ed2005-12-18 01:26:38 +0100804 mode http
805 cookie SERVERID
806 balance roundrobin
807 server web1 192.168.1.1 cookie server01
808 server web2 192.168.1.2 cookie server02
willy tarreaueedaa9f2005-12-17 14:08:03 +0100809
810# relaying of TCP ports 25, 389 and 663 to ports 1025, 1389 and 1663
811
812 listen http_proxy :25,:389,:663
willy tarreauc5f73ed2005-12-18 01:26:38 +0100813 mode tcp
814 balance roundrobin
815 server srv1 192.168.1.1:+1000
816 server srv2 192.168.1.2:+1000
willy tarreaueedaa9f2005-12-17 14:08:03 +0100817
818
willy tarreau197e8ec2005-12-17 14:10:59 +01008193.1) Server monitoring
820----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +0100821It is possible to check the servers status by trying to establish TCP
822connections or even sending HTTP requests to them. A server which fails to
823reply to health checks as expected will not be used by the load balancing
824algorithms. To enable monitoring, add the 'check' keyword on a server line.
825It is possible to specify the interval between tests (in milliseconds) with
826the 'inter' parameter, the number of failures supported before declaring that
827the server has fallen down with the 'fall' parameter, and the number of valid
828checks needed for the server to fully get up with the 'rise' parameter. Since
829version 1.1.22, it is also possible to send checks to a different port
830(mandatory when none is specified) with the 'port' parameter. The default
831values are the following ones :
832
833 - inter : 2000
834 - rise : 2
835 - fall : 3
836 - port : default server port
837
838The default mode consists in establishing TCP connections only. But in certain
839types of application failures, it is often that the server continues to accept
840connections because the system does it itself while the application is running
841an endless loop, or is completely stuck. So in version 1.1.16 were introduced
842HTTP health checks which only performed simple lightweight requests and analysed
843the response. Now, as of version 1.1.23, it is possible to change the HTTP
844method, the URI, and the HTTP version string (which even allows to send headers
845with a dirty trick). To enable HTTP health-checks, use 'option httpchk'.
846
847By default, requests use the 'OPTIONS' method because it's very light and easy
848to filter from logs, and does it on '/'. Only HTTP responses 2xx and 3xx are
849considered valid ones, and only if they come before the time to send a new
850request is reached ('inter' parameter). If some servers block this type of
851request, 3 other forms help to forge a request :
852
853 - option httpchk -> OPTIONS / HTTP/1.0
854 - option httpchk URI -> OPTIONS <URI> HTTP/1.0
855 - option httpchk METH URI -> <METH> <URI> HTTP/1.0
856 - option httpchk METH URI VER -> <METH> <URI> <VER>
857
858See examples below.
859
860Since version 1.1.17, it is possible to specify backup servers. These servers
861are only sollicited when no other server is available. This may only be useful
862to serve a maintenance page, or define one active and one backup server (seldom
863used in TCP mode). To make a server a backup one, simply add the 'backup' option
864on its line. These servers also support cookies, so if a cookie is specified for
865a backup server, clients assigned to this server will stick to it even when the
866other ones come back. Conversely, if no cookie is assigned to such a server,
867the clients will get their cookies removed (empty cookie = removal), and will
868be balanced against other servers once they come back. Please note that there
869is no load-balancing among backup servers. If there are several backup servers,
870the second one will only be used when the first one dies, and so on.
871
872Since version 1.1.17, it is also possible to visually check the status of all
873servers at once. For this, you just have to send a SIGHUP signal to the proxy.
874The servers status will be dumped into the logs at the 'notice' level, as well
875as on <stderr> if not closed. For this reason, it's always a good idea to have
876one local log server at the 'notice' level.
877
willy tarreau982249e2005-12-18 00:57:06 +0100878Since version 1.1.28 and 1.2.1, if an instance loses all its servers, an
willy tarreau0174f312005-12-18 01:02:42 +0100879emergency message will be sent in the logs to inform the administator that an
willy tarreau982249e2005-12-18 00:57:06 +0100880immediate action must be taken.
881
willy tarreau0174f312005-12-18 01:02:42 +0100882Since version 1.1.30 and 1.2.3, several servers can share the same cookie
883value. This is particularly useful in backup mode, to select alternate paths
884for a given server for example, to provide soft-stop, or to direct the clients
885to a temporary page during an application restart. The principle is that when
886a server is dead, the proxy will first look for another server which shares the
887same cookie value for every client which presents the cookie. If there is no
888standard server for this cookie, it will then look for a backup server which
889shares the same name. Please consult the architecture guide for more information.
willy tarreau982249e2005-12-18 00:57:06 +0100890
willy tarreaueedaa9f2005-12-17 14:08:03 +0100891Examples :
892----------
893# same setup as in paragraph 3) with TCP monitoring
894 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100895 mode http
896 cookie SERVERID
897 balance roundrobin
898 server web1 192.168.1.1:80 cookie server01 check
899 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100900
901# same with HTTP monitoring via 'OPTIONS / HTTP/1.0'
902 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100903 mode http
904 cookie SERVERID
905 balance roundrobin
906 option httpchk
907 server web1 192.168.1.1:80 cookie server01 check
908 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100909
910# same with HTTP monitoring via 'OPTIONS /index.html HTTP/1.0'
911 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100912 mode http
913 cookie SERVERID
914 balance roundrobin
915 option httpchk /index.html
916 server web1 192.168.1.1:80 cookie server01 check
917 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100918
919# same with HTTP monitoring via 'HEAD /index.jsp? HTTP/1.1\r\nHost: www'
920 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100921 mode http
922 cookie SERVERID
923 balance roundrobin
924 option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www
925 server web1 192.168.1.1:80 cookie server01 check
926 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
willy tarreaueedaa9f2005-12-17 14:08:03 +0100927
willy tarreau0174f312005-12-18 01:02:42 +0100928# Load-balancing with 'prefixed cookie' persistence, and soft-stop using an
929# alternate port 81 on the server for health-checks.
930 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100931 mode http
932 cookie JSESSIONID prefix
933 balance roundrobin
934 option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www
935 server web1-norm 192.168.1.1:80 cookie s1 check port 81
936 server web2-norm 192.168.1.2:80 cookie s2 check port 81
937 server web1-stop 192.168.1.1:80 cookie s1 check port 80 backup
938 server web2-stop 192.168.1.2:80 cookie s2 check port 80 backup
willy tarreau0174f312005-12-18 01:02:42 +0100939
willy tarreaueedaa9f2005-12-17 14:08:03 +0100940# automatic insertion of a cookie in the server's response, and automatic
941# deletion of the cookie in the client request, while asking upstream caches
942# not to cache replies.
943 listen web_appl 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100944 mode http
945 cookie SERVERID insert nocache indirect
946 balance roundrobin
947 server web1 192.168.1.1:80 cookie server01 check
948 server web2 192.168.1.2:80 cookie server02 check
willy tarreaueedaa9f2005-12-17 14:08:03 +0100949
950# same with off-site application backup and local error pages server
951 listen web_appl 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100952 mode http
953 cookie SERVERID insert nocache indirect
954 balance roundrobin
955 server web1 192.168.1.1:80 cookie server01 check
956 server web2 192.168.1.2:80 cookie server02 check
957 server web-backup 192.168.2.1:80 cookie server03 check backup
958 server web-excuse 192.168.3.1:80 check backup
willy tarreaueedaa9f2005-12-17 14:08:03 +0100959
willy tarreauc5f73ed2005-12-18 01:26:38 +0100960# SMTP+TLS relaying with health-checks and backup servers
willy tarreaueedaa9f2005-12-17 14:08:03 +0100961
962 listen http_proxy :25,:587
willy tarreauc5f73ed2005-12-18 01:26:38 +0100963 mode tcp
964 balance roundrobin
965 server srv1 192.168.1.1 check port 25 inter 30000 rise 1 fall 2
966 server srv2 192.168.1.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +0100967
968
9693.2) Redistribute connections in case of failure
970------------------------------------------------
971In HTTP mode, if a server designated by a cookie does not respond, the clients
972may definitely stick to it because they cannot flush the cookie, so they will
973not be able to access the service anymore. Specifying 'redispatch' will allow
974the proxy to break their persistence and redistribute them to working servers.
975
976Example :
977---------
978 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100979 mode http
980 cookie SERVERID
981 dispatch 192.168.1.100:80
982 server web1 192.168.1.1:80 cookie server01
983 server web2 192.168.1.2:80 cookie server02
984 redispatch # send back to dispatch in case of connection failure
willy tarreaueedaa9f2005-12-17 14:08:03 +0100985
986Up to, and including version 1.1.16, this parameter only applied to connection
987failures. Since version 1.1.17, it also applies to servers which have been
988detected as failed by the health check mechanism. Indeed, a server may be broken
989but still accepting connections, which would not solve every case. But it is
990possible to conserve the old behaviour, that is, make a client insist on trying
991to connect to a server even if it is said to be down, by setting the 'persist'
992option :
993
994 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +0100995 mode http
996 option persist
997 cookie SERVERID
998 dispatch 192.168.1.100:80
999 server web1 192.168.1.1:80 cookie server01
1000 server web2 192.168.1.2:80 cookie server02
1001 redispatch # send back to dispatch in case of connection failure
willy tarreaueedaa9f2005-12-17 14:08:03 +01001002
1003
10044) Additionnal features
1005=======================
1006
1007Other features are available. They are transparent mode, event logging and
1008header rewriting/filtering.
1009
willy tarreauc5f73ed2005-12-18 01:26:38 +01001010
willy tarreau0174f312005-12-18 01:02:42 +010010114.1) Network features
willy tarreaueedaa9f2005-12-17 14:08:03 +01001012---------------------
willy tarreau0174f312005-12-18 01:02:42 +010010134.1.1) Transparent mode
1014-----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +01001015In HTTP mode, the 'transparent' keyword allows to intercept sessions which are
1016routed through the system hosting the proxy. This mode was implemented as a
1017replacement for the 'dispatch' mode, since connections without cookie will be
1018sent to the original address while known cookies will be sent to the servers.
1019This mode implies that the system can redirect sessions to a local port.
1020
1021Example :
1022---------
1023 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001024 mode http
1025 transparent
1026 cookie SERVERID
1027 server server01 192.168.1.1:80
1028 server server02 192.168.1.2:80
willy tarreaueedaa9f2005-12-17 14:08:03 +01001029
1030 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
1031 --dport 80 -j REDIRECT --to-ports 65000
1032
1033Note :
1034------
1035If the port is left unspecified on the server, the port the client connected to
1036will be used. This allows to relay a full port range without using transparent
1037mode nor thousands of file descriptors, provided that the system can redirect
1038sessions to local ports.
1039
1040Example :
1041---------
1042 # redirect all ports to local port 65000, then forward to the server on the
1043 # original port.
1044 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001045 mode tcp
1046 server server01 192.168.1.1 check port 60000
1047 server server02 192.168.1.2 check port 60000
willy tarreaueedaa9f2005-12-17 14:08:03 +01001048
1049 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
1050 -j REDIRECT --to-ports 65000
1051
willy tarreau0174f312005-12-18 01:02:42 +010010524.1.2) Per-server source address binding
1053----------------------------------------
1054As of versions 1.1.30 and 1.2.3, it is possible to specify a particular source
1055to reach each server. This is useful when reaching backup servers from a
1056different LAN, or to use an alternate path to reach the same server. It is also
1057usable to provide source load-balancing for outgoing connections. Obviously,
1058the same source address is used to send health-checks.
1059
1060Example :
1061---------
1062 # use a particular source to reach both servers
1063 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001064 mode http
1065 balance roundrobin
1066 server server01 192.168.1.1:80 source 192.168.2.13
1067 server server02 192.168.1.2:80 source 192.168.2.13
willy tarreau0174f312005-12-18 01:02:42 +01001068
1069Example :
1070---------
1071 # use a particular source to reach each servers
1072 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001073 mode http
1074 balance roundrobin
1075 server server01 192.168.1.1:80 source 192.168.1.1
1076 server server02 192.168.2.1:80 source 192.168.2.1
willy tarreau0174f312005-12-18 01:02:42 +01001077
1078Example :
1079---------
1080 # provide source load-balancing to reach the same proxy through 2 WAN links
1081 listen http_proxy 0.0.0.0:65000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001082 mode http
1083 balance roundrobin
1084 server remote-proxy-way1 192.168.1.1:3128 source 192.168.2.1
1085 server remote-proxy-way2 192.168.1.1:3128 source 192.168.3.1
willy tarreau0174f312005-12-18 01:02:42 +01001086
1087Example :
1088---------
1089 # force a TCP connection to bind to a specific port
1090 listen http_proxy 0.0.0.0:2000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001091 mode tcp
1092 balance roundrobin
1093 server srv1 192.168.1.1:80 source 192.168.2.1:20
1094 server srv2 192.168.1.2:80 source 192.168.2.1:20
willy tarreau0174f312005-12-18 01:02:42 +01001095
willy tarreaub952e1d2005-12-18 01:31:20 +010010964.1.3) TCP keep-alive
1097---------------------
1098With version 1.2.7, it becomes possible to enable TCP keep-alives on both the
1099client and server sides. This makes it possible to prevent long sessions from
1100expiring on external layer 4 components such as firewalls and load-balancers.
1101It also allows the system to terminate dead sessions when no timeout has been
1102set (not recommanded). The proxy cannot set the keep-alive probes intervals nor
1103maximal count, consult your operating system manual for this. There are 3
1104options to enable TCP keep-alive :
1105
1106 option tcpka # enables keep-alive both on client and server side
1107 option clitcpka # enables keep-alive only on client side
1108 option srvtcpka # enables keep-alive only on server side
1109
willy tarreaueedaa9f2005-12-17 14:08:03 +01001110
11114.2) Event logging
1112------------------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001113
1114HAProxy's strength certainly lies in its precise logs. It probably provides the
1115finest level of information available for such a product, which is very
1116important for troubleshooting complex environments. Standard log information
1117include client ports, TCP/HTTP state timers, precise session state at
1118termination and precise termination cause, information about decisions to
1119direct trafic to a server, and of course the ability to capture arbitrary
1120headers.
1121
1122In order to improve administrators reactivity, it offers a great transparency
1123about encountered problems, both internal and external, and it is possible to
1124send logs to different sources at the same time with different level filters :
1125
1126 - global process-level logs (system errors, start/stop, etc..)
1127 - per-listener system and internal errors (lack of resource, bugs, ...)
1128 - per-listener external troubles (servers up/down, max connections)
1129 - per-listener activity (client connections), either at the establishment or
1130 at the termination.
1131
1132The ability to distribute different levels of logs to different log servers
1133allow several production teams to interact and to fix their problems as soon
1134as possible. For example, the system team might monitor system-wide errors,
1135while the application team might be monitoring the up/down for their servers in
1136real time, and the security team might analyze the activity logs with one hour
1137delay.
1138
willy tarreauc1cae632005-12-17 14:12:23 +010011394.2.1) Log levels
1140-----------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001141TCP and HTTP connections can be logged with informations such as date, time,
1142source IP address, destination address, connection duration, response times,
1143HTTP request, the HTTP return code, number of bytes transmitted, the conditions
1144in which the session ended, and even exchanged cookies values, to track a
1145particular user's problems for example. All messages are sent to up to two
1146syslog servers. Consult section 1.1 for more info about log facilities. The
1147syntax follows :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001148
willy tarreau197e8ec2005-12-17 14:10:59 +01001149 log <address_1> <facility_1> [max_level_1]
1150 log <address_2> <facility_2> [max_level_2]
1151or
willy tarreaueedaa9f2005-12-17 14:08:03 +01001152 log global
1153
willy tarreau197e8ec2005-12-17 14:10:59 +01001154Note :
1155------
1156The particular syntax 'log global' means that the same log configuration as the
1157'global' section will be used.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001158
willy tarreau197e8ec2005-12-17 14:10:59 +01001159Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001160---------
1161 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001162 mode http
1163 log 192.168.2.200 local3
1164 log 192.168.2.201 local4
willy tarreaueedaa9f2005-12-17 14:08:03 +01001165
willy tarreauc1cae632005-12-17 14:12:23 +010011664.2.2) Log format
1167-----------------
1168By default, connections are logged at the TCP level, as soon as the session
1169establishes between the client and the proxy. By enabling the 'tcplog' option,
1170the proxy will wait until the session ends to generate an enhanced log
1171containing more information such as session duration and its state during the
1172disconnection.
1173
willy tarreauc5f73ed2005-12-18 01:26:38 +01001174Example of TCP logging :
1175------------------------
willy tarreau982249e2005-12-18 00:57:06 +01001176 listen relais-tcp 0.0.0.0:8000
willy tarreauc5f73ed2005-12-18 01:26:38 +01001177 mode tcp
1178 option tcplog
1179 log 192.168.2.200 local3
willy tarreau982249e2005-12-18 00:57:06 +01001180
willy tarreauc5f73ed2005-12-18 01:26:38 +01001181>>> haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28] relais-tcp Srv1 0/5007 0 -- 1/1
1182
1183 Field Format Example
1184
1185 1 process_name '[' pid ']:' haproxy[18989]:
1186 2 client_ip ':' client_port 127.0.0.1:34550
1187 3 '[' date ']' [15/Oct/2003:15:24:28]
1188 4 listener_name relais-tcp
1189 5 server_name Srv1
1190 6 connect_time '/' total_time 0/5007
1191 7 bytes_read 0
1192 8 termination_state --
1193 9 listener_conns '/' process_conns 1/1
1194
willy tarreau982249e2005-12-18 00:57:06 +01001195
willy tarreauc1cae632005-12-17 14:12:23 +01001196Another option, 'httplog', provides more detailed information about HTTP
1197contents, such as the request and some cookies. In the event where an external
1198component would establish frequent connections to check the service, logs may be
1199full of useless lines. So it is possible not to log any session which didn't
1200transfer any data, by the setting of the 'dontlognull' option. This only has
1201effect on sessions which are established then closed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001202
willy tarreauc5f73ed2005-12-18 01:26:38 +01001203Example of HTTP logging :
1204-------------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +01001205 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001206 mode http
1207 option httplog
1208 option dontlognull
1209 log 192.168.2.200 local3
1210
1211>>> 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 +01001212
willy tarreauc5f73ed2005-12-18 01:26:38 +01001213More complete example
1214 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"
1215
1216 Field Format Example
1217
1218 1 process_name '[' pid ']:' haproxy[18989]:
1219 2 client_ip ':' client_port 10.0.0.1:34552
1220 3 '[' date ']' [15/Oct/2003:15:26:31]
1221 4 listener_name relais-http
1222 5 server_name Srv1
1223 6 Tq '/' Tc '/' Tr '/' Tt 3183/-1/-1/11215
1224 7 HTTP_return_code 503
1225 8 bytes_read 0
1226 9 captured_request_cookie -
1227 10 captured_response_cookie -
1228 11 termination_state SC--
1229 12 listener_conns '/' process_conns 202/205
1230 13 '{' captured_request_headers '}' {w.ods.org|Mozilla}
1231 14 '{' captured_response_headers '}' {}
1232 15 '"' HTTP_request '"' "HEAD / HTTP/1.0"
1233
1234Note for log parsers: the URI is ALWAYS the end of the line starting with the
1235 first double quote '"'.
willy tarreau982249e2005-12-18 00:57:06 +01001236
1237The problem when logging at end of connection is that you have no clue about
1238what is happening during very long sessions. To workaround this problem, a
1239new option 'logasap' has been introduced in 1.1.28/1.2.1. When specified, the
1240proxy will log as soon as possible, just before data transfer begins. This means
1241that in case of TCP, it will still log the connection status to the server, and
1242in case of HTTP, it will log just after processing the server headers. In this
1243case, the number of bytes reported is the number of header bytes sent to the
1244client.
1245
1246In order to avoid confusion with normal logs, the total time field and the
1247number of bytes are prefixed with a '+' sign which mean that real numbers are
1248certainly bigger.
1249
1250Example :
1251---------
1252
1253 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001254 mode http
1255 option httplog
1256 option dontlognull
1257 option logasap
1258 log 192.168.2.200 local3
willy tarreau982249e2005-12-18 00:57:06 +01001259
willy tarreauc5f73ed2005-12-18 01:26:38 +01001260>>> 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 +01001261
willy tarreauc1cae632005-12-17 14:12:23 +010012624.2.3) Timing events
1263--------------------
1264Timers provide a great help in trouble shooting network problems. All values
1265are reported in milliseconds (ms). In HTTP mode, four control points are
1266reported under the form 'Tq/Tc/Tr/Tt' :
1267
1268 - Tq: total time to get the client request.
1269 It's the time elapsed between the moment the client connection was accepted
1270 and the moment the proxy received the last HTTP header. The value '-1'
1271 indicates that the end of headers (empty line) has never been seen.
1272
1273 - Tc: total time to establish the TCP connection to the server.
1274 It's the time elapsed between the moment the proxy sent the connection
1275 request, and the moment it was acknowledged, or between the TCP SYN packet
1276 and the matching SYN/ACK in return. The value '-1' means that the
1277 connection never established.
1278
1279 - Tr: server response time. It's the time elapsed between the moment the
1280 TCP connection was established to the server and the moment it send its
1281 complete response header. It purely shows its request processing time,
1282 without the network overhead due to the data transmission. The value '-1'
1283 means that the last the response header (empty line) was never seen.
1284
1285 - Tt: total session duration time, between the moment the proxy accepted it
willy tarreau982249e2005-12-18 00:57:06 +01001286 and the moment both ends were closed. The exception is when the 'logasap'
1287 option is specified. In this case, it only equals (Tq+Tc+Tr), and is
1288 prefixed with a '+' sign. From this field, we can deduce Td, the data
1289 transmission time, by substracting other timers when valid :
willy tarreauc1cae632005-12-17 14:12:23 +01001290
1291 Td = Tt - (Tq + Tc + Tr)
1292
1293 Timers with '-1' values have to be excluded from this equation.
1294
1295In TCP mode ('option tcplog'), only Tc and Tt are reported.
1296
1297These timers provide precious indications on trouble causes. Since the TCP
1298protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure
1299that timers close to multiples of 3s are nearly always related to packets lost
1300due to network problems (wires or negociation). Moreover, if <Tt> is close to
1301a timeout value specified in the configuration, it often means that a session
1302has been aborted on time-out.
1303
1304Most common cases :
1305
1306 - If Tq is close to 3000, a packet has probably been lost between the client
1307 and the proxy.
1308 - If Tc is close to 3000, a packet has probably been lost between the server
1309 and the proxy during the server connection phase. This one should always be
1310 very low (less than a few tens).
1311 - If Tr is nearly always lower than 3000 except some rare values which seem to
1312 be the average majored by 3000, there are probably some packets lost between
1313 the proxy and the server.
1314 - If Tt is often slightly higher than a time-out, it's often because the
1315 client and the server use HTTP keep-alive and the session is maintained
1316 after the response ends. Se further for how to disable HTTP keep-alive.
1317
1318Other cases ('xx' means any value to be ignored) :
1319 -1/xx/xx/Tt : the client was not able to send its complete request in time,
willy tarreauc5f73ed2005-12-18 01:26:38 +01001320 or that it aborted it too early.
willy tarreauc1cae632005-12-17 14:12:23 +01001321 Tq/-1/xx/Tt : the connection could not establish on the server. Either it
willy tarreauc5f73ed2005-12-18 01:26:38 +01001322 refused it or it timed out after Tt-Tq ms.
willy tarreauc1cae632005-12-17 14:12:23 +01001323 Tq/Tc/-1/Tt : the server has accepted the connection but did not return a
willy tarreauc5f73ed2005-12-18 01:26:38 +01001324 complete response in time, or it closed its connexion
1325 unexpectedly, after Tt-(Tq+Tc) ms.
willy tarreauc1cae632005-12-17 14:12:23 +01001326
13274.2.4) Session state at disconnection
1328-------------------------------------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001329TCP and HTTP logs provide a session completion indicator in the
1330<termination_state> field, just before the number of active
1331connections. It is 2-characters long in TCP, and 4-characters long in
1332HTTP, each of which has a special meaning :
1333
willy tarreau197e8ec2005-12-17 14:10:59 +01001334 - On the first character, a code reporting the first event which caused the
1335 session to terminate :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001336
willy tarreauc5f73ed2005-12-18 01:26:38 +01001337 C : the TCP session was unexpectedly aborted by the client.
1338
1339 S : the TCP session was unexpectedly aborted by the server, or the
1340 server explicitly refused it.
1341
1342 P : the session was prematurely aborted by the proxy, because of a
1343 connection limit enforcement, because a DENY filter was matched,
1344 or because of a security check which detected and blocked a
1345 dangerous error in server response which might have caused
1346 information leak (eg: cacheable cookie).
1347
1348 R : a resource on the proxy has been exhausted (memory, sockets, source
1349 ports, ...). Usually, this appears during the connection phase, and
1350 system logs should contain a copy of the precise error.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001351
willy tarreauc5f73ed2005-12-18 01:26:38 +01001352 I : an internal error was identified by the proxy during a self-check.
1353 This should NEVER happen, and you are encouraged to report any log
1354 containing this, because this is a bug.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001355
willy tarreauc5f73ed2005-12-18 01:26:38 +01001356 c : the client-side time-out expired first.
1357
1358 s : the server-side time-out expired first.
1359
1360 - : normal session completion.
1361
1362 - on the second character, the TCP/HTTP session state when it was closed :
1363
1364 R : waiting for complete REQUEST from the client (HTTP only). Nothing
1365 was sent to any server.
1366
1367 C : waiting for CONNECTION to establish on the server. The server might
1368 at most have noticed a connection attempt.
1369
1370 H : waiting for, receiving and processing server HEADERS (HTTP only).
1371
1372 D : the session was in the DATA phase.
1373
1374 L : the proxy was still transmitting LAST data to the client while the
1375 server had already finished.
1376
1377 - : normal session completion after end of data transfer.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001378
willy tarreau197e8ec2005-12-17 14:10:59 +01001379 - the third character tells whether the persistence cookie was provided by
willy tarreauc1cae632005-12-17 14:12:23 +01001380 the client (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001381
willy tarreauc5f73ed2005-12-18 01:26:38 +01001382 N : the client provided NO cookie. This is usually the case on new
1383 connections.
1384
1385 I : the client provided an INVALID cookie matching no known
1386 server. This might be caused by a recent configuration change,
1387 mixed cookies between HTTP/HTTPS sites, or an attack.
1388
1389 D : the client provided a cookie designating a server which was DOWN,
1390 so either the 'persist' option was used and the client was sent to
1391 this server, or it was not set and the client was redispatched to
1392 another server.
1393
1394 V : the client provided a valid cookie, and was sent to the associated
1395 server.
1396
1397 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001398
willy tarreau197e8ec2005-12-17 14:10:59 +01001399 - the last character reports what operations were performed on the persistence
willy tarreauc1cae632005-12-17 14:12:23 +01001400 cookie returned by the server (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001401
willy tarreauc5f73ed2005-12-18 01:26:38 +01001402 N : NO cookie was provided by the server, and none was inserted either.
1403
1404 I : no cookie was provided by the server, and the proxy INSERTED one.
1405
willy tarreau197e8ec2005-12-17 14:10:59 +01001406 P : a cookie was PROVIDED by the server and transmitted as-is.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001407
willy tarreauc5f73ed2005-12-18 01:26:38 +01001408 R : the cookie provided by the server was REWRITTEN by the proxy.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001409
willy tarreauc5f73ed2005-12-18 01:26:38 +01001410 D : the cookie provided by the server was DELETED by the proxy.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001411
willy tarreauc5f73ed2005-12-18 01:26:38 +01001412 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001413
willy tarreauc5f73ed2005-12-18 01:26:38 +01001414The combination of the two first flags give a lot of information about what was
1415happening when the session terminated. It can be helpful to detect server
1416saturation, network troubles, local system resource starvation, attacks, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01001417
willy tarreauc5f73ed2005-12-18 01:26:38 +01001418The most common termination flags combinations are indicated here.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001419
willy tarreauc5f73ed2005-12-18 01:26:38 +01001420 Flags Reason
1421 CR The client aborted before sending a full request. Most probably the
1422 request was done by hand using a telnet client, and aborted early.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001423
willy tarreauc5f73ed2005-12-18 01:26:38 +01001424 cR The client timed out before sending a full request. This is sometimes
1425 caused by too large TCP MSS values on the client side for PPPoE
1426 networks which cannot transport full-sized packets, or by clients
1427 sending requests by hand and not typing fast enough.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001428
willy tarreauc5f73ed2005-12-18 01:26:38 +01001429 SC The server explicitly refused the connection (the proxy received a
1430 TCP RST or an ICMP in return). Under some circumstances, it can
1431 also be the network stack telling the proxy that the server is
1432 unreachable (eg: no route, or no ARP response on local network).
willy tarreau982249e2005-12-18 00:57:06 +01001433
willy tarreauc5f73ed2005-12-18 01:26:38 +01001434 sC The connection to the server did not complete during contimeout.
willy tarreau982249e2005-12-18 00:57:06 +01001435
willy tarreauc5f73ed2005-12-18 01:26:38 +01001436 PC The proxy refused to establish a connection to the server because the
1437 maxconn limit has been reached. The listener's maxconn parameter may
1438 be increased in the proxy configuration, as well as the global
1439 maxconn parameter.
willy tarreauc1cae632005-12-17 14:12:23 +01001440
willy tarreauc5f73ed2005-12-18 01:26:38 +01001441 RC A local resource has been exhausted (memory, sockets, source ports)
1442 preventing the connection to the server from establishing. The error
1443 logs will tell precisely what was missing. Anyway, this can only be
1444 solved by system tuning.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001445
willy tarreauc5f73ed2005-12-18 01:26:38 +01001446 cH The client timed out during a POST request. This is sometimes caused
1447 by too large TCP MSS values for PPPoE networks which cannot transport
1448 full-sized packets.
willy tarreauc1cae632005-12-17 14:12:23 +01001449
willy tarreauc5f73ed2005-12-18 01:26:38 +01001450 SH The server aborted before sending its full headers, or it crashed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001451
willy tarreauc5f73ed2005-12-18 01:26:38 +01001452 sH The server failed to reply during the srvtimeout delay, which
1453 indicates too long transactions, probably caused by back-end
1454 saturation. The only solutions are to fix the problem on the
1455 application or to increase the 'srvtimeout' parameter to support
1456 longer delays (at the risk of the client giving up anyway).
1457
1458 PR The proxy blocked the client's request, either because of an invalid
1459 HTTP syntax, in which case it returned an HTTP 400 error to the
1460 client, or because a deny filter matched, in which case it returned
1461 an HTTP 403 error.
1462
1463 PH The proxy blocked the server's response, because it was invalid,
1464 incomplete, dangerous (cache control), or matched a security filter.
1465 In any case, an HTTP 502 error is sent to the client.
1466
1467 cD The client did not read any data for as long as the clitimeout delay.
1468 This is often caused by network failures on the client side.
1469
1470 CD The client unexpectedly aborted during data transfer. This is either
1471 caused by a browser crash, or by a keep-alive session between the
1472 server and the client terminated first by the client.
1473
1474 sD The server did nothing during the srvtimeout delay. This is often
1475 caused by too short timeouts on L4 equipements before the server
1476 (firewalls, load-balancers, ...).
1477
14784.2.5) Non-printable characters
willy tarreau4302f492005-12-18 01:00:37 +01001479-------------------------------
1480As of version 1.1.29, non-printable characters are not sent as-is into log
1481files, but are converted to their two-digits hexadecimal representation,
1482prefixed by the character '#'. The only characters that can now be logged
1483without being escaped are between 32 and 126 (inclusive). Obviously, the
1484escape character '#' is also encoded to avoid any ambiguity. It is the same for
1485the character '"', as well as '{', '|' and '}' when logging headers.
1486
willy tarreauc5f73ed2005-12-18 01:26:38 +010014874.2.6) Capturing HTTP headers and cookies
1488-----------------------------------------
1489Version 1.1.23 brought cookie capture, and 1.1.29 the header capture. All this
1490is performed using the 'capture' keyword.
1491
1492Cookie capture makes it easy to track a complete user session. The syntax is :
1493
1494 capture cookie <cookie_prefix> len <capture_length>
1495
1496This will enable cookie capture from both requests and responses. This way,
1497it's easy to detect when a user switches to a new session for example, because
1498the server will reassign it a new cookie.
1499
1500The FIRST cookie whose name starts with <cookie_prefix> will be captured, and
1501logged as 'NAME=value', without exceeding <capture_length> characters (64 max).
1502When the cookie name is fixed and known, it's preferable to suffix '=' to it to
1503ensure that no other cookie will be logged.
1504
1505Examples :
1506----------
1507 # capture the first cookie whose name starts with "ASPSESSION"
1508 capture cookie ASPSESSION len 32
1509
1510 # capture the first cookie whose name is exactly "vgnvisitor"
1511 capture cookie vgnvisitor= len 32
1512
1513In the logs, the field preceeding the completion indicator contains the cookie
1514value as sent by the server, preceeded by the cookie value as sent by the
1515client. Each of these field is replaced with '-' when no cookie was seen or
1516when the option is disabled.
1517
1518Header captures have a different goal. They are useful to track unique request
1519identifiers set by a previous proxy, virtual host names, user-agents, POST
1520content-length, referrers, etc. In the response, one can search for information
1521about the response length, how the server asked the cache to behave, or an
1522object location during a redirection. As for cookie captures, it is both
1523possible to include request headers and response headers at the same time. The
1524syntax is :
willy tarreau4302f492005-12-18 01:00:37 +01001525
1526 capture request header <name> len <max length>
1527 capture response header <name> len <max length>
1528
1529Note: Header names are not case-sensitive.
1530
1531Examples:
1532---------
1533 # keep the name of the virtual server
1534 capture request header Host len 20
1535 # keep the amount of data uploaded during a POST
1536 capture request header Content-Length len 10
1537
1538 # note the expected cache behaviour on the response
1539 capture response header Cache-Control len 8
1540 # note the URL location during a redirection
1541 capture response header Location len 20
1542
1543Non-existant headers are logged as empty strings, and if one header appears more
1544than once, only its last occurence will be kept. Request headers are grouped
1545within braces '{' and '}' in the same order as they were declared, and delimited
1546with a vertical bar '|' without any space. Response headers follow the same
1547representation, but are displayed after a space following the request headers
1548block. These blocks are displayed just before the HTTP request in the logs.
willy tarreauc5f73ed2005-12-18 01:26:38 +01001549
willy tarreau4302f492005-12-18 01:00:37 +01001550Example :
1551
willy tarreauc5f73ed2005-12-18 01:26:38 +01001552 Config:
1553
1554 capture request header Host len 20
1555 capture request header Content-Length len 10
1556 capture request header Referer len 20
1557 capture response header Server len 20
1558 capture response header Content-Length len 10
1559 capture response header Cache-Control len 8
1560 capture response header Via len 20
1561 capture response header Location len 20
1562
1563 Log :
1564
1565 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/"
1566 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"
1567 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"
1568
1569
15704.2.7) Examples of logs
1571-----------------------
1572- 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"
1573 => long request (6.5s) entered by hand through 'telnet'. The server replied
1574 in 147 ms, and the session ended normally ('----')
1575
1576- 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"
1577 => request for a long data transfer. The 'logasap' option was specified, so
1578 the log was produced just before transfering data. The server replied in
1579 14 ms, 243 bytes of headers were sent to the client, and total time from
1580 accept to first data byte is 30 ms.
1581
1582- 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"
1583 => the proxy blocked a server response either because of an 'rspdeny' or
1584 'rspideny' filter, or because it blocked sensible information which risked
1585 being cached. In this case, the response is replaced with a '502 bad
1586 gateway'.
1587
1588- 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 ""
1589 => the client never completed its request and aborted itself ('C---') after
1590 8.5s, while the proxy was waiting for the request headers ('-R--').
1591 Nothing was sent to the server.
1592
1593- 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 ""
1594 => The client never completed its request, which was aborted by the time-out
1595 ('c---') after 50s, while the proxy was waiting for the request headers ('-R--').
1596 Nothing was sent to the server, but the proxy could send a 408 return code
1597 to the client.
willy tarreau4302f492005-12-18 01:00:37 +01001598
willy tarreauc5f73ed2005-12-18 01:26:38 +01001599- haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28] relais-tcp Srv1 0/5007 0 cD
1600 => This is a 'tcplog' entry. Client-side time-out ('c----') occured after 5s.
willy tarreau4302f492005-12-18 01:00:37 +01001601
willy tarreauc5f73ed2005-12-18 01:26:38 +01001602- 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"
1603 => The request took 3s to complete (probably a network problem), and the
1604 connection to the server failed ('SC--') after 4 attemps of 2 seconds
1605 (config says 'retries 3'), then a 503 error code was sent to the client.
1606 There were 202 connections on this proxy, and 205 on the global process.
1607 It is possible that the server refused the connection because of too many
1608 already established.
willy tarreau4302f492005-12-18 01:00:37 +01001609
willy tarreau4302f492005-12-18 01:00:37 +01001610
willy tarreau197e8ec2005-12-17 14:10:59 +010016114.3) HTTP header manipulation
1612-----------------------------
1613In HTTP mode, it is possible to rewrite, add or delete some of the request and
1614response headers based on regular expressions. It is also possible to block a
1615request or a response if a particular header matches a regular expression,
1616which is enough to stops most elementary protocol attacks, and to protect
1617against information leak from the internal network. But there is a limitation
1618to this : since haproxy's HTTP engine knows nothing about keep-alive, only
1619headers passed during the first request of a TCP session will be seen. All
1620subsequent headers will be considered data only and not analyzed. Furthermore,
1621haproxy doesn't touch data contents, it stops at the end of headers.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001622
willy tarreau197e8ec2005-12-17 14:10:59 +01001623The syntax is :
1624 reqadd <string> to add a header to the request
1625 reqrep <search> <replace> to modify the request
1626 reqirep <search> <replace> same, but ignoring the case
1627 reqdel <search> to delete a header in the request
1628 reqidel <search> same, but ignoring the case
1629 reqallow <search> definitely allow a request if a header matches <search>
1630 reqiallow <search> same, but ignoring the case
1631 reqdeny <search> denies a request if a header matches <search>
1632 reqideny <search> same, but ignoring the case
1633 reqpass <search> ignore a header matching <search>
1634 reqipass <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01001635
willy tarreau197e8ec2005-12-17 14:10:59 +01001636 rspadd <string> to add a header to the response
1637 rsprep <search> <replace> to modify the response
1638 rspirep <search> <replace> same, but ignoring the case
1639 rspdel <search> to delete the response
1640 rspidel <search> same, but ignoring the case
willy tarreau982249e2005-12-18 00:57:06 +01001641 rspdeny <search> replaces a response with a HTTP 502 if a header matches <search>
1642 rspideny <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01001643
1644
willy tarreau197e8ec2005-12-17 14:10:59 +01001645<search> is a POSIX regular expression (regex) which supports grouping through
1646parenthesis (without the backslash). Spaces and other delimiters must be
1647prefixed with a backslash ('\') to avoid confusion with a field delimiter.
1648Other characters may be prefixed with a backslash to change their meaning :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001649
willy tarreau197e8ec2005-12-17 14:10:59 +01001650 \t for a tab
1651 \r for a carriage return (CR)
1652 \n for a new line (LF)
1653 \ to mark a space and differentiate it from a delimiter
1654 \# to mark a sharp and differentiate it from a comment
1655 \\ to use a backslash in a regex
1656 \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy)
1657 \xXX to write the ASCII hex code XX as in the C language
willy tarreaueedaa9f2005-12-17 14:08:03 +01001658
1659
willy tarreau197e8ec2005-12-17 14:10:59 +01001660<replace> containst the string to be used to replace the largest portion of text
1661matching the regex. It can make use of the special characters above, and can
1662reference a substring delimited by parenthesis in the regex, by the group
1663numerical order from 1 to 9. In this case, you would write a backslah ('\')
1664immediately followed by one digit indicating the group position.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001665
willy tarreau197e8ec2005-12-17 14:10:59 +01001666<string> represents the string which will systematically be added after the last
1667header line. It can also use special characters above.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001668
willy tarreau197e8ec2005-12-17 14:10:59 +01001669Notes :
1670-------
1671 - the first line is considered as a header, which makes it possible to rewrite
1672 or filter HTTP requests URIs or response codes.
1673 - 'reqrep' is the equivalent of 'cliexp' in version 1.0, and 'rsprep' is the
1674 equivalent of 'srvexp' in 1.0. Those names are still supported but
1675 deprecated.
1676 - for performances reasons, the number of characters added to a request or to
1677 a response is limited to 4096 since version 1.1.5 (it was 256 before). This
1678 value is easy to modify in the code if needed (#define). If it is too short
1679 on occasional uses, it is possible to gain some space by removing some
1680 useless headers before adding new ones.
willy tarreau982249e2005-12-18 00:57:06 +01001681 - a denied request will generate an "HTTP 403 forbidden" response, while a
1682 denied response will generate an "HTTP 502 Bad gateway" response.
1683
willy tarreaueedaa9f2005-12-17 14:08:03 +01001684
willy tarreau197e8ec2005-12-17 14:10:59 +01001685Examples :
1686----------
willy tarreauc5f73ed2005-12-18 01:26:38 +01001687 ###### a few examples ######
willy tarreau197e8ec2005-12-17 14:10:59 +01001688
willy tarreauc5f73ed2005-12-18 01:26:38 +01001689 # rewrite 'online.fr' instead of 'free.fr' for GET and POST requests
1690 reqrep ^(GET\ .*)(.free.fr)(.*) \1.online.fr\3
1691 reqrep ^(POST\ .*)(.free.fr)(.*) \1.online.fr\3
willy tarreau197e8ec2005-12-17 14:10:59 +01001692
willy tarreauc5f73ed2005-12-18 01:26:38 +01001693 # force proxy connections to close
1694 reqirep ^Proxy-Connection:.* Proxy-Connection:\ close
1695 # rewrite locations
1696 rspirep ^(Location:\ )([^:]*://[^/]*)(.*) \1\3
willy tarreaueedaa9f2005-12-17 14:08:03 +01001697
willy tarreauc5f73ed2005-12-18 01:26:38 +01001698 ###### A full configuration being used on production ######
willy tarreaueedaa9f2005-12-17 14:08:03 +01001699
willy tarreau197e8ec2005-12-17 14:10:59 +01001700 # Every header should end with a colon followed by one space.
willy tarreauc5f73ed2005-12-18 01:26:38 +01001701 reqideny ^[^:\ ]*[\ ]*$
willy tarreaueedaa9f2005-12-17 14:08:03 +01001702
willy tarreau197e8ec2005-12-17 14:10:59 +01001703 # block Apache chunk exploit
willy tarreauc5f73ed2005-12-18 01:26:38 +01001704 reqideny ^Transfer-Encoding:[\ ]*chunked
1705 reqideny ^Host:\ apache-
willy tarreaueedaa9f2005-12-17 14:08:03 +01001706
willy tarreau197e8ec2005-12-17 14:10:59 +01001707 # block annoying worms that fill the logs...
willy tarreauc5f73ed2005-12-18 01:26:38 +01001708 reqideny ^[^:\ ]*\ .*(\.|%2e)(\.|%2e)(%2f|%5c|/|\\\\)
1709 reqideny ^[^:\ ]*\ ([^\ ]*\ [^\ ]*\ |.*%00)
1710 reqideny ^[^:\ ]*\ .*<script
1711 reqideny ^[^:\ ]*\ .*/(root\.exe\?|cmd\.exe\?|default\.ida\?)
willy tarreau197e8ec2005-12-17 14:10:59 +01001712
1713 # allow other syntactically valid requests, and block any other method
willy tarreauc5f73ed2005-12-18 01:26:38 +01001714 reqipass ^(GET|POST|HEAD|OPTIONS)\ /.*\ HTTP/1\.[01]$
1715 reqipass ^OPTIONS\ \\*\ HTTP/1\.[01]$
1716 reqideny ^[^:\ ]*\
willy tarreau197e8ec2005-12-17 14:10:59 +01001717
1718 # force connection:close, thus disabling HTTP keep-alive
willy tarreauc5f73ed2005-12-18 01:26:38 +01001719 option httpclose
willy tarreau197e8ec2005-12-17 14:10:59 +01001720
willy tarreauc5f73ed2005-12-18 01:26:38 +01001721 # change the server name
1722 rspidel ^Server:\
1723 rspadd Server:\ Formilux/0.1.8
willy tarreau197e8ec2005-12-17 14:10:59 +01001724
1725
willy tarreau982249e2005-12-18 00:57:06 +01001726Also, the 'forwardfor' option creates an HTTP 'X-Forwarded-For' header which
willy tarreauc1cae632005-12-17 14:12:23 +01001727contains the client's IP address. This is useful to let the final web server
1728know what the client address was (eg for statistics on domains).
1729
willy tarreau982249e2005-12-18 00:57:06 +01001730Last, the 'httpclose' option removes any 'Connection' header both ways, and
1731adds a 'Connection: close' header in each direction. This makes it easier to
1732disable HTTP keep-alive than the previous 4-rules block..
1733
willy tarreauc1cae632005-12-17 14:12:23 +01001734Example :
1735---------
1736 listen http_proxy 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001737 mode http
1738 log global
1739 option httplog
1740 option dontlognull
1741 option forwardfor
1742 option httpclose
1743
willy tarreau197e8ec2005-12-17 14:10:59 +01001744
17454.4) Load balancing with persistence
1746------------------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001747Combining cookie insertion with internal load balancing allows to transparently
1748bring persistence to applications. The principle is quite simple :
1749 - assign a cookie value to each server
1750 - enable the load balancing between servers
1751 - insert a cookie into responses resulting from the balancing algorithm
1752 (indirect accesses), end ensure that no upstream proxy will cache it.
1753 - remove the cookie in the request headers so that the application never sees
1754 it.
1755
1756Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001757---------
1758 listen application 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001759 mode http
1760 cookie SERVERID insert nocache indirect
1761 balance roundrobin
1762 server srv1 192.168.1.1:80 cookie server01 check
1763 server srv2 192.168.1.2:80 cookie server02 check
willy tarreaueedaa9f2005-12-17 14:08:03 +01001764
willy tarreau0174f312005-12-18 01:02:42 +01001765The other solution brought by versions 1.1.30 and 1.2.3 is to reuse a cookie
1766from the server, and prefix the server's name to it. In this case, don't forget
1767to force "httpclose" mode so that you can be assured that every subsequent
1768request will have its cookie fixed.
1769
1770 listen application 0.0.0.0:80
willy tarreauc5f73ed2005-12-18 01:26:38 +01001771 mode http
1772 cookie JSESSIONID prefix
1773 balance roundrobin
1774 server srv1 192.168.1.1:80 cookie srv1 check
1775 server srv2 192.168.1.2:80 cookie srv2 check
1776 option httpclose
willy tarreau0174f312005-12-18 01:02:42 +01001777
1778
willy tarreau982249e2005-12-18 00:57:06 +010017794.5) Protection against information leak from the servers
1780---------------------------------------------------------
1781In versions 1.1.28/1.2.1, a new option 'checkcache' was created. It carefully
1782checks 'Cache-control', 'Pragma' and 'Set-cookie' headers in server response
1783to check if there's a risk of caching a cookie on a client-side proxy. When this
1784option is enabled, the only responses which can be delivered to the client are :
1785 - all those without 'Set-Cookie' header ;
1786 - all those with a return code other than 200, 203, 206, 300, 301, 410,
1787 provided that the server has not set a 'Cache-control: public' header ;
1788 - all those that come from a POST request, provided that the server has not
1789 set a 'Cache-Control: public' header ;
1790 - those with a 'Pragma: no-cache' header
1791 - those with a 'Cache-control: private' header
1792 - those with a 'Cache-control: no-store' header
1793 - those with a 'Cache-control: max-age=0' header
1794 - those with a 'Cache-control: s-maxage=0' header
1795 - those with a 'Cache-control: no-cache' header
1796 - those with a 'Cache-control: no-cache="set-cookie"' header
1797 - those with a 'Cache-control: no-cache="set-cookie,' header
1798 (allowing other fields after set-cookie)
willy tarreaueedaa9f2005-12-17 14:08:03 +01001799
willy tarreau982249e2005-12-18 00:57:06 +01001800If a response doesn't respect these requirements, then it will be blocked just
1801as if it was from an 'rspdeny' filter, with an "HTTP 502 bad gateway". The
1802session state shows "PH--" meaning that the proxy blocked the response during
1803headers processing. Additionnaly, an alert will be sent in the logs so that
1804admins are told that there's something to be done.
1805
willy tarreauc5f73ed2005-12-18 01:26:38 +01001806
willy tarreau982249e2005-12-18 00:57:06 +010018074.6) Customizing errors
1808-----------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001809Some situations can make haproxy return an HTTP error code to the client :
1810 - invalid or too long request => HTTP 400
1811 - request not completely sent in time => HTTP 408
1812 - forbidden request (matches a deny filter) => HTTP 403
1813 - internal error in haproxy => HTTP 500
1814 - the server returned an invalid or incomplete response => HTTP 502
1815 - no server was available to handle the request => HTTP 503
1816 - the server failed to reply in time => HTTP 504
willy tarreaueedaa9f2005-12-17 14:08:03 +01001817
willy tarreau197e8ec2005-12-17 14:10:59 +01001818A succint error message taken from the RFC accompanies these return codes.
1819But depending on the clients knowledge, it may be better to return custom, user
1820friendly, error pages. This is made possible through the use of the 'errorloc'
1821command :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001822
willy tarreau197e8ec2005-12-17 14:10:59 +01001823 errorloc <HTTP_code> <location>
willy tarreaueedaa9f2005-12-17 14:08:03 +01001824
willy tarreau197e8ec2005-12-17 14:10:59 +01001825Instead of generating an HTTP error <HTTP_code> among those above, the proxy
1826will return a temporary redirection code (HTTP 302) towards the address
1827specified in <location>. This address may be either relative to the site or
1828absolute. Since this request will be handled by the client's browser, it's
1829mandatory that the returned address be reachable from the outside.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001830
willy tarreau197e8ec2005-12-17 14:10:59 +01001831Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001832---------
1833 listen application 0.0.0.0:80
1834 errorloc 400 /badrequest.html
1835 errorloc 403 /forbidden.html
1836 errorloc 408 /toolong.html
willy tarreauc5f73ed2005-12-18 01:26:38 +01001837 errorloc 500 http://haproxy.domain.net/bugreport.html
willy tarreaueedaa9f2005-12-17 14:08:03 +01001838 errorloc 502 http://192.168.114.58/error50x.html
1839 errorloc 503 http://192.168.114.58/error50x.html
1840 errorloc 504 http://192.168.114.58/error50x.html
1841
willy tarreauc1f47532005-12-18 01:08:26 +01001842Note: RFC2616 says that a client must reuse the same method to fetch the
1843Location returned by a 302, which causes problems with the POST method.
1844The return code 303 was designed explicitly to force the client to fetch the
1845Location URL with the GET method, but there are some browsers pre-dating
1846HTTP/1.1 which don't support it. Anyway, most browsers still behave with 302 as
willy tarreauc5f73ed2005-12-18 01:26:38 +01001847if it was a 303. In order to allow the user to chose, versions 1.1.31 and 1.2.5
1848bring two new keywords to replace 'errorloc' : 'errorloc302' and 'errorloc303'.
willy tarreauc1f47532005-12-18 01:08:26 +01001849
1850They are preffered over errorloc (which still does 302). Consider using
1851errorloc303 everytime you know that your clients support HTTP 303 responses..
1852
1853
willy tarreau982249e2005-12-18 00:57:06 +010018544.7) Modifying default values
willy tarreau197e8ec2005-12-17 14:10:59 +01001855-----------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001856Version 1.1.22 introduced the notion of default values, which eliminates the
1857pain of often repeating common parameters between many instances, such as
1858logs, timeouts, modes, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01001859
willy tarreau197e8ec2005-12-17 14:10:59 +01001860Default values are set in a 'defaults' section. Each of these section clears
1861all previously set default parameters, so there may be as many default
1862parameters as needed. Only the last one before a 'listen' section will be
1863used for this section. The 'defaults' section uses the same syntax as the
1864'listen' section, for the supported parameters. The 'defaults' keyword ignores
1865everything on its command line, so that fake instance names can be specified
1866there for better clarity.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001867
willy tarreau982249e2005-12-18 00:57:06 +01001868In version 1.1.28/1.2.1, only those parameters can be preset in the 'default'
willy tarreau197e8ec2005-12-17 14:10:59 +01001869section :
1870 - log (the first and second one)
willy tarreaueedaa9f2005-12-17 14:08:03 +01001871 - mode { tcp, http, health }
1872 - balance { roundrobin }
willy tarreau197e8ec2005-12-17 14:10:59 +01001873 - disabled (to disable every further instances)
1874 - enabled (to enable every further instances, this is the default)
willy tarreaueedaa9f2005-12-17 14:08:03 +01001875 - contimeout, clitimeout, srvtimeout, grace, retries, maxconn
willy tarreau982249e2005-12-18 00:57:06 +01001876 - option { redispatch, transparent, keepalive, forwardfor, logasap, httpclose,
1877 checkcache, httplog, tcplog, dontlognull, persist, httpchk }
willy tarreaueedaa9f2005-12-17 14:08:03 +01001878 - redispatch, redisp, transparent, source { addr:port }
1879 - cookie, capture
1880 - errorloc
1881
willy tarreau197e8ec2005-12-17 14:10:59 +01001882As of 1.1.24, it is not possible to put certain parameters in a 'defaults'
1883section, mainly regular expressions and server configurations :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001884 - dispatch, server,
willy tarreau197e8ec2005-12-17 14:10:59 +01001885 - req*, rsp*
willy tarreaueedaa9f2005-12-17 14:08:03 +01001886
willy tarreau197e8ec2005-12-17 14:10:59 +01001887Last, there's no way yet to change a boolean option from its assigned default
1888value. So if an 'option' statement is set in a 'defaults' section, the only
1889way to flush it is to redefine a new 'defaults' section without this 'option'.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001890
willy tarreau197e8ec2005-12-17 14:10:59 +01001891Examples :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001892----------
1893 defaults applications TCP
willy tarreauc5f73ed2005-12-18 01:26:38 +01001894 log global
1895 mode tcp
1896 balance roundrobin
1897 clitimeout 180000
1898 srvtimeout 180000
1899 contimeout 4000
1900 retries 3
1901 redispatch
willy tarreaueedaa9f2005-12-17 14:08:03 +01001902
1903 listen app_tcp1 10.0.0.1:6000-6063
willy tarreauc5f73ed2005-12-18 01:26:38 +01001904 server srv1 192.168.1.1 check port 6000 inter 10000
1905 server srv2 192.168.1.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01001906
1907 listen app_tcp2 10.0.0.2:6000-6063
willy tarreauc5f73ed2005-12-18 01:26:38 +01001908 server srv1 192.168.2.1 check port 6000 inter 10000
1909 server srv2 192.168.2.2 backup
willy tarreaueedaa9f2005-12-17 14:08:03 +01001910
1911 defaults applications HTTP
willy tarreauc5f73ed2005-12-18 01:26:38 +01001912 log global
1913 mode http
1914 option httplog
1915 option forwardfor
1916 option dontlognull
1917 balance roundrobin
1918 clitimeout 20000
1919 srvtimeout 20000
1920 contimeout 4000
1921 retries 3
willy tarreaueedaa9f2005-12-17 14:08:03 +01001922
1923 listen app_http1 10.0.0.1:80-81
willy tarreauc5f73ed2005-12-18 01:26:38 +01001924 cookie SERVERID postonly insert indirect
1925 capture cookie userid= len 10
1926 server srv1 192.168.1.1:+8000 cookie srv1 check port 8080 inter 1000
1927 server srv1 192.168.1.2:+8000 cookie srv2 check port 8080 inter 1000
willy tarreaueedaa9f2005-12-17 14:08:03 +01001928
1929 defaults
willy tarreauc5f73ed2005-12-18 01:26:38 +01001930 # this empty section voids all default parameters
willy tarreaueedaa9f2005-12-17 14:08:03 +01001931
willy tarreau197e8ec2005-12-17 14:10:59 +01001932=========================
1933| System-specific setup |
1934=========================
willy tarreaueedaa9f2005-12-17 14:08:03 +01001935
willy tarreau197e8ec2005-12-17 14:10:59 +01001936Linux 2.4
1937=========
willy tarreaueedaa9f2005-12-17 14:08:03 +01001938
1939-- cut here --
1940#!/bin/sh
1941# set this to about 256/4M (16384 for 256M machine)
1942MAXFILES=16384
1943echo $MAXFILES > /proc/sys/fs/file-max
1944ulimit -n $MAXFILES
1945
1946if [ -e /proc/sys/net/ipv4/ip_conntrack_max ]; then
willy tarreauc5f73ed2005-12-18 01:26:38 +01001947 echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max
willy tarreaueedaa9f2005-12-17 14:08:03 +01001948fi
1949
1950if [ -e /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait ]; then
willy tarreauc5f73ed2005-12-18 01:26:38 +01001951 # 30 seconds for fin, 15 for time wait
1952 echo 3000 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait
1953 echo 1500 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_time_wait
1954 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_invalid_scale
1955 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_out_of_window
willy tarreaueedaa9f2005-12-17 14:08:03 +01001956fi
1957
1958echo 1024 60999 > /proc/sys/net/ipv4/ip_local_port_range
1959echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
1960echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog
1961echo 262144 > /proc/sys/net/ipv4/tcp_max_tw_buckets
1962echo 262144 > /proc/sys/net/ipv4/tcp_max_orphans
1963echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time
1964echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
1965echo 0 > /proc/sys/net/ipv4/tcp_timestamps
1966echo 0 > /proc/sys/net/ipv4/tcp_ecn
willy tarreauc5f73ed2005-12-18 01:26:38 +01001967echo 1 > /proc/sys/net/ipv4/tcp_sack
willy tarreaueedaa9f2005-12-17 14:08:03 +01001968echo 0 > /proc/sys/net/ipv4/tcp_dsack
1969
1970# auto-tuned on 2.4
1971#echo 262143 > /proc/sys/net/core/rmem_max
1972#echo 262143 > /proc/sys/net/core/rmem_default
1973
1974echo 16384 65536 524288 > /proc/sys/net/ipv4/tcp_rmem
1975echo 16384 349520 699040 > /proc/sys/net/ipv4/tcp_wmem
1976
1977-- cut here --
1978
willy tarreau197e8ec2005-12-17 14:10:59 +01001979
1980FreeBSD
1981=======
1982
1983A FreeBSD port of HA-Proxy is now available and maintained, thanks to
1984Clement Laforet <sheepkiller@cultdeadsheep.org>.
1985
1986For more information :
1987http://www.freebsd.org/cgi/url.cgi?ports/net/haproxy/pkg-descr
1988http://www.freebsd.org/cgi/cvsweb.cgi/ports/net/haproxy/
1989http://www.freshports.org/net/haproxy
1990
1991
1992-- end --