Varnish v4 Production Directives

14 November 2016 by admin

Please note Varnish allows virtually endless configuration options, and the proxy directives below may need certain customization to work with your particular setup. You should always test your configuration to ensure it works properly before adding it to your production servers.

 

Yavli staff is always happy to help you integrate Proxy handling in Varnish. You may send us your existing Varnish configuration file, and we will implement the proxy directives in it for you.

Step 1: Locate your VCL configuration file

Typically this file is located here:

/etc/varnish/default.vcl

Step 2: Add a backend directive to the VCL configuration file

This should be placed after your existing backend declarations, usually in the beginning of the configuration file.


backend yavli {
  .host = "steg.yavli.com";
  .port = "80";
}

Step 3: Add Proxy directives to the VCL configuration file

This should be placed inside the vcl_backend_response section. Note this is in addition to what you already may have in there.


sub vcl_backend_response {

  if (bereq.url ~ ".*\.(?:png|jpg|gif)$" && beresp.status == 404 && bereq.retries == 0) {
    set bereq.backend = yavli;
    return(retry);
  }

}

Step 4: Restart Varnish

How Varnish is restarted varies from platform to platform. On Ubuntu, it is typically done like this:

service varnish restart