Skip to content

Instantly share code, notes, and snippets.

@arfaram
Last active April 3, 2022 11:58
Show Gist options
  • Save arfaram/54f01793f7224f2be751829faa35b1f4 to your computer and use it in GitHub Desktop.
Save arfaram/54f01793f7224f2be751829faa35b1f4 to your computer and use it in GitHub Desktop.
Varnish 6 cache static files

vcl:

sub vcl_backend_response {

    //..

# For static content strip all backend cookies and push to static storage
        if (bereq.url ~ "\.(css|js|png|gif|jp(e?)g)|swf|ico") {
                unset beresp.http.cookie;
                set beresp.storage = storage.static;
                set beresp.http.x-storage = "static";
        } else {
                set beresp.storage = storage.default;
                set beresp.http.x-storage = "default";
        }

}

start varnishd using:

varnishd ... -s static=file,/var/lib/varnish/varnish_storage.bin,1G -s default=malloc,512m

more infos: https://www.getpagespeed.com/server-setup/varnish-static-files-cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment