Varnish : how to add an exception for dynamic pages with cookies

Josh josh at schulzone.org
Fri Feb 18 17:26:20 CET 2011


It depends what you use the cookies for.  If they interact with code
to personalize the page then you can't cache them, but if they're
analytics cookies (for example) you can strip them out individually.
Here's the relevant line from my vcl:

set req.http.Cookie = regsuball(req.http.Cookie,
"(^|;\s*)(mbox|s_cc|s_cc|s_sq|s_vi)=[^;]+;?", "");

That pulls all the analytics cookies out from the back end request.
That's a better idea than just nuking the cookies, on the chance that
your code really is looking for one.  The server doesn't care about
any of those cookies, it's on page javascript elements that use them.

On Fri, Feb 18, 2011 at 8:58 AM, Roch Delsalle <rdelsalle at gmail.com> wrote:
> Thank you for your answer, I'm going to manage it from the Cache-Control
> headers then,
> All my pages are containing cookies, is it going to be a problem or do I
> need to use "unset beresp.http.set-cookie;" somewhere?
> On Fri, Feb 18, 2011 at 4:31 PM, Josh <josh at schulzone.org> wrote:
>>
>> On Fri, Feb 18, 2011 at 7:19 AM, Roch Delsalle <rdelsalle at gmail.com>
>> wrote:
>> > Hi,
>> >
>> > 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
>> >
>> > --
>> > D-Ro.ch
>> > _______________________________________________
>> > varnish-misc mailing list
>> > varnish-misc at varnish-cache.org
>> > http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>> >
>>
>>
>>
>> --
>> josh
>> @schulz
>> http://schulzone.org
>
>
>
> --
> D-Ro.ch



-- 
josh
@schulz
http://schulzone.org



More information about the varnish-misc mailing list