Varnish: Do not cache 404 error pages

Written by
Date: 2013-01-15 11:00:13 00:00


If Varnish Cache is caching 404 error code pages from the backend, you can change this behaviour by adding this to the vcl

In the vcl_fetch section add this:

if (beresp.status == 404) { 
    	set beresp.ttl = 30s; 
    }

You can change 30s to 0s if you do not want to cache 404 error codes at all.

I prefer to cache them for a short period of time, that way I can protect my back end from dealing with that load.