Search code examples
varnishvarnish-vcl

How to Ignore Cache If Session Set In Varnish


I need to do custom Varnish VCL configuration for cookie based by-pass objects. So, Varnish keep serving my cached pages unless user logged in. How can i prevent access to non-logged users? for specific pages or regex etc.

Using: Varnish 3 on Nginx, Ubuntu 64. bit EC2 instance


Solution

  • That's the varnish default behaviour, excerpt from the default config [1]:

    sub vcl_recv {
    #...
      if (req.http.Authorization || req.http.Cookie) {
        /* Not cacheable by default */
        return (pass);
      }
    #...
    }
    

    [1] https://www.varnish-cache.org/docs/3.0/reference/vcl.html#examples