Varnish config (any tips?)

Sim simvirus at gmail.com
Sat Mar 16 20:29:46 CET 2013


Dear users,
this is my Varnish config for use it at "100%" (to cache all) for about "5"
min.
Have you any comments or tips for me?
Are there other way or optimizations?
Why Varnish does not keep everything in cache by default?

Thanks
Regards


##############################################
backend [...]

##############################################
sub vcl_recv {

     if (req.restarts == 0) {
        if (req.http.x-forwarded-for) {
            set req.http.X-Forwarded-For =
                req.http.X-Forwarded-For + ", " + client.ip;
        } else {
            set req.http.X-Forwarded-For = client.ip;
        }
     }

     # Direct connections from 1.2.3.4 IP
     if (client.ip == "1.2.3.4"{
         return (pipe);
     }

     # CACHE ALL!
     if (req.request == "GET" || req.request == "HEAD") {
        return (lookup);
     }

     if (req.request != "GET" &&
         req.request != "HEAD" &&
         req.request != "PUT" &&
         req.request != "POST" &&
         req.request != "TRACE" &&
         req.request != "OPTIONS" &&
         req.request != "DELETE") {
         /* Non-RFC2616 or CONNECT which is weird. */
         return (pipe);
     }
     if (req.request != "GET" && req.request != "HEAD") {
         /* We only deal with GET and HEAD by default */
         return (pass);
     }
     if (req.http.Authorization || req.http.Cookie) {
         /* Not cacheable by default */
         return (pass);
     }
     return (lookup);
 }

##############################################
sub vcl_pipe {
     set bereq.http.connection = "close";
     return (pipe);
}

##############################################
sub vcl_hit {
    return (deliver);
}

##############################################
sub vcl_miss {
    return (fetch);
}

##############################################
sub vcl_fetch {
    if (beresp.ttl <= 0s ||
        beresp.http.Set-Cookie ||
        beresp.http.Vary == "*") {
                /*
                 * Mark as "Hit-For-Pass" for the next 5 minutes
                 */
                set beresp.ttl = 300s;
                return (hit_for_pass);
    }
    return (deliver);
}

##############################################
sub vcl_deliver {
   # Check if working
   if (obj.hits > 0) {
     set resp.http.X-Cache = "HIT";
  } else {
     set resp.http.X-Cache = "MISS";
  }
   return (deliver);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130316/a1c47e9c/attachment.html>


More information about the varnish-misc mailing list