Varnish logs twice

The default configuration of varnish logs every request twice, once for the client and once for the backend communication

edit the line in /etc/init.d/varnishncsa to something like

DAEMON_OPTS="-c -a -w $logfile -D -P $pidfile"

from the varnishncsa man page

-c Include log entries which result from communication with a client. If neither -b nor -c is specified, varnishncsa acts as if they both were.

Read more

Varnish ACL

To setup an IP based access control list so that only allowed users may access the site.

sub vcl_recv {

  if (!(client.ip ~ testers)) {
    error 403 "Access Denied - server in test mode (IP not in ACL)";
  }

}

acl testers {
    "localhost";
    "www.example.com";
    "192.168.0.1";
}

In my case I need to be able to test a dev site but don't want to make it public, we tried using password authentication but that made it harder to test varnish as the authentication headers affected caching.

Read more

Varnish config on Debian

I've just spent too long being very confused as to why varnish wasn't working

I'd forgotten that  the Debian version doesn't read the default.vcl config file by default!

You have to edit /etc/default/varnish and specify the config type you want.

I was getting the error message

Error 503 Service Unavailable

Error talking to backend

Guru Meditation: XID:

Read more

Varnish caching - passing a hostname

I'm using varnish to cache a REST service that's slow enough to cause me grief in development.

Out of the box it assumes you are caching your own server and that the client is already using the right host header.

To specify that it should use a host header to match the backend I'm using a config like

backend default {
        set backend.host = "www.example.com";
        set backend.port = "80";

}


sub vcl_recv {
        set req.http.host = "www.example.com";
}

Read more