VCL documentation

Poul-Henning Kamp phk at phk.freebsd.dk
Wed Sep 20 16:43:15 CEST 2006


In message <20060920132240.GG13253 at crusaders.no>, Trond Michelsen writes:
>Hi. 
>
>I've just downloaded and installed varnish, and I was just wondering
>if the VCL config language is documented somewhere, or if there are
>any examples that I could use for inspiration.

The main example right now is the default VCL code which you will
find in the source file bin/varnishd/mgt_vcc.c.

Also, this is the code we run at VG right now:

backend default {
        set backend.host = "10.0.2.1";
        set backend.port = "80";
}

acl purge {
        "localhost";
        "10.0.0.1";
}

sub vcl_recv {
        if (req.request == "PURGE") {
                if (!client.ip ~ purge) {
                        error 405 "Not allowed.";
                }
                lookup;
        }
        if (req.request == "GET" && req.http.cookie) {
                lookup;
        }
}

sub vcl_hit {
        if (req.request == "PURGE") {
                set obj.ttl = 0s;
                error 200 "Purged.";
        }
}

sub vcl_miss {
        if (req.request == "PURGE") {
                error 404 "Not in cache.";
        }
}


The important thing to know which is not obvious, is that if
you do not hit an "action" in for instance vcl_miss(), the
default vcl_miss() function will be executed and will determine
the action.

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.



More information about the varnish-misc mailing list