This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"proxychain": [ | |
{ | |
"name": "varnish", | |
"image": "varnish:4.0.3" | |
} | |
], | |
"environments": { | |
"Production": { | |
"origin": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- Rule engine initialization ---------------------------------------------- | |
# Enable ModSecurity, attaching it to every transaction. Use detection | |
# only to start with, because that minimises the chances of post-installation | |
# disruption. | |
# | |
#SecRuleEngine DetectionOnly | |
SecRuleEngine On |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub vcl_hash { | |
#Vary cache by protocol type to avoid caching things like HTTP->HTTPS redirects and different versions of files | |
hash_data(req.http.X-Forwarded-Proto); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Varnish 4 config below | |
sub vcl_recv { | |
#Add font files to be cached as static caching checkbox misses .woff | |
if (req.url ~ ".*\.(?:css|js|jpe?g|png|gif|ico|swf|woff)(?=\?|&|$)") { | |
return (hash); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: You will want to add the snippet: `include "pagespeed-requirement.vcl";` above your `vcl_recv` in the default.vcl file. | |
sub vcl_recv { | |
call pagespeed_capability_detection; | |
} | |
# Function derived from requirements here https://modpagespeed.com/doc/downstream-caching#ps-capabilitylist | |
# Additional detection logic for crawlers, tablet and mobile devices. | |
sub pagespeed_capability_detection { | |
if (req.http.User-Agent ~ "(?i)Chrome/[3][2-9]+\.|Chrome/[4-9][0-9]+\.|Chrome/[0-9]{3,}\.") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std; | |
acl whitelist { | |
"123.123.123.123"; | |
"216.3.128.12"; | |
} | |
sub vcl_recv { | |
# If not a whitelisted IP, then display maintenance page. Requires std library. | |
if(std.ip(regsub(req.http.X-Forwarded-For, "[, ].*$", ""), client.ip) !~ whitelist) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub vcl_recv { | |
if (req.http.X-Forwarded-Proto !~ "https") { | |
return (synth(850, "Moved Permanently")); | |
} | |
} | |
sub vcl_synth { | |
if(resp.status == 850) { | |
set resp.http.Location = "https://" + req.http.host + req.url; | |
set resp.status = 301; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub vcl_recv { | |
if (req.http.X-Forwarded-Proto !~ "https") { | |
error 850 "Moved permenantly"; | |
} | |
} | |
sub vcl_error { | |
if(obj.status == 850) { | |
set obj.http.Location = "https://" + req.http.host + req.url; | |
set obj.status = 301; |