Last active
May 20, 2019 18:16
-
-
Save hoffmannkrzysztof/10595779 to your computer and use it in GitHub Desktop.
Varnish config for django
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
# Default backend definition. Set this to point to your content | |
# server. | |
# | |
backend web { | |
.host = "127.0.0.1"; | |
.port = "8080"; | |
} | |
sub vcl_recv { | |
# unless sessionid is in the request, don't pass ANY cookies (referral_source, utm, etc) | |
if (req.request == "GET" && (req.url ~ "^/(static|media)" || (req.http.cookie !~ "sessionid" ) ) ) { | |
remove req.http.Cookie; | |
} | |
# normalize accept-encoding to account for different browsers | |
# see: https://www.varnish-cache.org/trac/wiki/VCLExampleNormalizeAcceptEncoding | |
if (req.http.Accept-Encoding) { | |
if (req.http.Accept-Encoding ~ "gzip") { | |
set req.http.Accept-Encoding = "gzip"; | |
} elsif (req.http.Accept-Encoding ~ "deflate") { | |
set req.http.Accept-Encoding = "deflate"; | |
} else { | |
# unknown algorithm | |
remove req.http.Accept-Encoding; | |
} | |
} | |
} | |
sub vcl_fetch { | |
set beresp.http.X-Backend = beresp.backend.name; | |
set beresp.ttl = 15m; | |
# static files always cached | |
if (req.url ~ "^/(static|media)") { | |
unset beresp.http.set-cookie; | |
set beresp.ttl = 24 h; | |
return (deliver); | |
} | |
# pass through for anything with a session/csrftoken set | |
if (beresp.http.set-cookie ~ "sessionid") { | |
return (hit_for_pass); | |
} else { | |
return (deliver); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment