varnish 2.15 - default set to cache nothing except two urls?
Mike Franon
kongfranon at gmail.com
Fri Feb 11 15:45:00 CET 2011
Great thanks,
got one more question If I do this it caches everything, it never gets to
the else return(pass), the reason I have the if set that way is I want it to
cache the home page but if the client clicks on anything else once they get
to home page, not to cache and send the cookie.
Thanks again.
:
sub vcl_recv {
if (req.url ~ "/"){
unset req.http.cookie;
return(lookup);
}
else {
return(pass);
}
}
sub vcl_fetch {
if (req.url ~ "/"){
set beresp.ttl = 300s;
set beresp.http.cache-control = "public, max-age = 300";
set beresp.http.X-CacheReason = "varnishcache";
unset beresp.http.set-cookie;
return(deliver);
}
}
On Fri, Feb 11, 2011 at 9:29 AM, Caunter, Stefan <scaunter at topscms.com>wrote:
> The difference is that in recv it is a “req” from the client. Unsetting it
> “strips” the cookie, and makes the request cacheable.
>
>
>
> In fetch it is indeed “beresp” (back end response), so you are
> removing/changing HTTP headers from your web server. I’ve added a max-age to
> control client browser behaviour in the example too.
>
>
>
> Stefan Caunter
>
> Operations
>
> Torstar Digital
>
> m: (416) 561-4871
>
>
>
>
>
> *From:* varnish-misc-bounces at varnish-cache.org [mailto:
> varnish-misc-bounces at varnish-cache.org] *On Behalf Of *Mike Franon
>
> *Sent:* February-10-11 4:51 PM
> *To:* varnish-misc at varnish-cache.org
> *Subject:* Re: varnish 2.15 - default set to cache nothing except two
> urls?
>
>
>
> Thank you for the help!
>
> Quick question:
>
> for this block
>
> if (req.url ~ "/blah"){
>
> set beresp.ttl = 300s;
>
> *unset req.http.set-cookie;*
>
> set beresp.http.cache-control = "public, max-age = 300";
>
> set beresp.http.X-CacheReason = "Blah";
>
> return(deliver);
>
> }
>
>
>
>
>
> I thought it was unset beresp.http.set-cookie;
>
>
>
> Is there a difference?
>
>
>
>
>
> Thanks again.
>
>
>
> On Thu, Feb 10, 2011 at 4:16 PM, Caunter, Stefan <scaunter at topscms.com>
> wrote:
>
> You need in vcl_recv:
>
>
>
> if (req.url ~ “/blah”){
>
> unset req.http.cookie;
>
> return(lookup);
>
> }
>
> else {
>
> return(pass);
>
> }
>
>
>
> Setting 360s for beresp.ttl gets you 6 minutes J
>
>
>
> Resetting it to 360 if it goes under 120 seems odd.
>
>
>
> Use something like this in vcl_fetch:
>
>
>
> if (req.url ~ "/blah"){
>
> set beresp.ttl = 300s;
>
> unset req.http.set-cookie;
>
> set beresp.http.cache-control = "public, max-age = 300";
>
> set beresp.http.X-CacheReason = "Blah";
>
> return(deliver);
>
> }
>
>
>
> Stefan Caunter
>
> Operations
>
> Torstar Digital
>
> m: (416) 561-4871
>
>
>
>
>
> *From:* varnish-misc-bounces at varnish-cache.org [mailto:
> varnish-misc-bounces at varnish-cache.org] *On Behalf Of *Mike Franon
> *Sent:* February-10-11 3:51 PM
> *To:* varnish-misc at varnish-cache.org
> *Subject:* varnish 2.15 - default set to cache nothing except two urls?
>
>
>
> HI,
>
>
>
> I am fairly new to varnish, and was curious, is there a way to have all
> traffic go through varnish to the backend without caching unless for
> specific pages. For example we only want two pages to be cached, our home,
> and a specific page under the home as seen below?
>
>
>
> Here is my default.vcl
>
>
>
> Thanks
>
>
>
>
>
>
>
> backend default {
>
> .host = "127.0.0.1";
>
> .port = "80";
>
> }
>
>
>
>
>
> sub vcl_recv {
>
>
>
> # for the default home page
>
> if (req.url ~ "^/") {
>
> unset req.http.cookie;
>
> }
>
>
>
>
>
> # if they go directly to /samplepage
>
> if (req.url ~ "^/samplepage") {
>
> unset req.http.cookie;
>
> }
>
>
>
> }
>
>
>
> sub vcl_fetch {
>
> if (req.url ~ "^/") {
>
> unset beresp.http.set-cookie;
>
> }
>
>
>
> if (req.url ~ "^/samplepage") {
>
> unset beresp.http.set-cookie;
>
> }
>
>
>
>
>
> #override cache headers from backend to keep element in cache for 5
> minutes
>
> if (beresp.ttl < 120s) {
>
> set beresp.ttl = 360s;
>
> }
>
>
>
> }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20110211/7e2118c2/attachment-0001.html>
More information about the varnish-misc
mailing list