Configure varnish to pipe a subdomain

Philipp Winkler varnish at streikt.net
Mon Jan 21 22:48:33 CET 2008


Hello list,

I installed varnish on a staging system today and I am totally impressed 
by the performance.
Unfortunately I'm no regex expert, so I will need your help with this 
config issue.

I want to use varnish for a domain - lets call it "example.com"
The domain has got a subdomain "admin.example.com" - any GET / POST to 
this subdomain and any pages underneath should not be cached but should 
directly passed to the backend.

This is my config - which does not work for as the requests to 
admin.example.com as they are also being cached :-(

Thanks so much for your help!
Philipp



(comments are in german - please dont bother!):



/* Definition Default Backend */
backend default {
        set backend.host = "127.0.0.1";
        set backend.port = "1234";
}

sub vcl_recv {
        /* Falls etwas an den Server geschickt wird, geben wir das durch */
        if (req.request == "POST") {
                pipe;
        }

        /* Anfragen an die "admin" Seite werden direkt durchgereicht /*
         if (req.http.url ~ "admin.example.com$") {
                pipe;
        }

        if (req.http.Cookie && req.http.url ~ "admin.example.com$") {
                pipe;
        }

        if (req.http.Expect) {
                pipe;
        }

        /* Wir cachen Bilder, Dokumente, Audio und FLV Filme*/
        if (req.url ~ 
"\.(jpg|jpeg|gif|png|tiff|tif|svg|swf|flv|ico|doc|ppt|xls|pdf|mp3|mp4|mp4a|ogg)$")
        {
                lookup;
        }
        /* Wir cachen auch CSS und javascript */
        if (req.url ~ "\.(css|js)$") {
                lookup;
        }

        /* Und wir cachen HTML Code */
        if (req.url ~ "\.(html|htm)$") {
                lookup;
        }
        /* Filme cachen wir auch - testweise */
        if (req.url ~ "\.(mov|avi|wmv)$") {
                lookup;
        }
        /* ZIP Dateien cachen wir experimentell auch */
        if (req.url ~ "\.(zip)$") {
                lookup;
        }

        /* Cookie Requests an die Hauptseite cachen wir weg */
        if (req.http.Cookie) {
                lookup;
        }

        /* Kein Caching fuer Content hinter http authentification */
        if (req.http.Authenticate || req.http.Authorization) {
                pipe;
        }

        /* Oh und wir cachen alles andere */
       lookup;
}

sub vcl_fetch {
        /* Wir setzen die TTL fuer jedes Objekt das eine TTL von unter 
60sec hat auf 60sec */
        if (obj.ttl < 60s) {
        }

        if (!obj.valid) {
                error;
        }
        if (!obj.cacheable) {
                pass;
        }
        if (obj.http.Set-Cookie) {
                pass;
        }
        /* Wir cachen HTML maximal 30 Minuten */
        if (req.url ~ "\.(htm|html)$") {
                set obj.ttl = 1800s;
        }

/* Wir cachen jedes Objekt maximal fuer drei Stunden */

        set obj.ttl = 10800s;
}

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.";
        }
}






More information about the varnish-misc mailing list