New Version backend config

Michael Alger varnish at
Wed Dec 15 03:41:21 CET 2010

On Wed, Dec 15, 2010 at 08:54:01AM +0800, ll wrote:
> 于 2010-12-14 16:27, Lars Jørgensen 写道:
>> Hi ll,
>> Specify the ip address instead of the DNS name. That way you also cut
>> the name lookups out of the equation.
> what is different between the .host is domain and IP ?
> I thought the IP had multi domains ,so I set the .host exactly to a
> domain which I want to proxy .

The backend definition gives the address and port of a backend web
server which you want to retrieve content from, in the event that the
request cannot be satisfied by Varnish's cache.

When you specify the backend .host attribute, you are just telling
Varnish where to connect to. It doesn't alter anything about the request
headers sent, including the Host header. It's purely used to specify an
endpoint of a TCP/IP connection. The actual data which is sent over that
connection is determined by the request and the VCL code.

If you have multiple websites on different domain names hosted by the
same server on the same IP address+port (i.e. name-based virtual
hosting), then the web server is deciding which site to serve content
for based on the "Host:" header in the HTTP request. That is, it reads
the request, looks at the value of the Host: header, and sees if it has
a site configured which matches that hostname.

You can check/manipulate the Host header within VCL using req.http.Host.
If you don't explicitly do anything with it, then it will remain set to
whatever the client sent in its request.

For the most reliable/easiest to understand use, I would recommend:

- always specify the IP address for your backend servers.

- if you have multiple backends for the same website, group them using
  a director; or use retries and some VCL logic to select a different
  backend if the first is no good.

- it's a good idea to check the Host header of the incoming request to
  make sure it matches a site you actually host/proxy.

  if (! req.http.Host ~ "^(www\.abc\.com|www\.xyz\.net|alpha\.bet)$")
    error 403 "Site not hosted here";

- if you are serving multiple domains, make sure you're including
  req.http.Host in the hash when looking up items in the cache.

- also consider rewriting it to a single form. e.g. rewrite a host
  header of "" to "" to avoid having two versions of
  the same object cached.

  if (req.http.Host == "")
    set req.http.Host = "";

- I'd also recommend doing something like:
    set req.http.Host = regsub(req.http.Host, ":80$", "");
  to remove the port 80 specification from the Host header, which some
  clients send.

- and consider what will/should happen if the client doesn't send a Host
  header at all.

  if (! req.http.Host)
    error 500 "No host header";

You'd want to implement these checks in the reverse of the order I
listed them, for obvious reasons. :)

>> -----Original Message-----
>> From: varnish-misc-bounces at On Behalf Of ll
>> Sent: Tuesday, December 14, 2010 3:31 AM
>> To: varnish-misc at
>> Subject: New Version backend config
>> hi,all,Is there any change about the muti-backend config in the
>> varnish-cache-2.1.4 version ?
>> I set the backend like that
>> backend abc {
>>           .host="";
>>           .port="80";
>> }
>> the DNS had change to my varnish server ip
>> and i had edit the varnish server 's /etc/hosts file ,add
>> but now, all the url which had set the backend to "abc" is not work.I
>> use the same config in the 2.0.4 version is fine. I don't know how to
>> fix it ?

More information about the varnish-misc mailing list