Varnish 2 VCL

jdouglas jdouglas at bksnetworks.com
Wed Oct 22 11:22:24 CEST 2008


How do i get varnish to cache all images?

I had varnish 1 working with this but it seems my vcl does not work at all with 2

Here is my VCL

#
# This is a basic VCL configuration file for varnish.  See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# $Id: default.vcl 1818 2007-08-09 12:12:12Z des $
#

# Default backend definition.  Set this to point to your content
# server.

backend default {
        .host = "127.0.0.1";
        .port = "80";
}


acl purge {
     "localhost";
}

sub vcl_recv {

     if (req.request == "PURGE") {
         if (!client.ip ~ purge) {
                 error 405 "Not allowed.";
         }
         lookup;
     }

     if (req.request != "GET" && req.request != "HEAD") {
         pipe;
     }

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

     /* Always cache images and binaries */
     if (req.url ~
"\.(jpg|jpeg|gif|png|tiff|tif|svg|swf|ico|vsd|doc|ppt|pps|xls|pdf|mp3|mp4|m4a|ogg|mov|avi|wmv|sxw|zip|gz|bz2|tgz|tar|rar|odc|odb|odf|odg|odi|odp|ods|odt|sxc|sxd|sxi|sxw|dmg|torrent|deb|msi|iso|rpm)$")
{
         lookup;
     }

     /* Always cache CSS and javascript */
     if (req.url ~ "\.(css|js)$") {
         lookup;
     }

     lookup;
}

/* Deal with purge requests */
sub vcl_hit {
     if (req.request == "PURGE") {
             set obj.ttl = 0s;
             error 200 "Purged";
     }
     deliver;
}

sub vcl_miss {
     if (req.http.If-Modified-Since) {
         pass;
     }
     if (req.request == "PURGE") {
             error 404 "Not in cache";
     }
     fetch;
}

sub vcl_fetch {
     if (!obj.valid) {
         error;
     }
     if (!obj.cacheable) {
         pass;
     }
     if (obj.http.Set-Cookie) {
         pass;
     }
     if(obj.http.Set-Cookie){
         pass;
     }
     if(obj.http.Pragma ~ "no-cache" ||
        obj.http.Cache-Control ~ "no-cache" ||
        obj.http.Cache-Control ~ "private"){
                pass;
     }
     if (req.url ~ "(errorPage?)") {
         set obj.ttl = 0s;
     }
     if (req.url ~ "(exceptionPage?)") {
         set obj.ttl = 0s;
     }
     if (req.url ~ "(unauthorizedPage?)") {
         set obj.ttl = 0s;
        }
    if (req.url ~ "(type=The+requested+Virtual+Kiosk+is+currently+not+available+from+%5Benter+Virtual+Kiosk+Sponsor+Name+here%5D.+Please+close+the+Virtual+Kiosk+and+try+again.)") {
         set obj.ttl = 0s;
        }

        insert;
}

sub vcl_deliver {
    remove resp.http.X-Varnish;
    remove resp.http.Via;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20081022/95e865bf/attachment-0001.html>


More information about the varnish-misc mailing list