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 { | |
# Happens before we check if we have this in cache already. | |
# | |
# Typically you clean up the request here, removing cookies you don't need, | |
# rewriting the request, etc. | |
if (req.method != "GET" && req.method != "HEAD" && req.method != "PURGE") { | |
return (pass); | |
} | |
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
#Example of HTML Streaming. This gist involves both Varnish and nginx LUA reverse proxies | |
#Varnish: | |
sub vcl_recv { | |
# Do not stream on non-get requests | |
if (req.method != "GET" && req.method != "HEAD" && req.method != "PURGE") { | |
return (pass); | |
} | |
# By defaul disable holepunch unless below cases fall through (do not modify this line) |
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 { | |
# Strip browser side tracking script to improve cache hit rate | |
if (req.url ~ "[?&](utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl|mc_cid|mc_eid)=") { | |
set req.url = regsuball(req.url, "(?:(\?)?|&)(?:utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl|mc_cid|mc_eid)=[^&]+", "\1"); | |
set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1"); | |
} | |
} |
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 { | |
# 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 ~ "^(AU|NZ)$") { | |
# Australia and New Zealand | |
#return (synth(802, "https://www.domain.com.au/")); | |
} else if (req.http.section-io-geo-country ~ "^(US|CA|MX)$") { | |
# US, Canada and Mexico | |
#return (synth(802, "http://www.domain.com/")); |
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; |
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
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
# 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
#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
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); | |
} |