Generate a 404 response

Overview

Varnish Cache allows you to create synthetic HTTP responses with the use of vcl_synth. This can be used to deliver a 404 not found or 410 permanently removed status code for a particular asset.

VCL syntax

Below is an example of how to deliver a synthetic 404 response using VCL syntax 4.0. This example will deliver a 404 response if the request matches the URI path “/hello.jpg”

sub vcl_recv {
    if (req.url ~ "/hello.jpg") {
        return (synth(804, "Not Found"));
    }
}

sub vcl_synth {
    if (resp.status == 804) {
        set resp.status = 404;
        return (deliver);
    }
}

Note: You can use 410 instead of 404 to deliver a HTTP 410