Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);


share|improve this question
up vote 5 down vote accepted

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


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.