Caching issue

Shain Miley smiley at npr.org
Fri Mar 7 22:10:18 CET 2008


Hello all,
First let me say thanks to everyone for taking time to work on this 
project...I am still in the testing phase, however if all goes well 
Varnish is going to come in quite handy.

So here is my problem:

I would like to use varnish to cache urls for say a period of 30 
minutes.  The caching seems fine as long as I use the same browser to 
request the url.  But I am looking for a stop gap solution at this time 
so in the event that the web server becomes unavailable....varnish can 
serve the docs for a little while, so we can get things back in order.  
Anyway..as it stands right now..I can request a url from wget or GET or 
firefox... and turn off the webserver and I can refresh the page and all 
is well.

What I cannot do...is request a url using GET on one machine..then stop 
the webserver and request that same url from firefox (different machine) 
and get a valid page...I get a 503 error...Here is the vcl.conf file 
(which I took most of from the web) I am using:

Any help would be great!

Thanks,

Shain

sub vcl_recv {
        if (req.request != "GET" && req.request != "HEAD") {
                # PURGE request if zope asks nicely
                if (req.request == "PURGE") {
                        if (!client.ip ~ purge) {
                              error 405 "Not allowed.";
                }
                lookup;
                }
                pipe;
        }
        if (req.http.Expect) {
                pipe;
        }

        if (req.http.Authenticate || req.http.Authorization) {
                pass;
        }

        # We only care about the "__ac.*" cookies, used for authentication
        if (req.http.Cookie && req.http.Cookie ~ 
"__ac(|_(name|password|persistent))=") {
                pass;
        }

        # File type that we will always cache
        if (req.request == "GET" && req.url ~ 
"\.(html|php|gif|jpg|swf|css|js|png|jpg|jpeg|gif|png|tiff|tif|svg|swf|ico|css|js|vsd|doc|ppt|pps|xls|pdf|mp3|mp4|m4a|ogg|mov|avi|wmv|sxw|zip|gz|bz2|tgz|tar)$") 
{
            lookup;
        }

        if (req.request == "POST") {
                pipe;
        }

        # force lookup even when cookies are present
        if (req.request == "GET" && req.http.cookie) {
                lookup;
        }
        lookup;
}

sub vcl_fetch {

if (obj.ttl < 1800) {
                set obj.ttl = 1800s;
        }
}

# Do the PURGE thing
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-dev mailing list