Varnish HTTP cache
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
varnishd -a :80 -f <file.vcl>
varnishadm vcl.load <name> <file>
varnishadm vcl.use <name>
varnishadm ban "<expr>"
varnishadm backend.list
varnishstat -1varnishlog -g request
varnishtop -i ReqURL
Concepts
- Client HTTP request
- Cache hit: serve object
- Backend fetch, vcl_backend_response
- Client vcl_deliver
Run varnishd
varnishd -a :<port> -f <file.vcl>
varnishd -a :<port> -b
<host>:<port>
varnishd -T localhost:6082 -S <secretfile>
varnishd -s malloc,<size>
varnishd -Vvarnishadm
varnishadmvarnishadm <command>
varnishadm -T <host>:<port> -S
<secretfile>
varnishadm helpvarnishadm status
VCL management
varnishadm vcl.load <name> <file>
varnishadm vcl.use <name>
varnishadm vcl.list
varnishadm vcl.show <name>
varnishadm vcl.discard <name>
Bans and purging
varnishadm ban req.url ~ "<regex>"
varnishadm ban req.http.host == "<host>"
&& req.url ~ "<regex>"
varnishadm ban.list
curl -X PURGE <url>
Backends and health
varnishadm backend.list
varnishadm backend.list -p
varnishadm backend.set_health <backend> sick
varnishadm backend.set_health <backend> auto
Parameters
varnishadm param.show
varnishadm param.show changed
varnishadm param.set <param> <value>
varnishstat
varnishstatvarnishstat -1varnishstat -1 -f MAIN.cache_hit -f MAIN.cache_miss
MAIN.cache_hit, MAIN.cache_miss
varnishlog
varnishlogvarnishlog -g request
varnishlog -cvarnishlog -bvarnishlog -q '<VSL query>'
varnishlog -q 'ReqURL ~ "^/api"'
varnishlog -q 'RespStatus >= 500'
varnishtop and friends
varnishtop -i ReqURL
varnishncsaVCL essentials
vcl 4.1;backend default { .host = "<host>"; .port =
"<port>"; }
sub vcl_recv { ... }
return (pass);sub vcl_backend_response { set beresp.ttl = 5m; }
sub vcl_deliver { ... }
set beresp.grace = 1h;
unset req.http.Cookie;
set resp.http.X-Cache = obj.hits > 0 ? "HIT" :
"MISS";
| Variable | Meaning |
|---|---|
req.url |
request path and query |
req.http.<h> |
request header |
bereq.* |
request sent to backend |
beresp.ttl |
object lifetime |
obj.hits |
times served from cache |
resp.http.<h> |
response header to client |
Recipes
varnishadm vcl.load v2 /etc/varnish/v2.vclvarnishadm vcl.use v2# something wrong? roll back:varnishadm vcl.use v1varnishadm vcl.discard v2
varnishstat -1 -f MAIN.cache_hit -f MAIN.cache_miss# live and updating:watch -n2 'varnishstat -1 -f MAIN.cache_hit -f MAIN.cache_miss'
varnishlog -g request -q 'ReqURL ~ "^/checkout"'# in another terminalcurl -sI http://localhost/checkout



