Re: Varnish and language cookie
In data 18 febbraio 2010 alle ore 21:58:39, Alessandro Ronchi ha scritto: > This is my configuration file: > http://dpaste.com/161264/ Ciao Alessandro, I'm no expert, but I think your config file explicitly defeats caching when there is a cookie. 41 if (req.http.Authorization || req.http.Cookie) { > I've used > set req.hash += req.http.cookie; I would suggest explicitly matching the "django_language" cookie, setting a custom header with its contents, and then using that as a hash part, so: In vcl_recv(): set req.http.X-Cookie-Language = regsub(req.http.Cookie, "..."); In vcl_hash(): set req.hash += req.http.X-Cookie-Language; This is part of one config I'm using, the vcl_recv() bit: if (req.http.Cookie ~ "language=") { set req.http.X-Varnish-Language = regsub(req.http.Cookie, "^.*?language=([^;]*?);*.*$", "\1"); } The regexp above is probably overly complicated. I tried a couple of times to simplify it, but I always broke it. Suggestions welcome :) -- Cosimo ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
RE: Varnish and language cookie
Hello, I am having hard time to to cache a multilingual web site. Vanish listen on port 80 and proxy the request to a multilingual django cms what I would like to do is to cache the pages per language and serve them from the cache. Unfortunately so far I have not been able to get this working and varnish keep on fetching th pages from the cms. I am going to add below all the information I think useful do not hesitate to let me know if you need more info ? Here it is my configuration : sub vcl_recv { # clean out requests sent via curls -X mode and LWP # http://varnish.projects.linpro.no/wiki/VCLExampleNormalizingReqUrl if (req.url ~ "^http://";) { set req.url = regsub(req.url, "http://[^/]*";, ""); } # Set the backend based on the subdomain name if (req.http.host == "static.gwadeloop.com") { set req.backend = static; } if (req.http.host == "dev.gwadeloop.com") { set req.backend = django; # Add a trailing slash if missing if ((req.url ~ "[^\]$") && (! (req.url ~ "^/media/"))) { set req.url = req.url "/"; } } if (req.http.Cookie) { # removes all cookies named __utm? (utma, utmb...) -- Google Analytics set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__utm.=[^;]+;? *", "\1"); if (req.http.Cookie == "") { remove req.http.Cookie; } } if (req.http.Cookie ~ "django_language=") { set req.http.X-Varnish-Language = regsub(req.http.Cookie, "django_language=([a-z]{2})", "\1"); } } - 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); } - here it is the information outputed by varnishlog when I try to access the same page twice: http://dpaste.com/163624/ I would be glad if someone could point me what I am doing wrong here. Regards, --yml ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Varnish and language cookie
I think this is your problem: 11 TxHeader b Cookie: sessionid=fd0523a529b0a09861a235d1c2fdd7de; changed=true; open_tab=1; rule_path=/general; django_language=fr; 11 RxHeader b Vary: Accept-Encoding 11 RxHeader b Vary: Accept-Language, Cookie If your pages are the same for all users then you should remove Cookie from the Vary. I would also remove the custom vcl_hash and just set req.http.Accept-Language to the value from the cookie, that way you avoid caching multiple copies of any images etc. Laurence On 23 February 2010 15:47, Yann Malet wrote: > Hello, > I am having hard time to to cache a multilingual web site. Vanish listen on > port 80 and proxy the request to a multilingual django cms what I would like > to do is to cache the pages per language and serve them from the > cache. Unfortunately so far I have not been able to get this working and > varnish keep on fetching th pages from the cms. > I am going to add below all the information I think useful do not hesitate > to let me know if you need more info ? > Here it is my configuration : > sub vcl_recv { > # clean out requests sent via curls -X mode and LWP > # http://varnish.projects.linpro.no/wiki/VCLExampleNormalizingReqUrl > if (req.url ~ "^http://";) { > set req.url = regsub(req.url, "http://[^/]*";, ""); > } > # Set the backend based on the subdomain name > if (req.http.host == "static.gwadeloop.com") { > set req.backend = static; > } > if (req.http.host == "dev.gwadeloop.com") { > set req.backend = django; > # Add a trailing slash if missing > if ((req.url ~ "[^\]$") && (! (req.url ~ "^/media/"))) { > set req.url = req.url "/"; > } > } > if (req.http.Cookie) { > # removes all cookies named __utm? (utma, utmb...) -- Google > Analytics > set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) > *__utm.=[^;]+;? *", "\1"); > if (req.http.Cookie == "") { > remove req.http.Cookie; > } > } > if (req.http.Cookie ~ "django_language=") { > set req.http.X-Varnish-Language = > regsub(req.http.Cookie, "django_language=([a-z]{2})", "\1"); > } > } > - > 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); > } > - > here it is the information outputed by varnishlog when I try to access the > same page twice: > http://dpaste.com/163624/ > I would be glad if someone could point me what I am doing wrong here. > Regards, > --yml > > ___ > varnish-misc mailing list > varnish-misc@projects.linpro.no > http://projects.linpro.no/mailman/listinfo/varnish-misc > > ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Varnish and language cookie
In data 27 febbraio 2010 alle ore 16:12:55, Alessandro Ronchi ha scritto: > 2010/2/19 Cosimo Streppone : > >> I'm no expert, but I think your config file >> explicitly defeats caching when there is a cookie. >> >> 41 if (req.http.Authorization || req.http.Cookie) { > > You are right. > I have a big problem: > > [...] > - cookie is removed from the browser. ??? This shouldn't happen at all. Maybe you're sending "Set-Cookie" headers from the django app and they are being stored with the cached objects? If so, when you know you're serving a cache hit, then you can unset obj.http.Set-Cookie. IINM, that should happen in vcl_deliver(). > Is it possible to save to a temp var the entire cookie, replacing in > it the not important cookies and if that var is emtpy return cached > version ignoring req.http.Cookie and leave that untoucked? > I've tried but it but without success. Cc'd varnish-misc, maybe there's someone facing the same exact problem, -- Cosimo ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Varnish and language cookie
2010/2/27 Cosimo Streppone : >> - cookie is removed from the browser. > > ??? This shouldn't happen at all. I'm unable to cache content with django-language=xx cookie and return the cached page. I've tried all the day, but without any success. http://dpaste.com/165609/ If I unset that cookie, the backend doesn't know that language the output is and it returns the default language. If I leave the cookie, it doesn't cache it. The best thing I've done is to have cached the requests without the cookie (and language), and get the other passed. But I think I can do that, it's a quite simple example: - all pages are cachable and varies only with language. - language is set in a cookie (that has to be sent to the backend if the page is not present in cache) or with a get url (&lang=en). - with the get url the backend sets the cookie language. so after that other pages will be translated also without the &lang=en suffix. - other cookies, except for google's, must send the page to pass. -- Alessandro Ronchi http://www.soasi.com SOASI - Sviluppo Software e Sistemi Open Source http://hobbygiochi.com Hobby & Giochi, l'e-commerce del divertimento ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Varnish and language cookie
> > 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 > > ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Varnish and language cookie
2010/2/26 Yann Malet : >> The interesting parts are in vcl_recv : >> # This is the only important part of the cookie because The problem with your configuration is that I need to pass pages with some cookies (like sessionid) because it's mean the user can have a cart (and sure I want to let them go to the checkout). I need the same behaviour of your conf but If I have only the language cookie I need not to pass. I didn't solved this problem. This is my actual conf: http://dpaste.com/166300/ With that I'm able to cache pages without cookies, eliminate analytics cookies, cache pages without language cookie but NOT return cached pages if the users have the language cookie. If I unset the language cookie, the backend doesn't know what language it has to return. If I leave it, it's not cached. -- Alessandro Ronchi http://www.soasi.com SOASI - Sviluppo Software e Sistemi Open Source http://hobbygiochi.com Hobby & Giochi, l'e-commerce del divertimento ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc