Skip to content

Instantly share code, notes, and snippets.

@andrewnimmo
Forked from joseluisq/default.vcl
Created April 13, 2019 20:20
Show Gist options
  • Save andrewnimmo/30c0376017dad73d886799c2b3ceb1f8 to your computer and use it in GitHub Desktop.
Save andrewnimmo/30c0376017dad73d886799c2b3ceb1f8 to your computer and use it in GitHub Desktop.
Varnish Cache v3 configuration for subdomains
# Customizing Varnish Cache for subdomains
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
# If exists any trouble, disable the cookie
if (!req.backend.healthy) {
unset req.http.Cookie;
}
# No-Cache: "nocache.domain.com"
if (req.http.host ~ "nocache\.domain\.com") {
return(pass);
}
# Cache: "domain.com", "cache.domain.com" and "cdn.domain.com"
if (req.http.host ~ "(^((cache|cdn)\.)?domain\.com)$") {
if (req.url ~ "\.(png|gif|jpg|swf|css|js|svg|eot|ttf|otf|ttc|webm|woff|woff2|mp3|mp4|ogg|flv|ogv|m4v|oga|pdf|csv|xls|xlsx|doc|docx|ppt|pptx|txt)$") {
unset req.http.Cookie;
return(lookup);
}
}
}
sub vcl_fetch {
# Unset cookie: "domain.com", "cache.domain.com" and "cdn.domain.com"
if (req.http.host ~ "(^((cache|cdn)\.)?domain\.com)$") {
if (req.url ~ "\.(png|gif|jpg|swf|css|js|svg|eot|ttf|otf|ttc|webm|woff|woff2|mp3|mp4|ogg|flv|ogv|m4v|oga|pdf|csv|xls|xlsx|doc|docx|ppt|pptx|txt)$") {
unset beresp.http.set-cookie;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment