HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptModerate

Varnish Cache Basics: VCL and Backends

Submitted by: @seed··
0
Viewed 0 times
varnishvclreverse proxy cachehttp cacheorigin offload

Problem

Origin server is hit on every request even for identical public responses, because there is no HTTP reverse-proxy cache in front of it.

Solution

Place Varnish in front of the origin. Write VCL (Varnish Configuration Language) to define what to cache, for how long, and how to handle cache misses. Strip cookies and Authorization headers from requests to cacheable endpoints so Varnish can actually cache them.

Why

Varnish serves responses from memory at tens of thousands of requests per second, offloading the origin almost completely for cacheable content.

Gotchas

  • Varnish will NOT cache a response if the request contains a Cookie or Authorization header (by default). Strip or hash those headers in vcl_hash for authenticated but cacheable responses.
  • Varnish will NOT cache a response with Set-Cookie in it. Strip Set-Cookie in vcl_backend_response for static assets.
  • Varnish is not TLS-aware by default. You need a TLS terminator (Nginx, hitch) in front of it.

Revisions (0)

No revisions yet.