Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wsaribeiro/4a3fe19863363253d3c0 to your computer and use it in GitHub Desktop.
Save wsaribeiro/4a3fe19863363253d3c0 to your computer and use it in GitHub Desktop.
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 60s;
.connect_timeout = 60s;
.between_bytes_timeout = 60s;
.max_connections = 200;
}
sub vcl_recv {
unset req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;
if (req.http.Cookie && req.http.Cookie ~ "wordpress_") {
return (pass);
}
# Post requests will not be cached
if (req.http.Authorization || req.request == "POST") {
return (pass);
}
# Don't cache urls with nocache
if (req.url ~ "nocache") {
return (pass);
}
# Don't cache previews
if (req.url ~ "preview=true") {
return (pass);
}
if (req.url ~ "^/wp-(login|admin)") {
return (pass);
}
#Serve stale cache objects for up to 2 minutes if the backend is down
set req.grace = 120s;
unset req.http.cookie;
}
sub vcl_fetch {
if (!(req.url ~ "^/wp-(login|admin)")) {
unset beresp.http.set-cookie;
}
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment