Varnish and language cookie
Yann Malet
yann.malet at gmail.com
Fri Feb 26 14:38:28 CET 2010
>
> hello,
> This confusing behavior was due to a some of different factor a bug in
> django cache middleware for i18n pages, the same pages in french, german,
> english, .... and my relative inexperince with varnish. I think that now I
> have this issue solved witht the following configuration:
> http://dpaste.com/165182/
>
> The interesting parts are in vcl_recv :
> # This is the only important part of the cookie because
>
> # an annonymous user could get a page that was generated and
> # cached for another user.
> if (req.http.Cookie ~ "django_language=") {
> set req.http.X-Varnish-Language =
> regsub(req.http.Cookie, "django_language=([a-z]{2})", "\1");
>
> }
>
> in vcl_hach where I add the language to the hash :
>
> sub vcl_hash {
> set req.hash += req.url;
> if (req.http.host) {
> set req.hash += req.http.host;
> } else {
> set req.hash += server.ip;
> }
> set req.hash += req.http.X-Varnish-Language;
> return (hash);
> }
>
> and in vcl_fetch where I have commented out the block that make varnish
> "pass" if there is a cookie :
>
> sub vcl_fetch {
> if (obj.http.Pragma ~ "no-cache" || obj.http.Cache-Control ~ "(no-cache|no-store|private)") {
> # varnish by default ignores Pragma and Cache-Control headers. It
> # only looks at the "max-age=" value in the Cache-Control header to
> # determine the TTL. So we need this rule so that the cache respects
> # the wishes of the backend application.
> pass;
> }
> if (!obj.cacheable) {
> return (pass);
> }
> # don't allow caching pages that are protected by basic authentication
> # unless when they explicitly set the cache-control to public.
> if (req.http.Authorization && !obj.http.Cache-Control ~ "public") {
> pass;
> }
> # Varnish by default does not serve from cache if there is a cookie
> # if (obj.http.Set-Cookie) {
> # return (pass);
> # }
> set obj.prefetch = -30s;
> return (deliver);
> }
>
> thank you
> Regards,
> --yml
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20100226/639adfda/attachment-0002.html>
More information about the varnish-misc
mailing list