LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Varnish caching based on cookies (https://www.linuxquestions.org/questions/linux-server-73/varnish-caching-based-on-cookies-4175493236/)

noriodesousa 01-31-2014 04:34 AM

Varnish caching based on cookies
 
Hi guys,

I run a Simple Machines forum and have Varnish in front of it. I'd like to cache all anonymous requests. This should be easy enough as SMF sets a cookie 'SMFCookie132' if you log in. This cookie can be renamed to anything I like.

So my question is: How do I configure Varnish to cache for everyone except those with this cookie?

Thanks a stack!

noriodesousa 01-31-2014 06:57 AM

Okay so I've got something that works pretty well. It checks for the SMFCookie132 cookie and, if it finds it, it deletes ALL the cookies. Varnish will serve cached objects if there are no cookies.

Code:

# recv
sub vcl_recv {
        # if SMFCookie132 is not there...
        if ( ! req.http.cookie ~ "SMFCookie132") {
                # kill ALL cookies
                unset req.http.Cookie;
        }
}



All times are GMT -5. The time now is 10:40 PM.