blob: 65ebb96d6e16146c650ad21ef5ab8e9eb923c80e [file] [log] [blame]
willy tarreau0174f312005-12-18 01:02:42 +01001 -------------------
2 H A - P r o x y
3 Reference Manual
4 -------------------
willy tarreauc1f47532005-12-18 01:08:26 +01005 version 1.2.5
willy tarreaueedaa9f2005-12-17 14:08:03 +01006 willy tarreau
willy tarreauc1f47532005-12-18 01:08:26 +01007 2005/04/24
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')
47
48
49The maximal number of connections per proxy is used as the default parameter for
50each instance for which the 'maxconn' paramter is not set in the 'listen' section.
51
52The maximal number of total connections limits the number of connections used by
53the whole process if the 'maxconn' parameter is not set in the 'global' section.
54
55The debugging mode has the same effect as the 'debug' option in the 'global'
56section. When the proxy runs in this mode, it dumps every connections,
57disconnections, timestamps, and HTTP headers to stdout. This should NEVER
58be used in an init script since it will prevent the system from starting up.
59
60Statistics are only available if compiled in with the 'STATTIME' option. It's
61only used during code optimization phases.
62
63======================
64| Configuration file |
65======================
66
67Structure
68=========
69
70The configuration file parser ignores empty lines, spaces, tabs. Anything
71between a sharp ('#') not following a backslash ('\'), and the end of a line
72constitutes a comment and is ignored too.
73
74The configuration file is segmented in sections. A section begins whenever
75one of these 3 keywords are encountered :
76
77 - 'global'
78 - 'listen'
79 - 'defaults'
80
81Every parameter refer to the section beginning at the last one of these 3
82keywords.
83
84
851) Global parameters
86====================
87
88Global parameters affect the whole process behaviour. They are all set in the
89'global' section. There may be several 'global' sections if needed, but their
90parameters will only be merged. Allowed parameters in 'global' section include
91the following ones :
92
93 - log <address> <facility> [max_level]
94 - maxconn <number>
95 - uid <user id>
96 - gid <group id>
97 - chroot <directory>
98 - nbproc <number>
99 - daemon
100 - debug
101 - quiet
willy tarreaufe2c5c12005-12-17 14:14:34 +0100102 - pidfile <file>
willy tarreau598da412005-12-18 01:07:29 +0100103 - stats
willy tarreaueedaa9f2005-12-17 14:08:03 +0100104
1051.1) Event logging
106------------------
107Most events are logged : start, stop, servers going up and down, connections and
108errors. Each event generates a syslog message which can be sent to up to 2
109servers. The syntax is :
110
111 log <ip_address> <facility> [max_level]
112
113Connections are logged at level "info". Services initialization and servers
114going up are logged at level "notice", termination signals are logged at
115"warning", and definitive service termination, as well as loss of servers are
116logged at level "alert". The optional parameter <max_level> specifies above
117what level messages should be sent. Level can take one of these 8 values :
118
119 emerg, alert, crit, err, warning, notice, info, debug
120
121For backwards compatibility with versions 1.1.16 and earlier, the default level
122value is "debug" if not specified.
123
124Permitted facilities are :
125 kern, user, mail, daemon, auth, syslog, lpr, news,
126 uucp, cron, auth2, ftp, ntp, audit, alert, cron2,
127 local0, local1, local2, local3, local4, local5, local6, local7
128
129According to RFC3164, messages are truncated to 1024 bytes before being emitted.
130
131Example :
132---------
133 global
134 log 192.168.2.200 local3
135 log 127.0.0.1 local4 notice
136
1371.2) limiting the number of connections
138---------------------------------------
139It is possible and recommended to limit the global number of per-process
140connections. Since one connection includes both a client and a server, it
141means that the max number of TCP sessions will be about the double of this
142number. It's important to understand this when trying to find best values
143for 'ulimit -n' before starting the proxy. To anticipate the number of
144sockets needed, all these parameters must be counted :
145
146 - 1 socket per incoming connection
147 - 1 socket per outgoing connection
148 - 1 socket per address/port/proxy tuple.
149 - 1 socket per server being health-checked
150 - 1 socket for all logs
151
152In simple configurations where each proxy only listens one one address/port,
153set the limit of file descriptors (ulimit -n) to
154(2 * maxconn + nbproxies + nbservers + 1). In a future release, haproxy may
155be able to set this value itself.
156
1571.3) Drop of priviledges
158------------------------
159In order to reduce the risk and consequences of attacks, in the event where a
160yet non-identified vulnerability would be successfully exploited, it's possible
161to lower the process priviledges and even isolate it in a riskless directory.
162
163In the 'global' section, the 'uid' parameter sets a numerical user identifier
164which the process will switch to after binding its listening sockets. The value
165'0', which normally represents the super-user, here indicates that the UID must
166not change during startup. It's the default behaviour. The 'gid' parameter does
167the same for the group identifier. It's particularly advised against use of
168generic accounts such as 'nobody' because it has the same consequences as using
169'root' if other services use them.
170
171The 'chroot' parameter makes the process isolate itself in an empty directory
172just before switching its UID. This type of isolation (chroot) can sometimes
173be worked around on certain OS (Linux, Solaris), provided that the attacker
174has gained 'root' priviledges and has the ability to use or create a directory.
175For this reason, it's capital to use a dedicated directory and not to share one
176between several services of different nature. To make isolation more resistant,
177it's recommended to use an empty directory without any right, and to change the
178UID of the process so that it cannot do anything there.
179
180Note: in the event where such a vulnerability would be exploited, it's most
181likely that first attempts would kill the process due to 'Segmentation Fault',
182'Bus Error' or 'Illegal Instruction' signals. Eventhough it's true that
183isolating the server reduces the risks of intrusion, it's sometimes useful to
184find why a process dies, via the analysis of a 'core' file, although very rare
185(the last bug of this sort was fixed in 1.1.9). For security reasons, most
186systems disable the generation of core file when a process changes its UID. So
187the two workarounds are either to start the process from a restricted user
188account, which will not be able to chroot itself, or start it as root and not
189change the UID. In both cases the core will be either in the start or the chroot
190directories. Do not forget to allow core dumps prior to start the process :
191
192# ulimit -c unlimited
193
194Example :
195---------
196
197 global
198 uid 30000
199 gid 30000
200 chroot /var/chroot/haproxy
201
2021.4) Startup modes
203------------------
204The service can start in several different :
205 - foreground / background
206 - quiet / normal / debug
207
208The default mode is normal, foreground, which means that the program doesn't
209return once started. NEVER EVER use this mode in a system startup script, or
210the system won't boot. It needs to be started in background, so that it
211returns immediately after forking. That's accomplished by the 'daemon' option
212in the 'global' section, which is the equivalent of the '-D' command line
213argument.
214
215Moreover, certain alert messages are still sent to the standard output even
216in 'daemon' mode. To make them disappear, simply add the 'quiet' option in the
217'global' section. This option has no command-line equivalent.
218
219Last, the 'debug' mode, enabled with the 'debug' option in the 'global' section,
220and which is equivalent of the '-d' option, allows deep TCP/HTTP analysis, with
221timestamped display of each connection, disconnection, and HTTP headers for both
222ways. This mode is incompatible with 'daemon' and 'quiet' modes for obvious
223reasons.
224
2251.5) Increasing the overall processing power
226--------------------------------------------
227On multi-processor systems, it may seem to be a shame to use only one processor,
willy tarreau982249e2005-12-18 00:57:06 +0100228eventhough the load needed to saturate a recent processor is far above common
willy tarreaueedaa9f2005-12-17 14:08:03 +0100229usage. Anyway, for very specific needs, the proxy can start several processes
230between which the operating system will spread the incoming connections. The
231number of processes is controlled by the 'nbproc' parameter in the 'global'
willy tarreau4302f492005-12-18 01:00:37 +0100232section. It defaults to 1, and obviously works only in 'daemon' mode. One
233typical usage of this parameter has been to workaround the default per-process
234file-descriptor limit that Solaris imposes to user processes.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100235
236Example :
237---------
238
239 global
240 daemon
241 quiet
242 nbproc 2
243
244
willy tarreaufe2c5c12005-12-17 14:14:34 +01002451.6) Helping process management
246-------------------------------
247Haproxy now supports the notion of pidfile. If the '-p' command line argument,
248or the 'pidfile' global option is followed with a file name, this file will be
249removed, then filled with all children's pids, one per line (only in daemon
250mode). This file is NOT within the chroot, which allows to work with a readonly
251 chroot. It will be owned by the user starting the process, and will have
252permissions 0644.
253
254Example :
255---------
256
257 global
258 daemon
259 quiet
260 nbproc 2
261 pidfile /var/run/haproxy-private.pid
262
263 # to stop only those processes among others :
264 # kill $(</var/run/haproxy-private.pid)
265
266
willy tarreaueedaa9f2005-12-17 14:08:03 +01002672) Declaration of a listening service
268=====================================
269
270Service sections start with the 'listen' keyword :
271
272 listen <instance_name> [ <IP_address>:<port_range>[,...] ]
273
274- <instance_name> is the name of the instance. This name will be reported in
275 logs, so it is good to have it reflect the proxied service. No unicity test
276 is done on this name, and it's not mandatory for it to be unique, but highly
277 recommended.
278
279- <IP_address> is the IP address the proxy binds to. Empty address, '*' and
280 '0.0.0.0' all mean that the proxy listens to all valid addresses on the
281 system.
282
283- <port_range> is either a unique port, or a port range for which the proxy will
284 accept connections for the IP address specified above. This range can be :
285 - a numerical port (ex: '80')
286 - a dash-delimited ports range explicitly stating the lower and upper bounds
287 (ex: '2000-2100') which are included in the range.
288
289 Particular care must be taken against port ranges, because every <addr:port>
290 couple consumes one socket (=a file descriptor), so it's easy to eat lots of
291 descriptors with a simple range. The <addr:port> couple must be used only once
292 among all instances running on a same system. Please note that attaching to
293 ports lower than 1024 need particular priviledges to start the program, which
294 are independant of the 'uid' parameter.
295
296- the <IP_address>:<port_range> couple may be repeated indefinitely to require
297 the proxy to listen to other addresses and/or ports. To achieve this, simply
298 separate them with a coma.
299
300Examples :
301---------
302 listen http_proxy :80
303 listen x11_proxy 127.0.0.1:6000-6009
304 listen smtp_proxy 127.0.0.1:25,127.0.0.1:587
305 listen ldap_proxy :389,:663
306
307In the event that all addresses do not fit line width, it's preferable to
308detach secondary addresses on other lines with the 'bind' keyword. If this
309keyword is used, it's not even necessary to specify the first address on the
310'listen' line, which sometimes makes multiple configuration handling easier :
311
312 bind [ <IP_address>:<port_range>[,...] ]
313
314Examples :
315----------
316 listen http_proxy
317 bind :80,:443
318 bind 10.0.0.1:10080,10.0.0.1:10443
319
3202.1) Inhibiting a service
321-------------------------
322A service may be disabled for maintenance reasons, without needing to comment
323out the whole section, simply by specifying the 'disabled' keyword in the
324section to be disabled :
325
326 listen smtp_proxy 0.0.0.0:25
327 disabled
328
329Note: the 'enabled' keyword allows to enable a service which has been disabled
330 previously by a default configuration.
331
3322.2) Modes of operation
333-----------------------
334A service can work in 3 different distinct modes :
335 - TCP
336 - HTTP
337 - monitoring
338
339TCP mode
340--------
341In this mode, the service relays TCP connections as soon as they're established,
342towards one or several servers. No processing is done on the stream. It's only
343an association of source(addr:port) -> destination(addr:port). To use this mode,
344you must specify 'mode tcp' in the 'listen' section. This is the default mode.
345
346Example :
347---------
348 listen smtp_proxy 0.0.0.0:25
349 mode tcp
350
351HTTP mode
352---------
353In this mode, the service relays TCP connections towards one or several servers,
354when it has enough informations to decide, which normally means that all HTTP
355headers have been read. Some of them may be scanned for a cookie or a pattern
356matching a regex. To use this mode, specify 'mode http' in the 'listen' section.
357
358Example :
359---------
360 listen http_proxy 0.0.0.0:80
361 mode http
362
363Health-checking mode
364--------------------
365This mode provides a way for external components to check the proxy's health.
366It is meant to be used with intelligent load-balancers which can use send/expect
367scripts to check for all of their servers' availability. This one simply accepts
willy tarreau197e8ec2005-12-17 14:10:59 +0100368the connection, returns the word 'OK' and closes it. If the 'option httpchk' is
369set, then the reply will be 'HTTP/1.0 200 OK' with no data, so that it can be
370tested from a tool which supports HTTP health-checks. To enable it, simply
willy tarreaueedaa9f2005-12-17 14:08:03 +0100371specify 'health' as the working mode :
372
373Example :
374---------
willy tarreau197e8ec2005-12-17 14:10:59 +0100375 # simple response : 'OK'
willy tarreaueedaa9f2005-12-17 14:08:03 +0100376 listen health_check 0.0.0.0:60000
377 mode health
378
willy tarreau197e8ec2005-12-17 14:10:59 +0100379 # HTTP response : 'HTTP/1.0 200 OK'
380 listen http_health_check 0.0.0.0:60001
381 mode health
382 option httpchk
383
willy tarreaueedaa9f2005-12-17 14:08:03 +0100384
3852.3) Limiting the number of simultaneous connections
386----------------------------------------------------
387The 'maxconn' parameter allows a proxy to refuse connections above a certain
388amount of simultaneous ones. When the limit is reached, it simply stops
389listening, but the system may still be accepting them because of the back log
willy tarreau982249e2005-12-18 00:57:06 +0100390queue. These connections will be processed later when other ones have freed
willy tarreaueedaa9f2005-12-17 14:08:03 +0100391some slots. This provides a serialization effect which helps very fragile
392servers resist to high loads. Se further for system limitations.
393
394Example :
395---------
396 listen tiny_server 0.0.0.0:80
397 maxconn 10
398
399
4002.4) Soft stop
401--------------
402It is possible to stop services without breaking existing connections by the
403sending of the SIG_USR1 signal to the process. All services are then put into
404soft-stop state, which means that they will refuse to accept new connections,
405except for those which have a non-zero value in the 'grace' parameter, in which
406case they will still accept connections for the specified amount of time, in
407milliseconds. This allows to tell a load-balancer that the service is failing,
408while still doing the job during the time it needs to detect it.
409
410Note: active connections are never killed. In the worst case, the user will have
411to wait for all of them to close or to time-out, or simply kill the process
412normally (SIG_TERM). The default 'grace' value is '0'.
413
414Example :
415---------
416 # enter soft stop after 'killall -USR1 haproxy'
417 # the service will still run 10 seconds after the signal
418 listen http_proxy 0.0.0.0:80
419 mode http
420 grace 10000
421
422 # this port is dedicated to a load-balancer, and must fail immediately
423 listen health_check 0.0.0.0:60000
424 mode health
425 grace 0
426
427
4282.5) Connections expiration time
429--------------------------------
430It is possible (and recommended) to configure several time-outs on TCP
431connections. Three independant timers are adjustable with values specified
432in milliseconds. A session will be terminated if either one of these timers
433expire.
434
435 - the time we accept to wait for data from the client, or for the client to
436 accept data : 'clitimeout' :
437
438 # client time-out set to 2mn30.
439 clitimeout 150000
440
441 - the time we accept to wait for data from the server, or for the server to
442 accept data : 'srvtimeout' :
443
444 # server time-out set to 30s.
445 srvtimeout 30000
446
447 - the time we accept to wait for a connection to establish on a server :
448 'contimeout' :
449
450 # we give up if the connection does not complete within 4 seconds
451 contimeout 4000
452
453Notes :
454-------
455 - 'contimeout' and 'srvtimeout' have no sense on 'health' mode servers ;
456 - under high loads, or with a saturated or defective network, it's possible
457 that some packets get lost. Since the first TCP retransmit only happens
458 after 3 seconds, a time-out equal to, or lower than 3 seconds cannot
459 compensate for a packet loss. A 4 seconds time-out seems a reasonable
460 minimum which will considerably reduce connection failures.
461
4622.6) Attempts to reconnect
463--------------------------
464After a connection failure to a server, it is possible to retry, potentially
465on another server. This is useful if health-checks are too rare and you don't
466want the clients to see the failures. The number of attempts to reconnect is
467set by the 'retries' paramter.
468
469Example :
470---------
471 # we can retry 3 times max after a failure
472 retries 3
473
474
4752.7) Address of the dispatch server (deprecated)
476------------------------------------------------
477The server which will be sent all new connections is defined by the 'dispatch'
478parameter, in the form <address>:<port>. It generally is dedicated to unknown
479connections and will assign them a cookie, in case of HTTP persistence mode,
480or simply is a single server in case of generic TCP proxy. This old mode is only
481provided for backwards compatibility, but doesn't allow to check remote servers
482state, and has a rather limited usage. All new setups should switch to 'balance'
483mode. The principle of the dispatcher is to be able to perform the load
484balancing itself, but work only on new clients so that the server doesn't need
485to be a big machine.
486
487Example :
488---------
489 # all new connections go there
490 dispatch 192.168.1.2:80
491
492Note :
493------
494This parameter has no sense for 'health' servers, and is incompatible with
495'balance' mode.
496
497
4982.8) Outgoing source address
499----------------------------
500It is often necessary to bind to a particular address when connecting to some
501remote hosts. This is done via the 'source' parameter which is a per-proxy
502parameter. A newer version may allow to fix different sources to reach different
503servers. The syntax is 'source <address>[:<port>]', where <address> is a valid
504local address (or '0.0.0.0' or '*' or empty to let the system choose), and
505<port> is an optional parameter allowing the user to force the source port for
506very specific needs. If the port is not specified or is '0', the system will
507choose a free port. Note that as of version 1.1.18, the servers health checks
508are also performed from the same source.
509
510Examples :
511----------
512 listen http_proxy *:80
513 # all connections take 192.168.1.200 as source address
514 source 192.168.1.200:0
515
516 listen rlogin_proxy *:513
517 # use address 192.168.1.200 and the reserved port 900 (needs to be root)
518 source 192.168.1.200:900
519
520
5212.9) Setting the cookie name
522----------------------------
523In HTTP mode, it is possible to look for a particular cookie which will contain
524a server identifier which should handle the connection. The cookie name is set
525via the 'cookie' parameter.
526
527Example :
528---------
529 listen http_proxy :80
530 mode http
531 cookie SERVERID
532
533It is possible to change the cookie behaviour to get a smarter persistence,
534depending on applications. It is notably possible to delete or modify a cookie
535emitted by a server, insert a cookie identifying the server in an HTTP response
536and even add a header to tell upstream caches not to cache this response.
537
538Examples :
539----------
540
541To remove the cookie for direct accesses (ie when the server matches the one
542which was specified in the client cookie) :
543
544 cookie SERVERID indirect
545
546To replace the cookie value with the one assigned to the server if any (no
547cookie will be created if the server does not provide one, nor if the
548configuration does not provide one). This lets the application put the cookie
549exactly on certain pages (eg: successful authentication) :
550
551 cookie SERVERID rewrite
552
553To create a new cookie and assign the server identifier to it (in this case, all
554servers should be associated with a valid cookie, since no cookie will simply
555delete the cookie from the client's browser) :
556
557 cookie SERVERID insert
558
willy tarreau0174f312005-12-18 01:02:42 +0100559To reuse an existing application cookie and prefix it with the server's
560identifier, and remove it in the request, use the 'prefix' option. This allows
561to insert a haproxy in front of an application without risking to break clients
562which does not support more than one cookie :
563
564 cookie JSESSIONID prefix
565
willy tarreaueedaa9f2005-12-17 14:08:03 +0100566To insert a cookie and ensure that no upstream cache will store it, add the
567'nocache' option :
568
569 cookie SERVERID insert nocache
570
571To insert a cookie only after a POST request, add 'postonly' after 'insert'.
572This has the advantage that there's no risk of caching, and that all pages
573seen before the POST one can still be cached :
574
575 cookie SERVERID insert postonly
576
577Notes :
578-----------
579- it is possible to combine 'insert' with 'indirect' or 'rewrite' to adapt to
580 applications which already generate the cookie with an invalid content.
581
582- in the case where 'insert' and 'indirect' are both specified, the cookie is
willy tarreau0174f312005-12-18 01:02:42 +0100583 never transmitted to the server, since it wouldn't understand it. This is the
584 most application-transparent mode.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100585
586- it is particularly recommended to use 'nocache' in 'insert' mode if any
587 upstream HTTP/1.0 cache is susceptible to cache the result, because this may
588 lead to many clients going to the same server, or even worse, some clients
589 having their server changed while retrieving a page from the cache.
590
willy tarreau0174f312005-12-18 01:02:42 +0100591- the 'prefix' mode normally does not need 'indirect', 'nocache', nor
592 'postonly', because just as in the 'rewrite' mode, it relies on the
593 application to know when a cookie can be emitted. However, since it has to
594 fix the cookie name in every subsequent requests, you must ensure that the
595 proxy will be used without any "HTTP keep-alive". Use option "httpclose" if
596 unsure.
597
willy tarreaueedaa9f2005-12-17 14:08:03 +0100598- when the application is well known and controlled, the best method is to
599 only add the persistence cookie on a POST form because it's up to the
willy tarreau0174f312005-12-18 01:02:42 +0100600 application to select which page it wants the upstream servers to cache. In
601 this case, you would use 'insert postonly indirect'.
willy tarreaueedaa9f2005-12-17 14:08:03 +0100602
6032.10) Associating a cookie value with a server
604----------------------------------------------
605In HTTP mode, it's possible to associate a cookie value to each server. This
606was initially used in combination with 'dispatch' mode to handle direct accesses
607but it is now the standard way of doing the load balancing. The syntax is :
608
609 server <identifier> <address>:<port> cookie <value>
610
611- <identifier> is any name which can be used to identify the server in the logs.
612- <address>:<port> specifies where the server is bound.
613- <value> is the value to put in or to read from the cookie.
614
615Example : the 'SERVERID' cookie can be either 'server01' or 'server02'
616---------
617 listen http_proxy :80
618 mode http
619 cookie SERVERID
620 dispatch 192.168.1.100:80
621 server web1 192.168.1.1:80 cookie server01
622 server web2 192.168.1.2:80 cookie server02
623
624Warning : the syntax has changed since version 1.0 !
625---------
626
willy tarreau598da412005-12-18 01:07:29 +01006272.11) Application Cookies
628-------------------------
629Since 1.2.4 it is possible to catch the cookie that comes from an
630application server in order to apply "application session stickyness".
631The server's response is searched for 'appsession' cookie, the first
632'len' bytes are used for matching and it is stored for a period of
633'timeout'.
634The syntax is:
635
636 appsession <SESSIONCOOKIE> len <MATCHLENGTH> timeout <HOLDTIME>
637
638- <SESSIONCOOKIE> is the cookie, the server uses for it's session-handling
639- <MATCHLENGTH> how many bytes/characters should be used for matching equal
640 sessions
641- <HOLDTIME> after this inactivaty time, in ms, the cookie will be deleted
642 from the sessionstore
643
644The appsession is only per 'listen' section possible.
645
646Example :
647---------
648 listen http_proxy :80
649 mode http
650 appsession JSESSIONID len 52 timeout 300000
651 .
652 .
653
willy tarreaueedaa9f2005-12-17 14:08:03 +01006543) Autonomous load balancer
655===========================
656
657The proxy can perform the load-balancing itself, both in TCP and in HTTP modes.
658This is the most interesting mode which obsoletes the old 'dispatch' mode
659described above. It has advantages such as server health monitoring, multiple
660port binding and port mapping. To use this mode, the 'balance' keyword is used,
661followed by the selected algorithm. As of version 1.1.23, only 'roundrobin' is
662available, which is also the default value if unspecified. In this mode, there
663will be no dispatch address, but the proxy needs at least one server.
664
665Example : same as the last one, with internal load balancer
666---------
667
668 listen http_proxy :80
669 mode http
670 cookie SERVERID
671 balance roundrobin
672 server web1 192.168.1.1:80 cookie server01
673 server web2 192.168.1.2:80 cookie server02
674
675
676Since version 1.1.22, it is possible to automatically determine on which port
677the server will get the connection, depending on the port the client connected
678to. Indeed, there now are 4 possible combinations for the server's <port> field:
679
680 - unspecified or '0' :
681 the connection will be sent to the same port as the one on which the proxy
682 received the client connection itself.
683
684 - numerical value (the only one supported in versions earlier than 1.1.22) :
685 the connection will always be sent to the specified port.
686
687 - '+' followed by a numerical value :
688 the connection will be sent to the same port as the one on which the proxy
689 received the connection, plus this value.
690
691 - '-' followed by a numerical value :
692 the connection will be sent to the same port as the one on which the proxy
693 received the connection, minus this value.
694
695Examples :
696----------
697
698# same as previous example
699
700 listen http_proxy :80
701 mode http
702 cookie SERVERID
703 balance roundrobin
704 server web1 192.168.1.1 cookie server01
705 server web2 192.168.1.2 cookie server02
706
707# simultaneous relaying of ports 80, 81 and 8080-8089
708
709 listen http_proxy :80,:81,:8080-8089
710 mode http
711 cookie SERVERID
712 balance roundrobin
713 server web1 192.168.1.1 cookie server01
714 server web2 192.168.1.2 cookie server02
715
716# relaying of TCP ports 25, 389 and 663 to ports 1025, 1389 and 1663
717
718 listen http_proxy :25,:389,:663
719 mode tcp
720 balance roundrobin
721 server srv1 192.168.1.1:+1000
722 server srv2 192.168.1.2:+1000
723
724
willy tarreau197e8ec2005-12-17 14:10:59 +01007253.1) Server monitoring
726----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +0100727
728It is possible to check the servers status by trying to establish TCP
729connections or even sending HTTP requests to them. A server which fails to
730reply to health checks as expected will not be used by the load balancing
731algorithms. To enable monitoring, add the 'check' keyword on a server line.
732It is possible to specify the interval between tests (in milliseconds) with
733the 'inter' parameter, the number of failures supported before declaring that
734the server has fallen down with the 'fall' parameter, and the number of valid
735checks needed for the server to fully get up with the 'rise' parameter. Since
736version 1.1.22, it is also possible to send checks to a different port
737(mandatory when none is specified) with the 'port' parameter. The default
738values are the following ones :
739
740 - inter : 2000
741 - rise : 2
742 - fall : 3
743 - port : default server port
744
745The default mode consists in establishing TCP connections only. But in certain
746types of application failures, it is often that the server continues to accept
747connections because the system does it itself while the application is running
748an endless loop, or is completely stuck. So in version 1.1.16 were introduced
749HTTP health checks which only performed simple lightweight requests and analysed
750the response. Now, as of version 1.1.23, it is possible to change the HTTP
751method, the URI, and the HTTP version string (which even allows to send headers
752with a dirty trick). To enable HTTP health-checks, use 'option httpchk'.
753
754By default, requests use the 'OPTIONS' method because it's very light and easy
755to filter from logs, and does it on '/'. Only HTTP responses 2xx and 3xx are
756considered valid ones, and only if they come before the time to send a new
757request is reached ('inter' parameter). If some servers block this type of
758request, 3 other forms help to forge a request :
759
760 - option httpchk -> OPTIONS / HTTP/1.0
761 - option httpchk URI -> OPTIONS <URI> HTTP/1.0
762 - option httpchk METH URI -> <METH> <URI> HTTP/1.0
763 - option httpchk METH URI VER -> <METH> <URI> <VER>
764
765See examples below.
766
767Since version 1.1.17, it is possible to specify backup servers. These servers
768are only sollicited when no other server is available. This may only be useful
769to serve a maintenance page, or define one active and one backup server (seldom
770used in TCP mode). To make a server a backup one, simply add the 'backup' option
771on its line. These servers also support cookies, so if a cookie is specified for
772a backup server, clients assigned to this server will stick to it even when the
773other ones come back. Conversely, if no cookie is assigned to such a server,
774the clients will get their cookies removed (empty cookie = removal), and will
775be balanced against other servers once they come back. Please note that there
776is no load-balancing among backup servers. If there are several backup servers,
777the second one will only be used when the first one dies, and so on.
778
779Since version 1.1.17, it is also possible to visually check the status of all
780servers at once. For this, you just have to send a SIGHUP signal to the proxy.
781The servers status will be dumped into the logs at the 'notice' level, as well
782as on <stderr> if not closed. For this reason, it's always a good idea to have
783one local log server at the 'notice' level.
784
willy tarreau982249e2005-12-18 00:57:06 +0100785Since version 1.1.28 and 1.2.1, if an instance loses all its servers, an
willy tarreau0174f312005-12-18 01:02:42 +0100786emergency message will be sent in the logs to inform the administator that an
willy tarreau982249e2005-12-18 00:57:06 +0100787immediate action must be taken.
788
willy tarreau0174f312005-12-18 01:02:42 +0100789Since version 1.1.30 and 1.2.3, several servers can share the same cookie
790value. This is particularly useful in backup mode, to select alternate paths
791for a given server for example, to provide soft-stop, or to direct the clients
792to a temporary page during an application restart. The principle is that when
793a server is dead, the proxy will first look for another server which shares the
794same cookie value for every client which presents the cookie. If there is no
795standard server for this cookie, it will then look for a backup server which
796shares the same name. Please consult the architecture guide for more information.
willy tarreau982249e2005-12-18 00:57:06 +0100797
willy tarreaueedaa9f2005-12-17 14:08:03 +0100798Examples :
799----------
800# same setup as in paragraph 3) with TCP monitoring
801 listen http_proxy 0.0.0.0:80
802 mode http
803 cookie SERVERID
804 balance roundrobin
805 server web1 192.168.1.1:80 cookie server01 check
806 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
807
808# same with HTTP monitoring via 'OPTIONS / HTTP/1.0'
809 listen http_proxy 0.0.0.0:80
810 mode http
811 cookie SERVERID
812 balance roundrobin
813 option httpchk
814 server web1 192.168.1.1:80 cookie server01 check
815 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
816
817# same with HTTP monitoring via 'OPTIONS /index.html HTTP/1.0'
818 listen http_proxy 0.0.0.0:80
819 mode http
820 cookie SERVERID
821 balance roundrobin
822 option httpchk /index.html
823 server web1 192.168.1.1:80 cookie server01 check
824 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
825
826# same with HTTP monitoring via 'HEAD /index.jsp? HTTP/1.1\r\nHost: www'
827 listen http_proxy 0.0.0.0:80
828 mode http
829 cookie SERVERID
830 balance roundrobin
831 option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www
832 server web1 192.168.1.1:80 cookie server01 check
833 server web2 192.168.1.2:80 cookie server02 check inter 500 rise 1 fall 2
834
willy tarreau0174f312005-12-18 01:02:42 +0100835# Load-balancing with 'prefixed cookie' persistence, and soft-stop using an
836# alternate port 81 on the server for health-checks.
837 listen http_proxy 0.0.0.0:80
838 mode http
839 cookie JSESSIONID prefix
840 balance roundrobin
841 option httpchk HEAD /index.jsp? HTTP/1.1\r\nHost:\ www
842 server web1-norm 192.168.1.1:80 cookie s1 check port 81
843 server web2-norm 192.168.1.2:80 cookie s2 check port 81
844 server web1-stop 192.168.1.1:80 cookie s1 check port 80 backup
845 server web2-stop 192.168.1.2:80 cookie s2 check port 80 backup
846
willy tarreaueedaa9f2005-12-17 14:08:03 +0100847# automatic insertion of a cookie in the server's response, and automatic
848# deletion of the cookie in the client request, while asking upstream caches
849# not to cache replies.
850 listen web_appl 0.0.0.0:80
851 mode http
852 cookie SERVERID insert nocache indirect
853 balance roundrobin
854 server web1 192.168.1.1:80 cookie server01 check
855 server web2 192.168.1.2:80 cookie server02 check
856
857# same with off-site application backup and local error pages server
858 listen web_appl 0.0.0.0:80
859 mode http
860 cookie SERVERID insert nocache indirect
861 balance roundrobin
862 server web1 192.168.1.1:80 cookie server01 check
863 server web2 192.168.1.2:80 cookie server02 check
864 server web-backup 192.168.2.1:80 cookie server03 check backup
865 server web-excuse 192.168.3.1:80 check backup
866
867# SMTP+TLS relaying with heakth-checks and backup servers
868
869 listen http_proxy :25,:587
870 mode tcp
871 balance roundrobin
872 server srv1 192.168.1.1 check port 25 inter 30000 rise 1 fall 2
873 server srv2 192.168.1.2 backup
874
875
8763.2) Redistribute connections in case of failure
877------------------------------------------------
878In HTTP mode, if a server designated by a cookie does not respond, the clients
879may definitely stick to it because they cannot flush the cookie, so they will
880not be able to access the service anymore. Specifying 'redispatch' will allow
881the proxy to break their persistence and redistribute them to working servers.
882
883Example :
884---------
885 listen http_proxy 0.0.0.0:80
886 mode http
887 cookie SERVERID
888 dispatch 192.168.1.100:80
889 server web1 192.168.1.1:80 cookie server01
890 server web2 192.168.1.2:80 cookie server02
891 redispatch # send back to dispatch in case of connection failure
892
893Up to, and including version 1.1.16, this parameter only applied to connection
894failures. Since version 1.1.17, it also applies to servers which have been
895detected as failed by the health check mechanism. Indeed, a server may be broken
896but still accepting connections, which would not solve every case. But it is
897possible to conserve the old behaviour, that is, make a client insist on trying
898to connect to a server even if it is said to be down, by setting the 'persist'
899option :
900
901 listen http_proxy 0.0.0.0:80
902 mode http
903 option persist
904 cookie SERVERID
905 dispatch 192.168.1.100:80
906 server web1 192.168.1.1:80 cookie server01
907 server web2 192.168.1.2:80 cookie server02
908 redispatch # send back to dispatch in case of connection failure
909
910
9114) Additionnal features
912=======================
913
914Other features are available. They are transparent mode, event logging and
915header rewriting/filtering.
916
willy tarreau0174f312005-12-18 01:02:42 +01009174.1) Network features
willy tarreaueedaa9f2005-12-17 14:08:03 +0100918---------------------
willy tarreau0174f312005-12-18 01:02:42 +01009194.1.1) Transparent mode
920-----------------------
willy tarreaueedaa9f2005-12-17 14:08:03 +0100921In HTTP mode, the 'transparent' keyword allows to intercept sessions which are
922routed through the system hosting the proxy. This mode was implemented as a
923replacement for the 'dispatch' mode, since connections without cookie will be
924sent to the original address while known cookies will be sent to the servers.
925This mode implies that the system can redirect sessions to a local port.
926
927Example :
928---------
929 listen http_proxy 0.0.0.0:65000
930 mode http
931 transparent
932 cookie SERVERID
933 server server01 192.168.1.1:80
934 server server02 192.168.1.2:80
935
936 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
937 --dport 80 -j REDIRECT --to-ports 65000
938
939Note :
940------
941If the port is left unspecified on the server, the port the client connected to
942will be used. This allows to relay a full port range without using transparent
943mode nor thousands of file descriptors, provided that the system can redirect
944sessions to local ports.
945
946Example :
947---------
948 # redirect all ports to local port 65000, then forward to the server on the
949 # original port.
950 listen http_proxy 0.0.0.0:65000
951 mode tcp
952 server server01 192.168.1.1 check port 60000
953 server server02 192.168.1.2 check port 60000
954
955 # iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.100 \
956 -j REDIRECT --to-ports 65000
957
willy tarreau0174f312005-12-18 01:02:42 +01009584.1.2) Per-server source address binding
959----------------------------------------
960As of versions 1.1.30 and 1.2.3, it is possible to specify a particular source
961to reach each server. This is useful when reaching backup servers from a
962different LAN, or to use an alternate path to reach the same server. It is also
963usable to provide source load-balancing for outgoing connections. Obviously,
964the same source address is used to send health-checks.
965
966Example :
967---------
968 # use a particular source to reach both servers
969 listen http_proxy 0.0.0.0:65000
970 mode http
971 balance roundrobin
972 server server01 192.168.1.1:80 source 192.168.2.13
973 server server02 192.168.1.2:80 source 192.168.2.13
974
975Example :
976---------
977 # use a particular source to reach each servers
978 listen http_proxy 0.0.0.0:65000
979 mode http
980 balance roundrobin
981 server server01 192.168.1.1:80 source 192.168.1.1
982 server server02 192.168.2.1:80 source 192.168.2.1
983
984Example :
985---------
986 # provide source load-balancing to reach the same proxy through 2 WAN links
987 listen http_proxy 0.0.0.0:65000
988 mode http
989 balance roundrobin
990 server remote-proxy-way1 192.168.1.1:3128 source 192.168.2.1
991 server remote-proxy-way2 192.168.1.1:3128 source 192.168.3.1
992
993Example :
994---------
995 # force a TCP connection to bind to a specific port
996 listen http_proxy 0.0.0.0:2000
997 mode tcp
998 balance roundrobin
999 server srv1 192.168.1.1:80 source 192.168.2.1:20
1000 server srv2 192.168.1.2:80 source 192.168.2.1:20
1001
willy tarreaueedaa9f2005-12-17 14:08:03 +01001002
10034.2) Event logging
1004------------------
willy tarreauc1cae632005-12-17 14:12:23 +010010054.2.1) Log levels
1006-----------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001007TCP and HTTP connections can be logged with informations such as date, time,
1008source IP address, destination address, connection duration, response times,
1009HTTP request, the HTTP return code, number of bytes transmitted, the conditions
1010in which the session ended, and even exchanged cookies values, to track a
1011particular user's problems for example. All messages are sent to up to two
1012syslog servers. Consult section 1.1 for more info about log facilities. The
1013syntax follows :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001014
willy tarreau197e8ec2005-12-17 14:10:59 +01001015 log <address_1> <facility_1> [max_level_1]
1016 log <address_2> <facility_2> [max_level_2]
1017or
willy tarreaueedaa9f2005-12-17 14:08:03 +01001018 log global
1019
willy tarreau197e8ec2005-12-17 14:10:59 +01001020Note :
1021------
1022The particular syntax 'log global' means that the same log configuration as the
1023'global' section will be used.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001024
willy tarreau197e8ec2005-12-17 14:10:59 +01001025Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001026---------
1027 listen http_proxy 0.0.0.0:80
1028 mode http
1029 log 192.168.2.200 local3
1030 log 192.168.2.201 local4
1031
willy tarreauc1cae632005-12-17 14:12:23 +010010324.2.2) Log format
1033-----------------
1034By default, connections are logged at the TCP level, as soon as the session
1035establishes between the client and the proxy. By enabling the 'tcplog' option,
1036the proxy will wait until the session ends to generate an enhanced log
1037containing more information such as session duration and its state during the
1038disconnection.
1039
willy tarreau982249e2005-12-18 00:57:06 +01001040Example :
1041---------
1042 listen relais-tcp 0.0.0.0:8000
1043 mode tcp
1044 option tcplog
1045 log 192.168.2.200 local3
1046
1047>>> haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28] relais-tcp Srv1 0/5007 0 --
1048
willy tarreauc1cae632005-12-17 14:12:23 +01001049Another option, 'httplog', provides more detailed information about HTTP
1050contents, such as the request and some cookies. In the event where an external
1051component would establish frequent connections to check the service, logs may be
1052full of useless lines. So it is possible not to log any session which didn't
1053transfer any data, by the setting of the 'dontlognull' option. This only has
1054effect on sessions which are established then closed.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001055
willy tarreau197e8ec2005-12-17 14:10:59 +01001056Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001057---------
1058 listen http_proxy 0.0.0.0:80
1059 mode http
1060 option httplog
1061 option dontlognull
1062 log 192.168.2.200 local3
1063
willy tarreau982249e2005-12-18 00:57:06 +01001064>>> haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57] relais-http Srv1 9/7/147/723 200 243 - - ---- "HEAD / HTTP/1.0"
1065
1066The problem when logging at end of connection is that you have no clue about
1067what is happening during very long sessions. To workaround this problem, a
1068new option 'logasap' has been introduced in 1.1.28/1.2.1. When specified, the
1069proxy will log as soon as possible, just before data transfer begins. This means
1070that in case of TCP, it will still log the connection status to the server, and
1071in case of HTTP, it will log just after processing the server headers. In this
1072case, the number of bytes reported is the number of header bytes sent to the
1073client.
1074
1075In order to avoid confusion with normal logs, the total time field and the
1076number of bytes are prefixed with a '+' sign which mean that real numbers are
1077certainly bigger.
1078
1079Example :
1080---------
1081
1082 listen http_proxy 0.0.0.0:80
1083 mode http
1084 option httplog
1085 option dontlognull
1086 option logasap
1087 log 192.168.2.200 local3
1088
1089>>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17] relais-http Srv1 9/7/14/+30 200 +243 - - ---- "GET /image.iso HTTP/1.0"
1090
1091
willy tarreauc1cae632005-12-17 14:12:23 +010010924.2.3) Timing events
1093--------------------
1094Timers provide a great help in trouble shooting network problems. All values
1095are reported in milliseconds (ms). In HTTP mode, four control points are
1096reported under the form 'Tq/Tc/Tr/Tt' :
1097
1098 - Tq: total time to get the client request.
1099 It's the time elapsed between the moment the client connection was accepted
1100 and the moment the proxy received the last HTTP header. The value '-1'
1101 indicates that the end of headers (empty line) has never been seen.
1102
1103 - Tc: total time to establish the TCP connection to the server.
1104 It's the time elapsed between the moment the proxy sent the connection
1105 request, and the moment it was acknowledged, or between the TCP SYN packet
1106 and the matching SYN/ACK in return. The value '-1' means that the
1107 connection never established.
1108
1109 - Tr: server response time. It's the time elapsed between the moment the
1110 TCP connection was established to the server and the moment it send its
1111 complete response header. It purely shows its request processing time,
1112 without the network overhead due to the data transmission. The value '-1'
1113 means that the last the response header (empty line) was never seen.
1114
1115 - Tt: total session duration time, between the moment the proxy accepted it
willy tarreau982249e2005-12-18 00:57:06 +01001116 and the moment both ends were closed. The exception is when the 'logasap'
1117 option is specified. In this case, it only equals (Tq+Tc+Tr), and is
1118 prefixed with a '+' sign. From this field, we can deduce Td, the data
1119 transmission time, by substracting other timers when valid :
willy tarreauc1cae632005-12-17 14:12:23 +01001120
1121 Td = Tt - (Tq + Tc + Tr)
1122
1123 Timers with '-1' values have to be excluded from this equation.
1124
1125In TCP mode ('option tcplog'), only Tc and Tt are reported.
1126
1127These timers provide precious indications on trouble causes. Since the TCP
1128protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure
1129that timers close to multiples of 3s are nearly always related to packets lost
1130due to network problems (wires or negociation). Moreover, if <Tt> is close to
1131a timeout value specified in the configuration, it often means that a session
1132has been aborted on time-out.
1133
1134Most common cases :
1135
1136 - If Tq is close to 3000, a packet has probably been lost between the client
1137 and the proxy.
1138 - If Tc is close to 3000, a packet has probably been lost between the server
1139 and the proxy during the server connection phase. This one should always be
1140 very low (less than a few tens).
1141 - If Tr is nearly always lower than 3000 except some rare values which seem to
1142 be the average majored by 3000, there are probably some packets lost between
1143 the proxy and the server.
1144 - If Tt is often slightly higher than a time-out, it's often because the
1145 client and the server use HTTP keep-alive and the session is maintained
1146 after the response ends. Se further for how to disable HTTP keep-alive.
1147
1148Other cases ('xx' means any value to be ignored) :
1149 -1/xx/xx/Tt : the client was not able to send its complete request in time,
1150 or that it aborted it too early.
1151 Tq/-1/xx/Tt : the connection could not establish on the server. Either it
1152 refused it or it timed out after Tt-Tq ms.
1153 Tq/Tc/-1/Tt : the server has accepted the connection but did not return a
1154 complete response in time, or it closed its connexion
1155 unexpectedly, after Tt-(Tq+Tc) ms.
1156
11574.2.4) Session state at disconnection
1158-------------------------------------
1159TCP and HTTP logs provide a session completion indicator. It's a 4-characters
1160(2 in TCP) field preceeding the HTTP request, and indicating :
willy tarreau197e8ec2005-12-17 14:10:59 +01001161 - On the first character, a code reporting the first event which caused the
1162 session to terminate :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001163
willy tarreau197e8ec2005-12-17 14:10:59 +01001164 C : the TCP session was aborted by the client.
1165 S : the TCP session was aborted by the server, or the server refused it.
1166 P : the session was abordted prematurely by the proxy, either because of
willy tarreau982249e2005-12-18 00:57:06 +01001167 an internal error, because a DENY filter was matched, or because of
1168 a security check which detected a dangerous error in server
1169 response.
willy tarreau197e8ec2005-12-17 14:10:59 +01001170 c : the client time-out expired first.
1171 s : the server time-out expired first.
1172 - : normal session completion.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001173
willy tarreau197e8ec2005-12-17 14:10:59 +01001174 - on the second character, the HTTP session state when it was closed :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001175
willy tarreau197e8ec2005-12-17 14:10:59 +01001176 R : waiting for complete REQUEST from the client
1177 C : waiting for CONNECTION to establish on the server
willy tarreau982249e2005-12-18 00:57:06 +01001178 H : processing server HEADERS
willy tarreau197e8ec2005-12-17 14:10:59 +01001179 D : the session was in the DATA phase
1180 L : the proxy was still transmitting LAST data to the client while the
1181 server had already finished.
1182 - : normal session completion after end of data transfer.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001183
willy tarreau197e8ec2005-12-17 14:10:59 +01001184 - the third character tells whether the persistence cookie was provided by
willy tarreauc1cae632005-12-17 14:12:23 +01001185 the client (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001186
willy tarreau197e8ec2005-12-17 14:10:59 +01001187 N : the client provided NO cookie.
1188 I : the client provided an INVALID cookie matching no known server.
1189 D : the client provided a cookie designating a server which was DOWN,
1190 so either the 'persist' option was used and the client was sent to
1191 this server, or it was not set and the client was redispatched to
1192 another server.
1193 V : the client provided a valid cookie, and was sent to the associated
1194 server.
1195 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001196
willy tarreau197e8ec2005-12-17 14:10:59 +01001197 - the last character reports what operations were performed on the persistence
willy tarreauc1cae632005-12-17 14:12:23 +01001198 cookie returned by the server (only in HTTP mode) :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001199
willy tarreau197e8ec2005-12-17 14:10:59 +01001200 N : NO cookie was provided by the server.
1201 P : a cookie was PROVIDED by the server and transmitted as-is.
1202 I : no cookie was provided by the server, and one was INSERTED by the
willy tarreaueedaa9f2005-12-17 14:08:03 +01001203 proxy.
willy tarreau197e8ec2005-12-17 14:10:59 +01001204 D : the cookie provided by the server was DELETED by the proxy.
1205 R : the cookie provided by the server was REWRITTEN by the proxy.
1206 - : does not apply (no cookie set in configuration).
willy tarreaueedaa9f2005-12-17 14:08:03 +01001207
willy tarreau197e8ec2005-12-17 14:10:59 +01001208The 'capture' keyword allows to capture and log informations exchanged between
1209clients and servers. As of version 1.1.23, only cookies can be captured, which
1210makes it easy to track a complete user session. The syntax is :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001211
willy tarreau197e8ec2005-12-17 14:10:59 +01001212 capture cookie <cookie_prefix> len <capture_length>
willy tarreaueedaa9f2005-12-17 14:08:03 +01001213
willy tarreau197e8ec2005-12-17 14:10:59 +01001214The FIRST cookie whose name starts with <cookie_prefix> will be captured, and
1215logged as 'NAME=value', without exceeding <capture_length> characters (64 max).
1216When the cookie name is fixed and known, it's preferable to suffix '=' to it to
1217ensure that no other cookie will be logged.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001218
willy tarreau197e8ec2005-12-17 14:10:59 +01001219Examples :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001220----------
willy tarreau197e8ec2005-12-17 14:10:59 +01001221 # capture the first cookie whose name starts with "ASPSESSION"
willy tarreaueedaa9f2005-12-17 14:08:03 +01001222 capture cookie ASPSESSION len 32
1223
willy tarreau197e8ec2005-12-17 14:10:59 +01001224 # capture the first cookie whose name is exactly "vgnvisitor"
willy tarreaueedaa9f2005-12-17 14:08:03 +01001225 capture cookie vgnvisitor= len 32
1226
willy tarreau197e8ec2005-12-17 14:10:59 +01001227In the logs, the field preceeding the completion indicator contains the cookie
1228value as sent by the server, preceeded by the cookie value as sent by the
1229client. Each of these field is replaced with '-' when no cookie was seen.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001230
willy tarreauc1cae632005-12-17 14:12:23 +010012314.2.5) Examples of logs
1232-----------------------
1233- haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57] relais-http Srv1 6559/7/147/6723 200 243 - - ---- "HEAD / HTTP/1.0"
1234 => long request (6.5s) entered by hand through 'telnet'. The server replied
1235 in 147 ms, and the session ended normally ('----')
willy tarreaueedaa9f2005-12-17 14:08:03 +01001236
willy tarreau982249e2005-12-18 00:57:06 +01001237- haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17] relais-http Srv1 9/7/14/+30 200 +243 - - ---- "GET /image.iso HTTP/1.0"
1238 => request for a long data transfer. The 'logasap' option was specified, so
1239 the log was produced just before transfering data. The server replied in
1240 14 ms, 243 bytes of headers were sent to the client, and total time from
1241 accept to first data byte is 30 ms.
1242
1243- haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17] relais-http Srv1 9/7/14/30 502 243 - - PH-- "GET /cgi-bin/bug.cgi? HTTP/1.0"
1244 => the proxy blocked a server response either because of an 'rspdeny' or
1245 'rspideny' filter, or because it blocked sensible information which risked
1246 being cached. In this case, the response is replaced with a '502 bad
1247 gateway'.
1248
willy tarreauc1cae632005-12-17 14:12:23 +01001249- haproxy[18113]: 127.0.0.1:34548 [15/Oct/2003:15:18:55] relais-http <NOSRV> -1/-1/-1/8490 -1 0 - - CR-- ""
1250 => the client never completed its request and aborted itself ('C---') after
1251 8.5s, while the proxy was waiting for the request headers ('-R--').
1252 Nothing was sent to the server.
1253
1254- haproxy[18113]: 127.0.0.1:34549 [15/Oct/2003:15:19:06] relais-http <NOSRV> -1/-1/-1/50001 408 0 - - cR-- ""
1255 => The client never completed its request, which was aborted by the time-out
1256 ('c---') after 50s, while the proxy was waiting for the request headers ('-R--').
1257 Nothing was sent to the server, but the proxy could send a 408 return code
1258 to the client.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001259
willy tarreauc1cae632005-12-17 14:12:23 +01001260- haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28] relais-tcp Srv1 0/5007 0 cD
1261 => This is a 'tcplog' entry. Client-side time-out ('c----') occured after 5s.
1262
1263- haproxy[18989]: 10.0.0.1:34552 [15/Oct/2003:15:26:31] relais-http Srv1 3183/-1/-1/11215 503 0 - - SC-- "HEAD / HTTP/1.0"
1264 => The request took 3s to complete (probably a network problem), and the
1265 connection to the server failed ('SC--') after 4 attemps of 2 seconds
1266 (config says 'retries 3'), then a 503 error code was sent to the client.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001267
willy tarreau4302f492005-12-18 01:00:37 +010012684.2.6) Non-printable characters
1269-------------------------------
1270As of version 1.1.29, non-printable characters are not sent as-is into log
1271files, but are converted to their two-digits hexadecimal representation,
1272prefixed by the character '#'. The only characters that can now be logged
1273without being escaped are between 32 and 126 (inclusive). Obviously, the
1274escape character '#' is also encoded to avoid any ambiguity. It is the same for
1275the character '"', as well as '{', '|' and '}' when logging headers.
1276
12774.2.7) Logging HTTP headers
1278---------------------------
1279As of version 1.1.29, it is now possible to log HTTP headers extracts. It is
1280both possible to include request headers and response headers. It is
1281particularly useful to know what virtual server the client requested, to know
1282the content length during a POST request, or a unique request ID set on a
1283previous proxy. In the response, one can search for information about the
1284response length, how the server asked the cache to behave, or an object location
1285during a redirection. The syntax is :
1286
1287 capture request header <name> len <max length>
1288 capture response header <name> len <max length>
1289
1290Note: Header names are not case-sensitive.
1291
1292Examples:
1293---------
1294 # keep the name of the virtual server
1295 capture request header Host len 20
1296 # keep the amount of data uploaded during a POST
1297 capture request header Content-Length len 10
1298
1299 # note the expected cache behaviour on the response
1300 capture response header Cache-Control len 8
1301 # note the URL location during a redirection
1302 capture response header Location len 20
1303
1304Non-existant headers are logged as empty strings, and if one header appears more
1305than once, only its last occurence will be kept. Request headers are grouped
1306within braces '{' and '}' in the same order as they were declared, and delimited
1307with a vertical bar '|' without any space. Response headers follow the same
1308representation, but are displayed after a space following the request headers
1309block. These blocks are displayed just before the HTTP request in the logs.
1310Example :
1311
1312Config:
1313
1314 capture request header Host len 20
1315 capture request header Content-Length len 10
1316 capture request header Referer len 20
1317 capture response header Server len 20
1318 capture response header Content-Length len 10
1319 capture response header Cache-Control len 8
1320 capture response header Via len 20
1321 capture response header Location len 20
1322
1323Log :
1324
1325Aug 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/"
1326Aug 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"
1327Aug 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"
1328
willy tarreau197e8ec2005-12-17 14:10:59 +010013294.3) HTTP header manipulation
1330-----------------------------
1331In HTTP mode, it is possible to rewrite, add or delete some of the request and
1332response headers based on regular expressions. It is also possible to block a
1333request or a response if a particular header matches a regular expression,
1334which is enough to stops most elementary protocol attacks, and to protect
1335against information leak from the internal network. But there is a limitation
1336to this : since haproxy's HTTP engine knows nothing about keep-alive, only
1337headers passed during the first request of a TCP session will be seen. All
1338subsequent headers will be considered data only and not analyzed. Furthermore,
1339haproxy doesn't touch data contents, it stops at the end of headers.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001340
willy tarreau197e8ec2005-12-17 14:10:59 +01001341The syntax is :
1342 reqadd <string> to add a header to the request
1343 reqrep <search> <replace> to modify the request
1344 reqirep <search> <replace> same, but ignoring the case
1345 reqdel <search> to delete a header in the request
1346 reqidel <search> same, but ignoring the case
1347 reqallow <search> definitely allow a request if a header matches <search>
1348 reqiallow <search> same, but ignoring the case
1349 reqdeny <search> denies a request if a header matches <search>
1350 reqideny <search> same, but ignoring the case
1351 reqpass <search> ignore a header matching <search>
1352 reqipass <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01001353
willy tarreau197e8ec2005-12-17 14:10:59 +01001354 rspadd <string> to add a header to the response
1355 rsprep <search> <replace> to modify the response
1356 rspirep <search> <replace> same, but ignoring the case
1357 rspdel <search> to delete the response
1358 rspidel <search> same, but ignoring the case
willy tarreau982249e2005-12-18 00:57:06 +01001359 rspdeny <search> replaces a response with a HTTP 502 if a header matches <search>
1360 rspideny <search> same, but ignoring the case
willy tarreaueedaa9f2005-12-17 14:08:03 +01001361
1362
willy tarreau197e8ec2005-12-17 14:10:59 +01001363<search> is a POSIX regular expression (regex) which supports grouping through
1364parenthesis (without the backslash). Spaces and other delimiters must be
1365prefixed with a backslash ('\') to avoid confusion with a field delimiter.
1366Other characters may be prefixed with a backslash to change their meaning :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001367
willy tarreau197e8ec2005-12-17 14:10:59 +01001368 \t for a tab
1369 \r for a carriage return (CR)
1370 \n for a new line (LF)
1371 \ to mark a space and differentiate it from a delimiter
1372 \# to mark a sharp and differentiate it from a comment
1373 \\ to use a backslash in a regex
1374 \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy)
1375 \xXX to write the ASCII hex code XX as in the C language
willy tarreaueedaa9f2005-12-17 14:08:03 +01001376
1377
willy tarreau197e8ec2005-12-17 14:10:59 +01001378<replace> containst the string to be used to replace the largest portion of text
1379matching the regex. It can make use of the special characters above, and can
1380reference a substring delimited by parenthesis in the regex, by the group
1381numerical order from 1 to 9. In this case, you would write a backslah ('\')
1382immediately followed by one digit indicating the group position.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001383
willy tarreau197e8ec2005-12-17 14:10:59 +01001384<string> represents the string which will systematically be added after the last
1385header line. It can also use special characters above.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001386
willy tarreau197e8ec2005-12-17 14:10:59 +01001387Notes :
1388-------
1389 - the first line is considered as a header, which makes it possible to rewrite
1390 or filter HTTP requests URIs or response codes.
1391 - 'reqrep' is the equivalent of 'cliexp' in version 1.0, and 'rsprep' is the
1392 equivalent of 'srvexp' in 1.0. Those names are still supported but
1393 deprecated.
1394 - for performances reasons, the number of characters added to a request or to
1395 a response is limited to 4096 since version 1.1.5 (it was 256 before). This
1396 value is easy to modify in the code if needed (#define). If it is too short
1397 on occasional uses, it is possible to gain some space by removing some
1398 useless headers before adding new ones.
willy tarreau982249e2005-12-18 00:57:06 +01001399 - a denied request will generate an "HTTP 403 forbidden" response, while a
1400 denied response will generate an "HTTP 502 Bad gateway" response.
1401
willy tarreaueedaa9f2005-12-17 14:08:03 +01001402
willy tarreau197e8ec2005-12-17 14:10:59 +01001403Examples :
1404----------
1405 ###### a few examples ######
1406
1407 # rewrite 'online.fr' instead of 'free.fr' for GET and POST requests
1408 reqrep ^(GET\ .*)(.free.fr)(.*) \1.online.fr\3
1409 reqrep ^(POST\ .*)(.free.fr)(.*) \1.online.fr\3
1410
1411 # force proxy connections to close
willy tarreaueedaa9f2005-12-17 14:08:03 +01001412 reqirep ^Proxy-Connection:.* Proxy-Connection:\ close
willy tarreau197e8ec2005-12-17 14:10:59 +01001413 # rewrite locations
willy tarreaueedaa9f2005-12-17 14:08:03 +01001414 rspirep ^(Location:\ )([^:]*://[^/]*)(.*) \1\3
willy tarreaueedaa9f2005-12-17 14:08:03 +01001415
willy tarreau197e8ec2005-12-17 14:10:59 +01001416 ###### A full configuration being used on production ######
willy tarreaueedaa9f2005-12-17 14:08:03 +01001417
willy tarreau197e8ec2005-12-17 14:10:59 +01001418 # Every header should end with a colon followed by one space.
1419 reqideny ^[^:\ ]*[\ ]*$
willy tarreaueedaa9f2005-12-17 14:08:03 +01001420
willy tarreau197e8ec2005-12-17 14:10:59 +01001421 # block Apache chunk exploit
1422 reqideny ^Transfer-Encoding:[\ ]*chunked
1423 reqideny ^Host:\ apache-
willy tarreaueedaa9f2005-12-17 14:08:03 +01001424
willy tarreau197e8ec2005-12-17 14:10:59 +01001425 # block annoying worms that fill the logs...
1426 reqideny ^[^:\ ]*\ .*(\.|%2e)(\.|%2e)(%2f|%5c|/|\\\\)
1427 reqideny ^[^:\ ]*\ ([^\ ]*\ [^\ ]*\ |.*%00)
1428 reqideny ^[^:\ ]*\ .*<script
1429 reqideny ^[^:\ ]*\ .*/(root\.exe\?|cmd\.exe\?|default\.ida\?)
1430
1431 # allow other syntactically valid requests, and block any other method
1432 reqipass ^(GET|POST|HEAD|OPTIONS)\ /.*\ HTTP/1\.[01]$
1433 reqipass ^OPTIONS\ \\*\ HTTP/1\.[01]$
1434 reqideny ^[^:\ ]*\
1435
1436 # force connection:close, thus disabling HTTP keep-alive
willy tarreau982249e2005-12-18 00:57:06 +01001437 option httpclose
willy tarreau197e8ec2005-12-17 14:10:59 +01001438
1439 # change the server name
1440 rspidel ^Server:\
1441 rspadd Server:\ Formilux/0.1.8
1442
1443
willy tarreau982249e2005-12-18 00:57:06 +01001444Also, the 'forwardfor' option creates an HTTP 'X-Forwarded-For' header which
willy tarreauc1cae632005-12-17 14:12:23 +01001445contains the client's IP address. This is useful to let the final web server
1446know what the client address was (eg for statistics on domains).
1447
willy tarreau982249e2005-12-18 00:57:06 +01001448Last, the 'httpclose' option removes any 'Connection' header both ways, and
1449adds a 'Connection: close' header in each direction. This makes it easier to
1450disable HTTP keep-alive than the previous 4-rules block..
1451
willy tarreauc1cae632005-12-17 14:12:23 +01001452Example :
1453---------
1454 listen http_proxy 0.0.0.0:80
1455 mode http
1456 log global
1457 option httplog
1458 option dontlognull
1459 option forwardfor
willy tarreau982249e2005-12-18 00:57:06 +01001460 option httpclose
willy tarreau197e8ec2005-12-17 14:10:59 +01001461
14624.4) Load balancing with persistence
1463------------------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001464Combining cookie insertion with internal load balancing allows to transparently
1465bring persistence to applications. The principle is quite simple :
1466 - assign a cookie value to each server
1467 - enable the load balancing between servers
1468 - insert a cookie into responses resulting from the balancing algorithm
1469 (indirect accesses), end ensure that no upstream proxy will cache it.
1470 - remove the cookie in the request headers so that the application never sees
1471 it.
1472
1473Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001474---------
1475 listen application 0.0.0.0:80
1476 mode http
1477 cookie SERVERID insert nocache indirect
1478 balance roundrobin
willy tarreau598da412005-12-18 01:07:29 +01001479 server srv1 192.168.1.1:80 cookie server01 check
1480 server srv2 192.168.1.2:80 cookie server02 check
willy tarreaueedaa9f2005-12-17 14:08:03 +01001481
willy tarreau0174f312005-12-18 01:02:42 +01001482The other solution brought by versions 1.1.30 and 1.2.3 is to reuse a cookie
1483from the server, and prefix the server's name to it. In this case, don't forget
1484to force "httpclose" mode so that you can be assured that every subsequent
1485request will have its cookie fixed.
1486
1487 listen application 0.0.0.0:80
1488 mode http
1489 cookie JSESSIONID prefix
1490 balance roundrobin
willy tarreau598da412005-12-18 01:07:29 +01001491 server srv1 192.168.1.1:80 cookie srv1 check
1492 server srv2 192.168.1.2:80 cookie srv2 check
willy tarreau0174f312005-12-18 01:02:42 +01001493 option httpclose
1494
1495
willy tarreau982249e2005-12-18 00:57:06 +010014964.5) Protection against information leak from the servers
1497---------------------------------------------------------
1498In versions 1.1.28/1.2.1, a new option 'checkcache' was created. It carefully
1499checks 'Cache-control', 'Pragma' and 'Set-cookie' headers in server response
1500to check if there's a risk of caching a cookie on a client-side proxy. When this
1501option is enabled, the only responses which can be delivered to the client are :
1502 - all those without 'Set-Cookie' header ;
1503 - all those with a return code other than 200, 203, 206, 300, 301, 410,
1504 provided that the server has not set a 'Cache-control: public' header ;
1505 - all those that come from a POST request, provided that the server has not
1506 set a 'Cache-Control: public' header ;
1507 - those with a 'Pragma: no-cache' header
1508 - those with a 'Cache-control: private' header
1509 - those with a 'Cache-control: no-store' header
1510 - those with a 'Cache-control: max-age=0' header
1511 - those with a 'Cache-control: s-maxage=0' header
1512 - those with a 'Cache-control: no-cache' header
1513 - those with a 'Cache-control: no-cache="set-cookie"' header
1514 - those with a 'Cache-control: no-cache="set-cookie,' header
1515 (allowing other fields after set-cookie)
willy tarreaueedaa9f2005-12-17 14:08:03 +01001516
willy tarreau982249e2005-12-18 00:57:06 +01001517If a response doesn't respect these requirements, then it will be blocked just
1518as if it was from an 'rspdeny' filter, with an "HTTP 502 bad gateway". The
1519session state shows "PH--" meaning that the proxy blocked the response during
1520headers processing. Additionnaly, an alert will be sent in the logs so that
1521admins are told that there's something to be done.
1522
15234.6) Customizing errors
1524-----------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001525Some situations can make haproxy return an HTTP error code to the client :
1526 - invalid or too long request => HTTP 400
1527 - request not completely sent in time => HTTP 408
1528 - forbidden request (matches a deny filter) => HTTP 403
1529 - internal error in haproxy => HTTP 500
1530 - the server returned an invalid or incomplete response => HTTP 502
1531 - no server was available to handle the request => HTTP 503
1532 - the server failed to reply in time => HTTP 504
willy tarreaueedaa9f2005-12-17 14:08:03 +01001533
willy tarreau197e8ec2005-12-17 14:10:59 +01001534A succint error message taken from the RFC accompanies these return codes.
1535But depending on the clients knowledge, it may be better to return custom, user
1536friendly, error pages. This is made possible through the use of the 'errorloc'
1537command :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001538
willy tarreau197e8ec2005-12-17 14:10:59 +01001539 errorloc <HTTP_code> <location>
willy tarreaueedaa9f2005-12-17 14:08:03 +01001540
willy tarreau197e8ec2005-12-17 14:10:59 +01001541Instead of generating an HTTP error <HTTP_code> among those above, the proxy
1542will return a temporary redirection code (HTTP 302) towards the address
1543specified in <location>. This address may be either relative to the site or
1544absolute. Since this request will be handled by the client's browser, it's
1545mandatory that the returned address be reachable from the outside.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001546
willy tarreau197e8ec2005-12-17 14:10:59 +01001547Example :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001548---------
1549 listen application 0.0.0.0:80
1550 errorloc 400 /badrequest.html
1551 errorloc 403 /forbidden.html
1552 errorloc 408 /toolong.html
1553 errorloc 500 http://haproxy.domain.net/bugreport.html
1554 errorloc 502 http://192.168.114.58/error50x.html
1555 errorloc 503 http://192.168.114.58/error50x.html
1556 errorloc 504 http://192.168.114.58/error50x.html
1557
willy tarreauc1f47532005-12-18 01:08:26 +01001558Note: RFC2616 says that a client must reuse the same method to fetch the
1559Location returned by a 302, which causes problems with the POST method.
1560The return code 303 was designed explicitly to force the client to fetch the
1561Location URL with the GET method, but there are some browsers pre-dating
1562HTTP/1.1 which don't support it. Anyway, most browsers still behave with 302 as
1563if it was a 303. In order to allow the user to chose, version 1.2.5 brings two
1564new keywords to replace 'errorloc' : 'errorloc302' and 'errorloc303'.
1565
1566They are preffered over errorloc (which still does 302). Consider using
1567errorloc303 everytime you know that your clients support HTTP 303 responses..
1568
1569
willy tarreau982249e2005-12-18 00:57:06 +010015704.7) Modifying default values
willy tarreau197e8ec2005-12-17 14:10:59 +01001571-----------------------------
willy tarreau197e8ec2005-12-17 14:10:59 +01001572Version 1.1.22 introduced the notion of default values, which eliminates the
1573pain of often repeating common parameters between many instances, such as
1574logs, timeouts, modes, etc...
willy tarreaueedaa9f2005-12-17 14:08:03 +01001575
willy tarreau197e8ec2005-12-17 14:10:59 +01001576Default values are set in a 'defaults' section. Each of these section clears
1577all previously set default parameters, so there may be as many default
1578parameters as needed. Only the last one before a 'listen' section will be
1579used for this section. The 'defaults' section uses the same syntax as the
1580'listen' section, for the supported parameters. The 'defaults' keyword ignores
1581everything on its command line, so that fake instance names can be specified
1582there for better clarity.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001583
willy tarreau982249e2005-12-18 00:57:06 +01001584In version 1.1.28/1.2.1, only those parameters can be preset in the 'default'
willy tarreau197e8ec2005-12-17 14:10:59 +01001585section :
1586 - log (the first and second one)
willy tarreaueedaa9f2005-12-17 14:08:03 +01001587 - mode { tcp, http, health }
1588 - balance { roundrobin }
willy tarreau197e8ec2005-12-17 14:10:59 +01001589 - disabled (to disable every further instances)
1590 - enabled (to enable every further instances, this is the default)
willy tarreaueedaa9f2005-12-17 14:08:03 +01001591 - contimeout, clitimeout, srvtimeout, grace, retries, maxconn
willy tarreau982249e2005-12-18 00:57:06 +01001592 - option { redispatch, transparent, keepalive, forwardfor, logasap, httpclose,
1593 checkcache, httplog, tcplog, dontlognull, persist, httpchk }
willy tarreaueedaa9f2005-12-17 14:08:03 +01001594 - redispatch, redisp, transparent, source { addr:port }
1595 - cookie, capture
1596 - errorloc
1597
willy tarreau197e8ec2005-12-17 14:10:59 +01001598As of 1.1.24, it is not possible to put certain parameters in a 'defaults'
1599section, mainly regular expressions and server configurations :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001600 - dispatch, server,
willy tarreau197e8ec2005-12-17 14:10:59 +01001601 - req*, rsp*
willy tarreaueedaa9f2005-12-17 14:08:03 +01001602
willy tarreau197e8ec2005-12-17 14:10:59 +01001603Last, there's no way yet to change a boolean option from its assigned default
1604value. So if an 'option' statement is set in a 'defaults' section, the only
1605way to flush it is to redefine a new 'defaults' section without this 'option'.
willy tarreaueedaa9f2005-12-17 14:08:03 +01001606
willy tarreau197e8ec2005-12-17 14:10:59 +01001607Examples :
willy tarreaueedaa9f2005-12-17 14:08:03 +01001608----------
1609 defaults applications TCP
1610 log global
1611 mode tcp
1612 balance roundrobin
1613 clitimeout 180000
1614 srvtimeout 180000
1615 contimeout 4000
1616 retries 3
1617 redispatch
1618
1619 listen app_tcp1 10.0.0.1:6000-6063
1620 server srv1 192.168.1.1 check port 6000 inter 10000
1621 server srv2 192.168.1.2 backup
1622
1623 listen app_tcp2 10.0.0.2:6000-6063
1624 server srv1 192.168.2.1 check port 6000 inter 10000
1625 server srv2 192.168.2.2 backup
1626
1627 defaults applications HTTP
1628 log global
1629 mode http
1630 option httplog
1631 option forwardfor
1632 option dontlognull
1633 balance roundrobin
1634 clitimeout 20000
1635 srvtimeout 20000
1636 contimeout 4000
1637 retries 3
1638
1639 listen app_http1 10.0.0.1:80-81
1640 cookie SERVERID postonly insert indirect
1641 capture cookie userid= len 10
1642 server srv1 192.168.1.1:+8000 cookie srv1 check port 8080 inter 1000
1643 server srv1 192.168.1.2:+8000 cookie srv2 check port 8080 inter 1000
1644
1645 defaults
willy tarreau197e8ec2005-12-17 14:10:59 +01001646 # this empty section voids all default parameters
willy tarreaueedaa9f2005-12-17 14:08:03 +01001647
willy tarreau197e8ec2005-12-17 14:10:59 +01001648=========================
1649| System-specific setup |
1650=========================
willy tarreaueedaa9f2005-12-17 14:08:03 +01001651
willy tarreau197e8ec2005-12-17 14:10:59 +01001652Linux 2.4
1653=========
willy tarreaueedaa9f2005-12-17 14:08:03 +01001654
1655-- cut here --
1656#!/bin/sh
1657# set this to about 256/4M (16384 for 256M machine)
1658MAXFILES=16384
1659echo $MAXFILES > /proc/sys/fs/file-max
1660ulimit -n $MAXFILES
1661
1662if [ -e /proc/sys/net/ipv4/ip_conntrack_max ]; then
1663 echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max
1664fi
1665
1666if [ -e /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait ]; then
1667 # 30 seconds for fin, 15 for time wait
1668 echo 3000 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_fin_wait
1669 echo 1500 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_timeout_time_wait
1670 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_invalid_scale
1671 echo 0 > /proc/sys/net/ipv4/netfilter/ip_ct_tcp_log_out_of_window
1672fi
1673
1674echo 1024 60999 > /proc/sys/net/ipv4/ip_local_port_range
1675echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
1676echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog
1677echo 262144 > /proc/sys/net/ipv4/tcp_max_tw_buckets
1678echo 262144 > /proc/sys/net/ipv4/tcp_max_orphans
1679echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time
1680echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
1681echo 0 > /proc/sys/net/ipv4/tcp_timestamps
1682echo 0 > /proc/sys/net/ipv4/tcp_ecn
1683echo 0 > /proc/sys/net/ipv4/tcp_sack
1684echo 0 > /proc/sys/net/ipv4/tcp_dsack
1685
1686# auto-tuned on 2.4
1687#echo 262143 > /proc/sys/net/core/rmem_max
1688#echo 262143 > /proc/sys/net/core/rmem_default
1689
1690echo 16384 65536 524288 > /proc/sys/net/ipv4/tcp_rmem
1691echo 16384 349520 699040 > /proc/sys/net/ipv4/tcp_wmem
1692
1693-- cut here --
1694
willy tarreau197e8ec2005-12-17 14:10:59 +01001695
1696FreeBSD
1697=======
1698
1699A FreeBSD port of HA-Proxy is now available and maintained, thanks to
1700Clement Laforet <sheepkiller@cultdeadsheep.org>.
1701
1702For more information :
1703http://www.freebsd.org/cgi/url.cgi?ports/net/haproxy/pkg-descr
1704http://www.freebsd.org/cgi/cvsweb.cgi/ports/net/haproxy/
1705http://www.freshports.org/net/haproxy
1706
1707
1708-- end --