wiki:VCLExamples

Please feel free to add your useful VCL snippets to the page.

This page holds (links to) (somewhat) useful VCL examples.

Attention: As of 2.1.0, obj.* is called beresp.* in vcl_fetch, and obj.* is now read-only.

VCL Examples

VCL Real World Examples

Below are full VCL's used already in live production systems.

These should only be used as a reference to help build your own VCL!

  • Submitted by alexc - 25-09-2009 - varnish 2.0.4 stable
  •  Submitted by Niall Douglas - 21st Jan 2011 - NEEDS varnish v2.0.5 or later. This VCL has the following features:
    1. Designed to primarily cache Zope and Plone content.
    2. Gives an example of how to "mount" parts of other websites onto your own e.g. here I mount Google Finance and the RePeC economics database. VERY useful for AJAX programming!
    3. Uses cunningly designed statically compiled regular expressions to perform VirtualHostMonster? style auto-generation of VirtualHostBase? paths out of the HTTP headers (includes HTTPS support!). This saves you having to specify them manually for each and every site you host.
    4. Enables varnish to serve stale content up to 24h old if Zope has gone down (very useful for performing upgrades), but keeps grace at 20s if the Zope backend is healthy. Note that this bit particularly requires the If-None-Match ETag support in varnish v2.0.5 and later.
    5. Patches SVGZ files to be returned as a more compatible SVG + gzip content encoded.
    6. Harmonises Content-Encoding to avoid caching too many copies.
  •  Submitted by Niall Douglas - 21st Jan 2011 - varnish v2.0.5 or later. This VCL configures a dumb content caching server which provides a local copy of another server's content. VERY useful for geo-targeted content, or for setting up an "everything has gone tits up so fall back to something" solution.
  •  Security.vcl - a Web Application Firewall implemented in VCL
  •  Varnish 3.0 templates - Wordpress, Drupal, Joomla and Fork CMS VCL templates

VCL Example Templates

Community supplied VCL templates to cover a few real world scenarios. These are meant to be a good starting point that can be tweaked to meet your own site requirements.

Attachments