configuration-templates – Diff between revs 2 and 16

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 2 Rev 16
Line 1... Line 1...
1 vcl 4.0; 1 vcl 4.0;
-   2 ###########################################################################
2 # Optimized Varnish VCL for load balancing and caching. 3 ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ##
3 # original: https://github.com/mattiasgeniar/varnish-4.0-configuration-templates/blob/master/default.vcl 4 ## Please see: http://www.gnu.org/licenses/gpl.html for legal details, ##
-   5 ## rights of fair usage, the disclaimer and warranty conditions. ##
-   6 ###########################################################################
4 # modified: Wizardry and Steamworks (http://grimore.org) 7 ## Derived from the original by Mattias Geniar as a starting template. ##
-   8 ###########################################################################
Line 5... Line 9...
5   9  
6 import std; 10 import std;
Line 7... Line 11...
7 import directors; 11 import directors;
Line 99... Line 103...
99 req.method != "PUT" && 103 req.method != "PUT" &&
100 req.method != "POST" && 104 req.method != "POST" &&
101 req.method != "TRACE" && 105 req.method != "TRACE" &&
102 req.method != "OPTIONS" && 106 req.method != "OPTIONS" &&
103 req.method != "PATCH" && 107 req.method != "PATCH" &&
104 req.method != "DELETE") { 108 req.method != "DELETE" &&
-   109 req.method != "PROPFIND" &&
-   110 req.method != "REPORT") {
105 /* Non-RFC2616 or CONNECT which is weird. */ 111 /* Non-RFC2616 or CONNECT which is weird. */
106 return (pipe); 112 return (pipe);
107 } 113 }
Line 108... Line 114...
108   114  
Line 137... Line 143...
137   143  
138 # Some generic cookie manipulation, useful for all templates that follow 144 # Some generic cookie manipulation, useful for all templates that follow
139 # Remove the "has_js" cookie 145 # Remove the "has_js" cookie
Line -... Line 146...
-   146 set req.http.Cookie = regsuball(req.http.Cookie, "has_js=[^;]+(; )?", "");
-   147  
-   148 # Remove any CloudFlare cookies
140 set req.http.Cookie = regsuball(req.http.Cookie, "has_js=[^;]+(; )?", ""); 149 set req.http.Cookie = regsuball(req.http.Cookie, "cf_.=[^;]+(; )?", "");
141   150  
142 # Remove any Google Analytics based cookies 151 # Remove any Google Analytics based cookies
143 set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", ""); 152 set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");
144 set req.http.Cookie = regsuball(req.http.Cookie, "_ga=[^;]+(; )?", ""); 153 set req.http.Cookie = regsuball(req.http.Cookie, "_ga=[^;]+(; )?", "");
Line 185... Line 194...
185   194  
186 # Remove all cookies for static files 195 # Remove all cookies for static files
187 # A valid discussion could be held on this line: do you really need to cache static files that don't cause load? Only if you have memory left. 196 # A valid discussion could be held on this line: do you really need to cache static files that don't cause load? Only if you have memory left.
188 # Sure, there's disk I/O, but chances are your OS will already have these files in their buffers (thus memory). 197 # Sure, there's disk I/O, but chances are your OS will already have these files in their buffers (thus memory).
189 # Before you blindly enable this, have a read here: https://ma.ttias.be/stop-caching-static-files/ 198 # Before you blindly enable this, have a read here: https://ma.ttias.be/stop-caching-static-files/
190 # if (req.url ~ "^[^?]*\.(7z|avi|bmp|bz2|css|csv|doc|docx|eot|flac|flv|gif|gz|ico|jpeg|jpg|js|less|mka|mkv|mov|mp3|mp4|mpeg|mpg|odt|otf|ogg|ogm|opus|pdf|png|ppt|pptx|rar|rtf|svg|svgz|swf|tar|tbz|tgz|ttf|txt|txz|wav|webm|webp|woff|woff2|xls|xlsx|xml|xz|zip)(\?.*)?$") { 199 if (req.url ~ "^[^?]*\.(7z|avi|bmp|bz2|css|csv|doc|docx|eot|flac|flv|gif|gz|ico|jpeg|jpg|js|less|mka|mkv|mov|mp3|mp4|mpeg|mpg|odt|otf|ogg|ogm|opus|pdf|png|ppt|pptx|rar|rtf|svg|svgz|swf|tar|tbz|tgz|ttf|txt|txz|wav|webm|webp|woff|woff2|xls|xlsx|xml|xz|zip)(\?.*)?$") {
191 # unset req.http.Cookie; 200 unset req.http.Cookie;
192 # return (hash); 201 return (hash);
Line 193... Line 202...
193 # } 202 }
194   203  
Line 195... Line 204...
195 # Send Surrogate-Capability headers to announce ESI support to backend 204 # Send Surrogate-Capability headers to announce ESI support to backend
Line 264... Line 273...
264 } 273 }
Line 265... Line 274...
265   274  
266 # https://www.varnish-cache.org/docs/trunk/users-guide/vcl-grace.html 275 # https://www.varnish-cache.org/docs/trunk/users-guide/vcl-grace.html
267 # When several clients are requesting the same page Varnish will send one request to the backend and place the others on hold while fetching one copy from the backend. In some products this is called request coalescing and Varnish does this automatically. 276 # When several clients are requesting the same page Varnish will send one request to the backend and place the others on hold while fetching one copy from the backend. In some products this is called request coalescing and Varnish does this automatically.
268 # If you are serving thousands of hits per second the queue of waiting requests can get huge. There are two potential problems - one is a thundering herd problem - suddenly releasing a thousand threads to serve content might send the load sky high. Secondly - nobody likes to wait. To deal with this we can instruct Varnish to keep the objects in cache beyond their TTL and to serve the waiting requests somewhat stale content. -  
269   277 # If you are serving thousands of hits per second the queue of waiting requests can get huge. There are two potential problems - one is a thundering herd problem - suddenly releasing a thousand threads to serve content might send the load sky high. Secondly - nobody likes to wait. To deal with this we can instruct Varnish to keep the objects in cache beyond their TTL and to serve the waiting requests somewhat stale content.
270 # if (!std.healthy(req.backend_hint) && (obj.ttl + obj.grace > 0s)) { 278 # if (!std.healthy(req.backend_hint) && (obj.ttl + obj.grace > 0s)) {
271 # return (deliver); 279 # return (deliver);
272 # } else { 280 # } else {
273 # return (fetch); 281 # return (fetch);
Line 312... Line 320...
312   320  
313 # Pause ESI request and remove Surrogate-Control header 321 # Pause ESI request and remove Surrogate-Control header
314 if (beresp.http.Surrogate-Control ~ "ESI/1.0") { 322 if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
315 unset beresp.http.Surrogate-Control; 323 unset beresp.http.Surrogate-Control;
-   324 set beresp.do_esi = true;
316 set beresp.do_esi = true; 325 set beresp.ttl = 24h; # Set 24h ESI
Line -... Line 326...
-   326 }
-   327  
-   328 ### Set content expiration.
-   329 ## You may want to disable any expiration on the backend (ie: for Apache, disable mod_expires).
-   330 # 1 Year
-   331 if(beresp.http.content-type ~ "(?i)(application/(javascript|x\-javascript))|(text/(javascript|css))|(application/(atom\+xml|rdf\+xml|rss\+xml))") {
-   332 set beresp.http.Expires = "" + (now + 1y);
-   333 }
-   334 # 1 Month
-   335 if(beresp.http.content-type ~ "(?i)(application/(vnd\.ms\-fontobject|font\-woff|x\-font\-(ttf|woff)))|(audio/ogg)|(font/(eot|opentype|woff))|(image/(bmp|gif|jp2|jpeg|png|svg\+xmlwebp))|(video/(mp4|ogg|webm))") {
-   336 set beresp.http.Expires = "" + (now + 24w);
-   337 }
-   338 # 1 Week
-   339 if(beresp.http.content-type ~ "(?i)(image/(vnd\.microsoft\.icon|x\-icon))|(application/manifest\+json)|(text/x\-cross\-domain\-policy)") {
-   340 set beresp.http.Expires = "" + (now + 1w);
-   341 }
-   342 # Immediately
-   343 # Not exactly "immediately" since we do not want to have to recache on fast reloads - ideally, set this to average page log time.
-   344 if(beresp.http.content-type ~ "(?i)(application/(json|ld\+json|schema\+json|vnd\.geo\+jsonxml|x\-web\-app\-manifest\+json))|(text/(xml|cache\-manifest|html))") {
-   345 set beresp.http.Expires = "" + (now + 3s);
-   346 }
-   347  
317 } 348 ### GZip content if not already compressed.
-   349 ## You may want to disable any compression on the backend (ie: for Apache, disable mod_deflate).
-   350 if(beresp.http.content-type ~ "(?i)(application/(atom\+xml|javascript|json|ld\+json|manifest\+json|rdf\+xml|rss\+xml|schema\+json|vnd\.geo\+json|vnd\.ms\-fontobject|x\-(font\-ttf|javascript|web\-app\-manifest\+json)|xhtml\+xml|xml)|font/(eot|opentype))|(image/(bmp|svg\+xml|vnd\.microsoft\.icon|x\-icon))|(text/(cache\-manifest|css|html|javascript|plain|vcard|vnd\.rim\.location\.xloc|vcalendar|vtt|x\-component|x\-cross\-domain\-policy|xml))") {
-   351 # Compress object for sending.
-   352 set beresp.do_gzip = true;
-   353 }
318   354  
319 # Enable cache for all static files 355 ### Enable cache for all static files
320 # The same argument as the static caches from above: monitor your cache size, if you get data nuked out of it, consider giving up the static file cache. 356 ## The same argument as the static caches from above: monitor your cache size, if you get data nuked out of it, consider giving up the static file cache.
321 # Before you blindly enable this, have a read here: https://ma.ttias.be/stop-caching-static-files/ 357 ## Before you blindly enable this, have a read here: https://ma.ttias.be/stop-caching-static-files/
322 if (bereq.url ~ "^[^?]*\.(7z|avi|bmp|bz2|css|csv|doc|docx|eot|flac|flv|gif|gz|ico|jpeg|jpg|js|less|mka|mkv|mov|mp3|mp4|mpeg|mpg|odt|otf|ogg|ogm|opus|pdf|png|ppt|pptx|rar|rtf|svg|svgz|swf|tar|tbz|tgz|ttf|txt|txz|wav|webm|webp|woff|woff2|xls|xlsx|xml|xz|zip)(\?.*)?$") { 358 if(beresp.http.content-type ~ "(?i)(application/(java\-vm|javascript|json|msword|pdf|postscript|rtf|vnd\.ms\-(excel|fontobject|powerpoint)|vnd\.oasis\.opendocument\.text|vnd\.openxmlformats\-officedocument\.(presentationml\.presentation|spreadsheetml\.sheet|wordprocessingml\.document)|x\-(7z\-compressed|bzip2|gzip|rar\-compressed|shockwave\-flash|tar)|x\-font\-(bdf|ghostscript|linux\-psf|otf|pcf|snf|ttf|type1|woff)|xz|xml|zip))|(audio/((mpeg|ogg)|(x\-(flac|matroska|ms\-wma|wav))))|(image/((bmp|gif|jp2|jpeg|png|svg\+xml|vnd\.wap\.wbmp|webp|x\-(icon|pict))))|(text/((css|csv|javascript|plain)))|(video/((mp4|quicktime|webm|x\-(flv|matroska|ms\-wmv|msvideo))))") {
Line 323... Line 359...
323 unset beresp.http.set-cookie; 359 unset beresp.http.set-cookie;
324 } 360 }
325   361  
326 # Large static files are delivered directly to the end-user without 362 # Large static files are delivered directly to the end-user without
327 # waiting for Varnish to fully read the file first. 363 # waiting for Varnish to fully read the file first.
328 # Varnish 4 fully supports Streaming, so use streaming here to avoid locking. 364 # Varnish 4 fully supports Streaming, so use streaming here to avoid locking.
329 if (bereq.url ~ "^[^?]*\.(7z|avi|bz2|flac|flv|gz|mka|mkv|mov|mp3|mp4|mpeg|mpg|ogg|ogm|opus|rar|tar|tgz|tbz|txz|wav|webm|xz|zip)(\?.*)?$") { 365 if (bereq.url ~ "^[^?]*\.(7z|ace|avi|bin|bz2|flac|flv|gz|iso|mka|mkv|mov|mp3|mp4|mpeg|mpg|ogg|ogm|opus|rar|tar|tgz|tbz|txz|wav|webm|wma|wmv|xz|zip)(\?.*)?$") {
Line 330... Line 366...
330 unset beresp.http.set-cookie; 366 unset beresp.http.set-cookie;