Please feel free to add your useful VCL snippets to the page.
This page holds (links to) useful VCL examples.
Attention: As of 2.1.0, obj.* is called beresp.* in vcl_fetch, and obj.* is now read-only.
VCL Examples
- The Default VCL with examples and a graphical overview of how a request goes through all the VCL hooks.
- Purging (also see the FAQ)
- Using restarts to protect from Apache error codes of 5xx
- Using restarts to try multiple backends
- Using directors for load balancing
- Caching even when cookies are present
- Caching content for logged in users or content based on cookie settings
- How to cache things longer on Varnish than the client
- Removing some, but not all cookies
- Enable force-refresh from clients
- Redirect using VCL
- How to ignore cache headers from the backend
- Log to syslog using VCL and embedded C
- Useful bits if you are using pipe
- Adding a header indicating hit/miss & extended diagnostics
- Grace - Handling backend failures and expired objects gracefully
- Saint Mode - Holding off backend requests for a specific object for a while
- How to avoid hotlinking to your site
- An example showing how Varnish can change your web server signature
- Redirecting the browser to another hostname
- Normalizing req.url
- Setting ttl in Varnish based on a header
- Normalize Accept-Language header
- Strip Google Adwords "gclid" parameter from bought Analytics tagged traffic
- Set Expires header based on max-age in Cache-Control
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!
VCL Syntax
Manually maintained syntax description of VCL
- Varnish 1.1 source:branches/1.1/lib/libvcl/syntax.txt
- Varnish 1.2 source:branches/1.2/lib/libvcl/syntax.txt
Note: This document has been removed from trunk (which has a number of VclSyntaxChanges).
Attachments
-
varnish_vcl.pdf
(122.4 KB) - added by perbu
2 years ago.
A presentation held by phk in Aalborg 2008-03-25
