Created
September 3, 2013 20:27
-
-
Save mishudark/6429103 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Varnisch VCL file for the boundaries.minnpost.com site. | |
| # | |
| # Borrowed from http://ghughes.com/blog/2011/11/11/using-varnish-with-django-for-high-performance-caching/ | |
| # Default backend definition. Set this to point to your content | |
| # server. | |
| # | |
| backend default { | |
| .host = "127.0.0.1"; | |
| .port = "8080"; | |
| } | |
| sub vcl_recv { | |
| # unless sessionid/csrftoken is in the request, don't pass ANY cookies (referral_source, utm, etc) | |
| if (req.request == "GET" && (req.url ~ "^/static" || (req.http.cookie !~ "sessionid" && req.http.cookie !~ "csrftoken"))) { | |
| remove req.http.Cookie; | |
| } | |
| #remove google analytics cookies | |
| set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js|NO_CACHE)=[^;]*", ""); | |
| if (req.http.Cookie == "") { | |
| unset req.http.Cookie; | |
| } | |
| if (req.http.Authorization) { | |
| return (pass); | |
| } | |
| # Pass login | |
| if (req.url ~ "login") { | |
| return (pass); | |
| } | |
| if (req.url ~ "password") { | |
| return (pass); | |
| } | |
| if (req.url ~ "register") { | |
| return (pass); | |
| } | |
| # 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 { | |
| # static files always cached | |
| if (req.url ~ "^/static") { | |
| unset beresp.http.set-cookie; | |
| return (deliver); | |
| } | |
| # pass through for anything with a session/csrftoken set | |
| if (beresp.http.set-cookie ~ "sessionid" || beresp.http.set-cookie ~ "csrftoken") { | |
| 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