Need help with varnish-vcl-collection?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

128 Stars 44 Forks GNU General Public License v2.0 5 Commits 4 Opened issues


Collection of Varnish VCL files

Services available


Need anything else?

Contributors list



Collection of Varnish VCL files. The purpose of this collection is to make it easier to configure varnish for some common setups and behaviors. Some of these files require you to define specific ACLs in your main VCL, and also note that the order of including files could change the behavior of Varnish.

The main goal for this VCL Collection is to provide a simple config with just a few options that can make Varnish work for the majority of sites. Most of the "configuration" is done by choosing which files to include and defining ACLs. We hope to provide a robust configuration that can be used with relatively little information or control over what is actually running on the backend. This is particularly useful for managed web hosts who want to have customers benefit from the performance of a caching proxy without limiting what can run on the web backend and without customizing the configuration for each customer.


for an example of how to use this collection of VCLs to configure Varnish for a WordPress site.


If you use CloudFlare and the backend is running

(for Apache) or
(for Nginx), then you should use

CloudFlare uses the HTTP Header

to store the original client IP address. Note that unlike the
Header, this just contains the original IP address, not the entire forward chain.

If you are using a CloudFlare Railgun server, or have any other trusted proxy servers between Varnish and CloudFlare, you will need to specify them in the


Also note that you will need to make sure that Varnish's IP is configured as trusted in

or the
on the backend.

Example usage::

include "lib/cloudflare.vcl";

acl cloudflare { # put the IP of your Railgun (or proxy) server here # ""; }

Mobile Device Optimizaiton

Different applications optimize for mobile devices in different ways. The best way is to use an "adaptive" design so that the same HTML is served to both desktop and mobile devices. If your application is "adaptive", then no special Varnish config is necessary; all devices will access the same objects in the Varnish cache.

However, if your application does serve different content to different devices, then you'll need to handle that in Varnish. Since applications do mobile device detection differently, the VCL code included here is intentionally limited and simple. Crafting a custom configuration to handle the way your application treats mobile devices will usually give better results than using one of the following standard configs.

simply adds the string
to the hash data to give mobile devices a separate cache from non-mobile devices. This is only viable if your application serves just 2 different versions of each page depending on if the visitor is on a mobile device or not (and if the application uses the same method to detect mobile devices). Any disagreement between
and your backend on what User-Agents should be considered "mobile" could mean that the incorrect versions of pages are served to some visitors.

simply disables caching for mobile devices. This is not good for performance, but will at least will prevent serving the incorrect version of pages to mobile visitors.

HTTP Purging


to allow purging pages from the cache using the HTTP PURGE method. This uses the ban feature of varnish and will make bans take advantage of Varnish's ban-lurker. You will need to specify a
ACL so that only requests coming from your application are allowed to purge.

Example usage::

include "lib/purge.vcl";

acl purge { # include the IP of your app if it isn't on localhost "localhost"; ""; }

There are several different possible behaviors of HTTP purging which can be controlled with the X-Purge-Method HTTP header. This config will be smart and attempt to automatically pick the best method based on the URL if you don't use an X-Purge-Method header. See the comments in

for details.

Static File Caching


to use a simple set of rules to cache static files. This will ignore the query string part of request URLs, and discard all cookies for these requests. This will also cache static files for 24 hours.

The cache behavior for this vcl can be bypassed by adding

to the url. For example,
will always retrieve the file from the backend instead of serving from the cache.

Big Files

Varnish cannot cache files larger than the entire cache. Additionally, a few large files could potentially fill up the cache and force many more small files to be removed from the cache. Use

to prevent caching files larger than 10 MB. This size was chosen because this should allow most common website assets to be cached. Files larger than 10 MB such as videos, long podcasts, or binary downloads are better suited to be served with a CDN or some server separate from your main web application. This config will still allow Varnish to serve these large files, but the files will always be retrieved from the backend.

marks files with
when they are above the size threshold. However this only works in Varnish 3.0.3 or later. Earlier versions of Varnish will instead show an internal server error when this method is used. In the case of these older versions of Varnish, you should use
, which instead pipes the request.

Your main VCL must have

import std;
. This import line is not included within the files themselves because having an import multiple times in a Varnish config (counting all included files) produces a compile error.

Example usage::

import std;
include "lib/bigfiles.vcl";

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.