caching and hiding 302 redirects
Stroomer, Jeff
Jeff.Stroomer at disney.com
Wed Sep 7 22:57:13 CEST 2011
From: varnish-misc-bounces at varnish-cache.org<mailto:varnish-misc-bounces at varnish-cache.org> [mailto:varnish-misc-bounces at varnish-cache.org]<mailto:[mailto:varnish-misc-bounces at varnish-cache.org]> On Behalf Of Rob S
Sent: Wednesday, September 07, 2011 1:51 PM
To: varnish-misc at varnish-cache.org<mailto:varnish-misc at varnish-cache.org>
Subject: Re: caching and hiding 302 redirects
On 07/09/2011 20:41, Stroomer, Jeff wrote:
Varnish folks,
I’m trying to combine Varnish with a Tomcat servlet to make a fancy reverse proxy. The idea is that Varnish forwards a URL to the servlet, which uses a 302 redirect to tell Varnish what the “real” URL should be. For this to work well I need Varnish to do two things: 1) cache the 302 redirects from the servlet, and also 2) hide the redirect from the client. It seems like I can get Varnish to do one or the other, but not both simultaneously.
...
Any suggestions as to how I can cache the 302 response and also hide the redirect from the client?
Jeff
Jeff,
Take a look at https://www.varnish-cache.org/trac/ticket/411 - this suggests putting a restart in vcl_deliver.
Rob
________________________________
Rob,
Thanks, this seems like exactly what I need … but I tried it, and my 302 redirects are still not getting cached. Here’s what I have in my default.vcl:
sub vcl_hit {
if (obj.http.X-Cache-Redirect == "1") {
set req.url = obj.http.Location;
restart;
}
}
sub vcl_fetch {
if (beresp.status == 302) {
set req.url = beresp.http.Location;
set beresp.http.X-Cache-Redirect = "1";
set beresp.ttl = 600s;
set beresp.cacheable = true;
return(deliver);
}
}
sub vcl_deliver {
if (resp.http.X-Cache-Redirect == "1") {
unset resp.http.X-Cache-Redirect;
restart;
}
return(deliver);
}
I think this is a faithful copy of what’s in the trac ticket, but updated to the current VCL syntax. If it makes a difference, I’m running the 2.1.3 version of Varnish.
Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20110907/4e8b0f90/attachment-0003.html>
More information about the varnish-misc
mailing list