Skip to content

Instantly share code, notes, and snippets.

sub vcl_recv {
# Set the header at the very top of sub vcl_recv before anyu return(pass) calls
set req.http.section-shared-secret = "RTio4vNHfxiWabqKxj8PZ99k";
}
# Check for this header and its value on the origin server
sub vcl_recv {
if (req.request != "GET" && req.request != "HEAD" && req.request != "PURGE") {
return (pass);
}
// Rest of vcl_recv code
return(lookup);
}
sub vcl_fetch {
if (req.request != "GET" && req.request != "HEAD" && req.request != "PURGE") {
sub vcl_recv {
if the request isn't GET|HEAD|PURGE {
skip the rest of vcl_recv code
}
// Rest of vcl_recv code
perform a lookup in cache
}
sub vcl_backend_response {
if the request isn't GET|HEAD|PURGE {
sub vcl_recv {
if (req.method != "GET" && req.method != "HEAD" && req.method != "PURGE") {
return (pass);
}
// Rest of vcl_recv code
return(hash);
}
sub vcl_backend_response {
@section-io-gists
section-io-gists / language-header.vcl
Last active October 9, 2017 15:35
Language header based on country code.
sub vcl_recv {
# Set a X-Language header to spanish is the client is from a spanish speaking country
if (req.http.section-io-geo-country ~ "^(AR|BO|CL|CO|CR|CU|DO|EC|SV|GQ|GT|HN|MX|NI|PA|PY|PE|ES|UY|VE)$") {
set req.http.X-Language = "Spanish";
} else {
set req.http.X-Language = "English";
}
}
sub vcl_hash {
@section-io-gists
section-io-gists / bareDomainRedirectVCL3.vcl
Last active April 20, 2021 20:45
Redirect from bare domain to www site in VCL3
sub vcl_recv {
if (req.http.host !~ "www") {
error 850 "Moved Permanently";
}
}
sub vcl_error {
if(obj.status == 850) {
set obj.http.Location = "https://www." + req.http.host + req.url;
set obj.status = 301;
@section-io-gists
section-io-gists / bareDomainRedirectVCL4.vcl
Last active April 20, 2021 20:45
Redirect from bare domain to www site in VCL4.0
sub vcl_recv {
if (req.http.host !~ "www") {
return (synth(850, "Moved Permanently"));
}
}
sub vcl_synth {
if(resp.status == 850) {
set resp.http.Location = "https://www." + req.http.host + req.url;
set resp.status = 301;
@section-io-gists
section-io-gists / section-user-throttling.vcl
Last active April 23, 2018 02:14
Add fallback values to stdtime2integer functions.
#vcl 4.0;
# comment the following imports if imported elsewhere
import cookie;
import header;
import std;
import var;
sub vcl_synth {
if (resp.status == 837) {
@section-io-gists
section-io-gists / varnish-anonymous-wordpress.vcl
Created September 11, 2017 15:49
This Varnish configuration is meant for Wordpress sites where site users are always anonymous.
# Please note: There is an underlying default Varnish behavior that occurs after the VCL logic
# you see below. You can see the bultin code here
# https://github.com/varnishcache/varnish-cache/blob/5.1/bin/varnishd/builtin.vcl
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.
# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;
sub vcl_recv {
# section.io Edge node automatically performs GEO IP (and city) lookup on every request.
# We create a request header called "section-io-geo-country" that you can leverage
if (req.http.section-io-geo-country ~ "^RU$") {
# Block Russia
error 403 "Forbidden";
}
}