[master] 7293eaf On virutal hosting in Varnis

Per Buer perbu at varnish-cache.org
Fri Aug 30 08:49:59 CEST 2013


commit 7293eaf9dc729ab2c2e5932ce18ca98b068431ef
Author: Per Buer <perbu at varnish-software.com>
Date:   Fri Aug 30 08:49:05 2013 +0200

    On virutal hosting in Varnis

diff --git a/doc/sphinx/tutorial/backend_servers.rst b/doc/sphinx/tutorial/backend_servers.rst
index 7ea3a20..ebc05ad 100644
--- a/doc/sphinx/tutorial/backend_servers.rst
+++ b/doc/sphinx/tutorial/backend_servers.rst
@@ -20,19 +20,23 @@ the configuration that looks like this:::
       .port = "80";
   }
 
+This means we set up a backend in Varnish that fetches content from
+the host www.varnish-cache.org on port 80. 
+
 Since you probably don't want to be mirroring varnish-cache.org we
 need to get Varnish to fetch content from your own origin
 server. We've already bound Varnish to the public port 80 on the
 server so now we need to tie it to the origin.
 
 For this example, let's pretend the origin server is running on
-localhost, port 8080.
+localhost, port 8080.::
 
           backend default {
                 .host = "127.0.0.1";
     		.port = "8080";
 	  }
 
+
 Varnish can have several backends defined and can you can even join
 several backends together into clusters of backends for load balancing
 purposes, having Varnish pick one backend based on different
diff --git a/doc/sphinx/users-guide/vcl-backends.rst b/doc/sphinx/users-guide/vcl-backends.rst
index 586b221..7dc8c95 100644
--- a/doc/sphinx/users-guide/vcl-backends.rst
+++ b/doc/sphinx/users-guide/vcl-backends.rst
@@ -31,6 +31,7 @@ Varnish can have several backends defined and can you can even join
 several backends together into clusters of backends for load balancing
 purposes. 
 
+
 Multiple backends
 -----------------
 
@@ -73,8 +74,42 @@ really arbitrary data. You want to send mobile devices to a different
 backend? No problem. if (req.User-agent ~ /mobile/) .. should do the
 trick. 
 
+
+Backends and virtual hosts in Varnish
+-------------------------------------
+
+Varnish fully supports virtual hosts. They might work in a somewhat
+counter intuitive fashion since they are never declared
+explicitly. You set up the routing of incoming HTTP requests in
+vcl_recv. If you want this routing to be done on the basis of virtual
+hosts you just need to inspect req.http.host.
+
+You can have something like this:::
+
+  sub vcl_recv {
+     if (req.http.host ~ "foo.com") {
+       set req.backend = foo;
+     } elsif (req.http.host ~ "bar.com") {
+       set req.backend = bar;
+     }
+  }
+
+Note that the first regular expressions will match foo.com,
+www.foo.com, zoop.foo.com and any other host ending in foo.com. In
+this example this is intentional but you might want it to be a bit
+more tight, maybe relying on the == operator in stead, like this:::
+
+
+  sub vcl_recv {
+    if (req.http.host == "foo.com" or req.http.host == "www.foo.com") {
+      set req.backend = foo;
+    }
+  } 
+
+
 .. _users-guide-advanced_backend_servers-directors:
 
+
 Directors
 ---------
 



More information about the varnish-commit mailing list