Pass 200 on 404

Hugo Cisneiros (Eitch) hugo.cisneiros at gmail.com
Mon Feb 25 21:17:49 CET 2013


On Mon, Feb 25, 2013 at 5:08 PM, Jeffrey Taylor <jefe78 at gmail.com> wrote:

> We're using Amazon Cloudfront(CF). The issue we've run into is that when
> CF gets a 404, it caches that for ~5 minutes. What we want to do is have
> Varnish(already part of our stack) pass a 200 to CF on a 404 event, but
> only cache that '404' for ~1 minute. In doing so, we give ourselves 1
> minute to recover from the 404 event on our stack, in doing so, we can keep
> serving content 1 minute after, instead of 5 minutes because of CF.
>

On vcl_fetch, you can test if the response status from backend request is
404 and return a 200 to the client (CloudFrond) using the vcl_error, like
this:

sub vcl_fetch {
  if (beresp.status == 404) {
    set beresp.ttl = 1m;
    error 200 "Not Found";
  }

  [...]
}

The default vcl_error should return the correct HTTP status code.

But IMHO this isn't a good thing to do with every content from the backend
:-) Isn't there a cache TTL setting on CloudFront?

[]'s
Hugo
www.devin.com.br
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130225/f1599536/attachment.html>


More information about the varnish-misc mailing list