blob: 3d3d86b1676044b6551b4f704a498789685c2ae1 [file] [log] [blame]
Willy Tarreau6bbf14c2006-07-09 09:08:05 +02001#
2# This configuration can be used as an example of how URL-switching may be
3# implemented with current haproxy versions.
4#
5# Right now (version 1.2), haproxy can only select a server based on the cookie
6# provided by the client. While this may sound limitated, it is yet possible to
7# combine this feature to rewrites to provide full URL-switching capabilities.
8#
9# For this, we have to chain 3 levels :
10# - front-end : will match the expected URIs and assign a cookie accordingly ;
11# it uses regexps and could match on anything else (Host:,
12# cookies, ...)
13# - switch : will select a back-end depending on the cookie above
14# - back-ends : will perform the load balancing between multiple servers for
15# the same group. Note that this level can be omitted if there
16# is only one server for each backend.
17#
18# Logging is performed at the lower level (back-ends) so that local server
19# problems can be identified quickly with the timers. The client's IP is
20# propagated in the X-Forwarded-For: header.
21#
22
23global
24 daemon
25 maxconn 6000 # warning: this has to be 3 times the expected value!
26 log 192.168.0.1 local0
27
28defaults
29 mode http
30 balance roundrobin
31 option dontlognull
32 option httpclose
33 retries 1
34 redispatch
35 maxconn 2000
36 contimeout 5000
37 clitimeout 50000
38 srvtimeout 50000
39
40#
41# This is the instance the client connects to.
42#
43listen frontend 10.20.30.40:80
44 option forwardfor # add 'X-Forwarded-For: IP'
45
46 # remove an eventual 'backend' cookie the client might have sent
47 reqidel ^Cookie:\ backend=
48
49 # add cookie 'backend=2' for any HTTP method followed by
50 # '/img' only or '/img/' followed by anything.
51 reqirep ^[^:\ ]*\ /img[/\ ].* \0\nCookie:\ backend=2
52
53 # add cookie 'backend=3' for any HTTP method followed by
54 # '/home' only or '/home/' followed by anything.
55 reqirep ^[^:\ ]*\ /home[/\ ].* \0\nCookie:\ backend=3
56
57 # send everything to next stage
58 server switch 127.0.0.2:8000
59
60
61#
62# This instance is only seen by the 'frontend' instance above. It receives all
63# of its traffic.
64#
65listen switch 127.0.0.2:8000
66 # cookie name 'backend' inserted by the 'frontend' instance above
67 cookie backend
68
69 # default server 'backend1' gets the default traffic.
70 server backend1 127.0.0.3:8001
71
72 # those servers get traffic only if their cookie is present because
73 # they are tagged 'backup'.
74 server backend2 127.0.0.3:8002 cookie 2 backup
75 server backend3 127.0.0.3:8003 cookie 3 backup
76
77#
78# Backend 1 for dynamic contents.
79# It is made of 4 apache servers which we can test thanks to a CGI script.
80#
81listen backend1 127.0.0.3:8001
82 log global
83 option httplog
84 capture request header X-Forwarded-For len 15
85 option httpchk /cgi-bin/testhost.pl
86 server apache1 192.168.1.1:80 maxconn 100 check inter 2000 fall 3
87 server apache2 192.168.1.2:80 maxconn 100 check inter 2000 fall 3
88 server apache3 192.168.1.3:80 maxconn 100 check inter 2000 fall 3
89 server apache4 192.168.1.4:80 maxconn 100 check inter 2000 fall 3
90
91#
92# backend 2 for images (/img).
93# It is made of 3 Tux servers which we test by requesting the /img/logo.png
94# file which should be present when file-systems are mounted.
95#
96listen backend2 127.0.0.3:8002
97 log global
98 option httplog
99 capture request header X-Forwarded-For len 15
100 option httpchk /img/logo.png
101 server tux5 192.168.1.5:80 check inter 2000 fall 3
102 server tux6 192.168.1.6:80 check inter 2000 fall 3
103 server tux7 192.168.1.7:80 check inter 2000 fall 3
104
105#
106# backend 3 for home directories (/home). These are the same machines as for
107# dynamic content, except that a different server is bound to another port.
108# We test the service by checking that the file "/home/webmaster/started"
109# exists.
110#
111listen backend3 127.0.0.3:8003
112 log global
113 option httplog
114 capture request header X-Forwarded-For len 15
115 option httpchk /home/webmaster/started
116 server light1 192.168.1.1:8080 check inter 2000 fall 3
117 server light2 192.168.1.2:8080 check inter 2000 fall 3
118 server light3 192.168.1.3:8080 check inter 2000 fall 3
119 server light4 192.168.1.4:8080 check inter 2000 fall 3
120