]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[DOC] provided an example of configuration involving URL switching.
authorWilly Tarreau <w@1wt.eu>
Sun, 9 Jul 2006 07:08:05 +0000 (09:08 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 9 Jul 2006 15:02:06 +0000 (17:02 +0200)
examples/haproxy-small.spec
examples/haproxy.spec
examples/url-switching.cfg [new file with mode: 0644]

index 14f278866a8ec5d38b55ccb65c7ba6cc42e57ab6..cde9b942b944cc57ebf5da6478ba6ab9cb9df2ee 100644 (file)
@@ -62,7 +62,7 @@ fi
 
 %files
 %defattr(-,root,root)
-%doc CHANGELOG TODO examples doc/haproxy-en.txt doc/haproxy-fr.txt doc/architecture.txt
+%doc CHANGELOG TODO examples doc/haproxy-en.txt doc/haproxy-fr.txt doc/architecture.txt examples/url-switching.cfg
 %attr(0755,root,root) %{_sbindir}/%{name}
 %dir %{_sysconfdir}/%{name}
 %attr(0644,root,root) %config(noreplace) %{_sysconfdir}/%{name}/%{name}.cfg
index 5dcb2e32171a67a44e372a4e81fb3f2a497f2e98..1a97b81495f59ed7c7b36cd85c0069be38ec7e64 100644 (file)
@@ -64,7 +64,7 @@ fi
 
 %files
 %defattr(-,root,root)
-%doc CHANGELOG TODO examples doc/haproxy-en.txt doc/haproxy-fr.txt doc/architecture.txt
+%doc CHANGELOG TODO examples doc/haproxy-en.txt doc/haproxy-fr.txt doc/architecture.txt examples/url-switching.cfg
 %attr(0755,root,root) %{_sbindir}/%{name}
 %dir %{_sysconfdir}/%{name}
 %attr(0644,root,root) %config(noreplace) %{_sysconfdir}/%{name}/%{name}.cfg
diff --git a/examples/url-switching.cfg b/examples/url-switching.cfg
new file mode 100644 (file)
index 0000000..3d3d86b
--- /dev/null
@@ -0,0 +1,120 @@
+#
+# This configuration can be used as an example of how URL-switching may be
+# implemented with current haproxy versions.
+#
+# Right now (version 1.2), haproxy can only select a server based on the cookie
+# provided by the client. While this may sound limitated, it is yet possible to
+# combine this feature to rewrites to provide full URL-switching capabilities.
+#
+# For this, we have to chain 3 levels :
+#  - front-end : will match the expected URIs and assign a cookie accordingly ;
+#                it uses regexps and could match on anything else (Host:,
+#                cookies, ...)
+#  - switch    : will select a back-end depending on the cookie above
+#  - back-ends : will perform the load balancing between multiple servers for
+#                the same group. Note that this level can be omitted if there
+#                is only one server for each backend.
+#
+# Logging is performed at the lower level (back-ends) so that local server
+# problems can be identified quickly with the timers. The client's IP is
+# propagated in the X-Forwarded-For: header.
+#
+
+global
+       daemon
+       maxconn 6000      # warning: this has to be 3 times the expected value!
+       log 192.168.0.1 local0
+
+defaults
+       mode    http
+       balance roundrobin
+       option  dontlognull
+       option  httpclose
+       retries 1
+       redispatch
+       maxconn         2000
+       contimeout      5000
+       clitimeout      50000
+       srvtimeout      50000
+
+#
+# This is the instance the client connects to.
+#
+listen frontend 10.20.30.40:80
+       option forwardfor               # add 'X-Forwarded-For: IP'
+
+       # remove an eventual 'backend' cookie the client might have sent
+       reqidel ^Cookie:\ backend=
+
+       # add cookie 'backend=2' for any HTTP method followed by
+       #  '/img' only or '/img/' followed by anything.
+       reqirep ^[^:\ ]*\ /img[/\ ].* \0\nCookie:\ backend=2
+
+       # add cookie 'backend=3' for any HTTP method followed by
+       #  '/home' only or '/home/' followed by anything.
+       reqirep ^[^:\ ]*\ /home[/\ ].*   \0\nCookie:\ backend=3
+
+       # send everything to next stage
+       server  switch 127.0.0.2:8000
+
+
+#
+# This instance is only seen by the 'frontend' instance above. It receives all
+# of its traffic.
+#
+listen switch 127.0.0.2:8000
+       # cookie name 'backend' inserted by the 'frontend' instance above
+       cookie backend
+
+       # default server 'backend1' gets the default traffic.
+       server backend1 127.0.0.3:8001
+
+       # those servers get traffic only if their cookie is present because
+       # they are tagged 'backup'.
+       server backend2 127.0.0.3:8002 cookie 2 backup
+       server backend3 127.0.0.3:8003 cookie 3 backup
+
+#
+# Backend 1 for dynamic contents.
+# It is made of 4 apache servers which we can test thanks to a CGI script.
+#
+listen backend1 127.0.0.3:8001
+       log     global
+       option  httplog
+       capture request header X-Forwarded-For len 15
+       option  httpchk /cgi-bin/testhost.pl
+       server  apache1 192.168.1.1:80 maxconn 100 check inter 2000 fall 3
+       server  apache2 192.168.1.2:80 maxconn 100 check inter 2000 fall 3
+       server  apache3 192.168.1.3:80 maxconn 100 check inter 2000 fall 3
+       server  apache4 192.168.1.4:80 maxconn 100 check inter 2000 fall 3
+
+#
+# backend 2 for images (/img).
+# It is made of 3 Tux servers which we test by requesting the /img/logo.png
+# file which should be present when file-systems are mounted.
+#
+listen backend2 127.0.0.3:8002
+       log     global
+       option  httplog
+       capture request header X-Forwarded-For len 15
+       option  httpchk /img/logo.png
+       server  tux5 192.168.1.5:80 check inter 2000 fall 3
+       server  tux6 192.168.1.6:80 check inter 2000 fall 3
+       server  tux7 192.168.1.7:80 check inter 2000 fall 3
+
+#
+# backend 3 for home directories (/home). These are the same machines as for
+# dynamic content, except that a different server is bound to another port.
+# We test the service by checking that the file "/home/webmaster/started"
+# exists.
+#
+listen backend3 127.0.0.3:8003
+       log     global
+       option  httplog
+       capture request header X-Forwarded-For len 15
+       option  httpchk /home/webmaster/started
+       server  light1 192.168.1.1:8080 check inter 2000 fall 3
+       server  light2 192.168.1.2:8080 check inter 2000 fall 3
+       server  light3 192.168.1.3:8080 check inter 2000 fall 3
+       server  light4 192.168.1.4:8080 check inter 2000 fall 3
+