Search code examples
varnish-vcl

varnish referencing an external file


I am new to varnish and I am trying to figure out a way in which varnish can reference to an external html file to serve an error page, as having the html code in the synthetic function would be too complex as the error page has too many visualizations, thanks


Solution

  • If you are using Varnish 4 (or more recent) you can do it with the std vmod See the doc : https://www.varnish-cache.org/docs/4.0/reference/vmod_std.generated.html#func-fileread

    I think the vcl should look like the following (not tested) :

    vcl 4.0;
    import std;
    
    #other stuff
    
    sub vcl_synth {
      if (resp.status == 404) {
         set resp.http.Content-Type = "text/html;";
         synthetic(std.fileread("/etc/varnish/404.html"));
         return (deliver);
      }
    }