Realizing vhosts with varnish

Frank Helmschrott fhelmschrott at
Thu Dec 16 10:06:04 CET 2010

Hi list,

here's my situation:

I got one dedicated server to run varnish and multiple backend servers
delivering websites. These Backend servers host several different web
projects and the standard solution is the each project runs without
any cache or anything else.

Now i want to take some load off of the servers by using varnish and
routing them through the cache. I thought about different solutions
and searched around a bit and came across this blog post
( and also
found the mailing list entry on that topic. I tried it out in my
config but it didn't work. I think this is due to my missing knowledge
so i thought i'd ask here.

I currently have a default.vcl containing these lines:

sub vcl_recv {
        if (!req.http.Host)
                error 404 "Need a host header";

        set req.http.Host = regsub(req.http.Host, "^www\.", "");
        set req.http.Host = regsub(req.http.Host, ":80$", "");

        if (req.http.Host = "")
                include "/etc/varnish/";
        elsif (req.http.Host = "")
        include "/etc/varnish/";

The two vhost files contain a basically working configuration (it
workes well when using it as the only config). With the default.vcl
from above varnish doesn't start. Unfortunately on my server (using
CentOS 5.5 and varnish from EPL) i don't get any error messages what
may be wrong. Is there something missing that must be set before this
if/else statement can be handled?

I'm currently a bit confused and don't know where to continue. Any
help is appreciated. I'm using the latest Version from EPEL which is

One additional question: When fetching the files from backend servers,
doesn't varnish send a hostname? I tried putting some more vhosts on
one IP on the backend and setup this IP in varnish as backend server
but what varnish delivered was the default content from the backend
instead of the vhosts content the hostname belonged to.

Thanks for helping!

More information about the varnish-misc mailing list