Skip to content

Instantly share code, notes, and snippets.

Avatar

section-io-gists

View GitHub Profile
@section-io-gists
section-io-gists / Varnish 4.0: Add HTTP response headers to indicate cache hit or miss
Last active Aug 29, 2015
Varnish 4.0: Add HTTP response headers to indicate cache hit/miss
View Varnish 4.0: Add HTTP response headers to indicate cache hit or miss
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
@section-io-gists
section-io-gists / normaliseAcceptEncoding.vcl
Created Jul 2, 2015
section.io VCL - Normalise Accept Encoding
View normaliseAcceptEncoding.vcl
#section.io VCL sample. Copy paste into your section.io account to implement instantly
#vcl_recv - copy this code into the section called sub vcl_recv
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
unset req.http.Accept-Encoding;
View geoIPLookup.vcl
#section.io VCL sample. Copy paste into your section.io account to implement instantly
#This code example requires you to use a Varnish version that has the GEO IP vmod installed
#Import vmod to do geoip on requests
import geoip;
#vcl_recv - copy this code into the section called sub vcl_recv
set req.http.X-Country-Code = geoip.country_code(regsub(req.http.X-Forwarded-For, ",.*",""));
View enforce_https.vcl
sub vcl_recv {
//Use req.proto instead of req.http.X-Forwarded-Proto if your varnish server isn't behind a load balancer
if ( req.http.X-Forwarded-Proto !~ "(?i)https") {
//The 750 number is arbitrary, you just need a unique number to check for in the vcl_synth sub
return (synth(750, ""));
}
}
sub vcl_synth {
if (resp.status == 750) {
@section-io-gists
section-io-gists / block_access.vcl
Created Aug 14, 2015
Block access to your site with VCL
View block_access.vcl
sub vcl_recv {
if (req.http.User-Agent ~ "(?i)ima-naughty-bot") {
return (synth(403, "Forbidden"));
}
}
@section-io-gists
section-io-gists / cacheEverything.vcl
Created Sep 11, 2015
Cache both static and dynamic content (Great for sites with no personalisation)
View cacheEverything.vcl
#section.io VCL sample. Copy paste into your section.io account to implement instantly
#vcl_recv - copy this code into the section called sub vcl_recv
#Normalise Accept-Encoding
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
@section-io-gists
section-io-gists / ISEPureVarnish
Last active Sep 23, 2015
section.io ISE template (for Magento)
View ISEPureVarnish
# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
#
backend default {
.host = "next-hop";
.port = "80";
.first_byte_timeout = 300s;
@section-io-gists
section-io-gists / starterConfig.vcl
Last active Jan 27, 2016
section.io VCL - Starter Config
View starterConfig.vcl
#section.io VCL sample. Copy paste into your section.io account to implement instantly
#vcl_recv - copy this code into the section called sub vcl_recv
if (req.url ~ ".*\.(?:css|js|jpe?g|png|gif|ico|swf)(?=\?|&|$)") {
unset req.http.Cookie;
#Varnish <= 3.x calls this "return (lookup);"
return (hash);
}
#vcl_backend_response - copy this code into the section called sub vcl_backend_response
@section-io-gists
section-io-gists / performanceConfig.vcl
Last active Jan 27, 2016
section.io VCL - Performance Config
View performanceConfig.vcl
#section.io VCL sample. Copy paste into your section.io account to implement instantly
#vcl_recv - copy this code into the section called sub vcl_recv
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
unset req.http.Accept-Encoding;
View section.config.json
{
"proxychain": [
{
"name": "varnish",
"image": "varnish:4.0.3"
}
],
"environments": {
"Production": {
"origin": {