Pass 200 on 404

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

On Mon, Feb 25, 2013 at 5:08 PM, Jeffrey Taylor <jefe78 at> 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

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?

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

More information about the varnish-misc mailing list