I needed a small VCL for caching assets in Varnish. I used some tutorials and documentation to come to this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
It basically unsets cookies for all static contents, so Varnish can cache it. In the vcl_fetch it unsets the server that served the request and the X-Powered-By header to hide the PHP-Version. Then it checks if the request was for an image or an CSS/JS File and writes new TTL-headers and sets the Varnish keep time to cache images for 2 hours, for CSS/JS 4 hours. The vcl_recv also contains a rule to check for certain cookies to keep them and drop the ones not nessecary. With that rule we enable Varnish to cache content for anonymous users, altough we use Google Analytics / other analytics tools. (Varnish doesnt cache requests containing Cookies).