vcl 4.1; # https://github.com/varnish/toolbox/tree/master/vcls/hit-miss include "hit-miss.vcl"; # import vmod_dynamic for better backend name resolution import dynamic; import std; backend default { .host = "rstat-dashboard"; .port = "5000"; } acl purge { "localhost"; "nginx"; "127.0.0.1"; } sub vcl_recv { if (req.url ~ "/purge-cache") { if (!client.ip ~ purge) { return(synth(403, "Not allowed.")); } ban("req.http.host == rstat.net"); return(synth(200, "Cache cleared")); } # Cache static files if (req.url ~ "\.(css|js|avif|webp|png|jpe?g|gif|ico|svg|woff2?|eot|ttf|otf|json|csv|pdf|mp4|webm|ogg|mp3|wav|flac)$") { unset req.http.Cookie; return(hash); } # Remove all cookies for other requests unset req.http.Cookie; return(hash); } sub vcl_backend_response { # Cache static files and other content in Varnish for 1 year set beresp.ttl = 1m; # Enable stale content serving set beresp.grace = 24h; # Preserve the origin's Cache-Control header for client-side caching if (beresp.http.Cache-Control) { set beresp.http.X-Orig-Cache-Control = beresp.http.Cache-Control; } } sub vcl_deliver { # Restore the origin's Cache-Control header for the browser if (resp.http.X-Orig-Cache-Control) { set resp.http.Cache-Control = resp.http.X-Orig-Cache-Control; unset resp.http.X-Orig-Cache-Control; } else { # If no Cache-Control was set by the origin, we'll set a default set resp.http.Cache-Control = "no-cache, must-revalidate"; } }