caching and hiding 302 redirects

Stroomer, Jeff Jeff.Stroomer at
Wed Sep 7 22:57:13 CEST 2011

From: varnish-misc-bounces at<mailto:varnish-misc-bounces at> [mailto:varnish-misc-bounces at]<mailto:[mailto:varnish-misc-bounces at]> On Behalf Of Rob S
Sent: Wednesday, September 07, 2011 1:51 PM
To: varnish-misc at<mailto:varnish-misc at>
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?



Take a look at - this suggests putting a restart in vcl_deliver.



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;
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;
sub vcl_deliver {
  if (resp.http.X-Cache-Redirect == "1") {
    unset resp.http.X-Cache-Redirect;

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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list