Skip to content

Instantly share code, notes, and snippets.

@bosim
Last active August 25, 2016 06:33
Show Gist options
  • Save bosim/3944980 to your computer and use it in GitHub Desktop.
Save bosim/3944980 to your computer and use it in GitHub Desktop.
Basic varnish configuration for Plone
acl purge {
"localhost";
}
director plone_director round-robin {
{
.backend = {
.host = "127.0.0.1";
.port = "50020";
.probe = {
.url = "/site/alive";
.timeout = 6s;
.interval = 6s;
.window = 3;
.threshold = 3;
}
}
}
{
.backend = {
.host = "127.0.0.1";
.port = "50021";
.probe = {
.url = "/site/alive";
.timeout = 6s;
.interval = 6s;
.window = 3;
.threshold = 3;
}
}
}
}
sub vcl_recv {
set req.url = "/VirtualHostBase/http/fivu-www.headprod.dk:80/site/VirtualHostRoot" req.url;
set req.backend = plone_director;
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
return (lookup);
}
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For ", " client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
return (pass);
}
set req.grace = 15s;
return (lookup);
}
sub vcl_pipe {
return (pipe);
}
sub vcl_pass {
return (pass);
}
sub vcl_hash {
set req.hash += req.url;
if (req.http.host) {
set req.hash += req.http.host;
} else {
set req.hash += server.ip;
}
return (hash);
}
sub vcl_hit {
if (req.request == "PURGE") {
purge_url(req.url);
error 200 "Purged.";
}
if (!obj.cacheable) {
return (pass);
}
return (deliver);
}
sub vcl_miss {
if (req.request == "PURGE") {
purge_url(req.url);
error 200 "Purged.";
}
return (fetch);
}
sub vcl_fetch {
if (!beresp.cacheable) {
return (pass);
}
if (beresp.http.Set-Cookie) {
return (pass);
}
set beresp.ttl = 45s;
set beresp.grace = 15s;
return (deliver);
}
sub vcl_deliver {
return (deliver);
}
sub vcl_error {
set obj.http.Content-Type = "text/html; charset=utf-8";
synthetic {"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>"} obj.status " " obj.response {"</title>
</head>
<body>
<h1>Error "} obj.status " " obj.response {"</h1>
<p>"} obj.response {"</p>
<h3>Guru Meditation:</h3>
<p>XID: "} req.xid {"</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>
"};
return (deliver);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment