Monthly Archives: August 2015

Load balancing varnish 4

Since I had to google a lot to find this here a simple config for loadbalancing in varnish 4

vcl 4.0;
import std;
import directors;
backend server1 {
    .host = "ip/hostname";
backend server2 {
    .host = "ip/hostname";
sub vcl_init {
	new vdir = directors.round_robin();
sub vcl_recv {
    set req.backend_hint = vdir.backend();

See what is passing though the varnish proxy without a log

First add a header to see what is going on in the varnish proxy

vcl 4.0;
sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    # You can do accounting or modifying the final object here.
        if (obj.hits > 0) {
                set resp.http.X-Cache = "HIT";
        } else {
                set resp.http.X-Cache = "MISS";

No we can us varnishlog to see what urls are passing as a miss!

varnishlog -q ‘RespHeader ~ “X-Cache: MISS”‘ | grep -i requrl