Skip to content

Instantly share code, notes, and snippets.

Avatar

section-io-gists

View GitHub Profile
View SharedSecretVCL4.0
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
View AnonymousHTMLcachingVCL3.vcl
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") {
View AnonymousHTMLcachingPseudoCode
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 {
View AnonymousHTMLcachingVCL4.vcl
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 Oct 9, 2017
Language header based on country code.
View language-header.vcl
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
Created Oct 3, 2017
Redirect from bare domain to www site in VCL3
View bareDomainRedirectVCL3.vcl
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 Feb 15, 2018
Redirect from bare domain to www site in VCL4.0
View bareDomainRedirectVCL4.vcl
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 Apr 23, 2018
Add fallback values to stdtime2integer functions.
View section-user-throttling.vcl
#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 Sep 11, 2017
This Varnish configuration is meant for Wordpress sites where site users are always anonymous.
View varnish-anonymous-wordpress.vcl
# 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;
View GEOIPblock.vcl Varnish 3.0.5
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";
}
}