72 lines
1.8 KiB
Plaintext
72 lines
1.8 KiB
Plaintext
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 = "ghost";
|
|
.port = "2368";
|
|
}
|
|
|
|
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 == its.pkhamre.com");
|
|
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);
|
|
}
|
|
|
|
# Don't cache if these cookies are present
|
|
if (req.http.Cookie ~ "ghost-members-ssr" || req.http.Cookie ~ "ghost-admin-api-session") {
|
|
return(pass);
|
|
}
|
|
|
|
# Don't cache these paths
|
|
if (req.url ~ "^/(ghost|members|p)/") {
|
|
return(pass);
|
|
}
|
|
|
|
# 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 = 1y;
|
|
# 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";
|
|
}
|
|
}
|