Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to know what's the right way to avoid caching "some pages" of a website using Varnish and cache all the others.

This is what I have tried to do with the vcl conf:

     sub vcl_fetch {
         #set beresp.ttl = 1d;
         if (!(req.url ~ "/page1withauth") ||
             !(req.url ~ "/page2withauth")) {
            unset beresp.http.set-cookie;
         }
         if (!beresp.cacheable) {
             return (pass);
         }
         if (beresp.http.Set-Cookie) {
             return (pass);
         }
         return (deliver);
}

Thanks

share|improve this question

1 Answer 1

up vote 4 down vote accepted
+75

Typically, this would be done in vcl_recv:

sub vcl_recv {
  if ( req.url !~ "^/page1withauth" && req.url !~ "^/page2withauth" )
  {
    unset req.http.Cookie;
    remove req.http.Cookie;
  }
}

Then, the only time you should have a set-cookie parameter coming back from the server is when you are trying to uniquely identify the connection. If it's because they just POSTed or similar, that's already going to evade the cache. If it's because you simply want to uniquely identify them, then the problem is your application's code intentionally breaking Varnish; fix your app if you can, otherwise you can override vcl_fetch similar to what you're doing here.

share|improve this answer
    
thank you It solved it –  mnml Feb 22 '11 at 10:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.