Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rezan
rezan / self_route.vcl
Last active February 28, 2024 12:56
Self routing Varnish Cache cluster example
# Self routing cluster example
vcl 4.0;
import directors;
backend node1 {
.host = "node1.example.com";
.port = "80";
}
@rezan
rezan / self_route_302.vcl
Last active February 10, 2017 20:34
Self routing Varnish Cache cluster example using 302 redirects
# Self routing cluster example using 302 redirects
vcl 4.0;
import directors;
backend node1 {
.host = "node1.example.com";
.port = "80";
}
@rezan
rezan / panic.vtc
Last active February 13, 2017 20:10
Capture panic
varnishtest "Capture potential panic (sleep => gdb attach to pid)"
varnish v1 -cli "help"
shell "sleep 20"
server s1 {
rxreq
txresp
expect req.url == "/"
@rezan
rezan / post.vtc
Created February 20, 2017 20:56
Cache POST requests
varnishtest "Cache POSTs"
server s1 {
rxreq
txresp -body "resp_body"
expect req.url == "/"
expect req.method == "POST"
expect req.bodylen == 14
} -start
@rezan
rezan / extend.vcl
Created March 17, 2017 17:44
Varnish Extend example VCL
# Varnish Extend VOD Demo
vcl 4.0;
import std;
import fsbackend;
backend default {
.host = "origin-frankfurt.varnish-software.com";
.port = "https";
@rezan
rezan / xff_acl.vcl
Created April 20, 2017 15:10
Parse XFF and check it against an ACL
vcl 4.0;
import std;
backend default
{
.host = "127.0.0.1";
.port = "80";
}
@rezan
rezan / content-length.vcl
Created May 9, 2017 19:16
Content-Length on all responses, this requests and stores both gzip and non gzip responses natively
sub vcl_hash
{
if (req.url ~ "xxx") {
set req.http.X-Accept-Encoding = req.http.Accept-Encoding;
hash_data(req.http.Accept-Encoding);
}
}
sub vcl_backend_fetch
{
@rezan
rezan / vcs_session.vcl
Created May 30, 2017 18:56
VCS session tracking
vcl 4.0;
import cookie;
import std;
sub vcl_deliver
{
cookie.parse(req.http.cookie);
set req.http.X-vcsid = cookie.get("_vcsid");
if (req.http.X-vcsid == "") {
@rezan
rezan / whoami.vcl
Created June 15, 2017 19:25
Who am I (VCL)
vcl 4.0;
sub vcl_recv
{
if (req.url == "/whoami.html") {
return(synth(765));
}
}
sub vcl_synth
@rezan
rezan / multi_tier_grace.vcl
Last active July 21, 2017 13:55
Properly handle grace across multiple tiers
vcl 4.0;
# Include this VCL on all tiers
# Call this once on the Edge tier
sub dvcl_init_edge
{
unset req.http.X-DVCL-skip-grace;
}