Last active
December 20, 2015 01:29
-
-
Save dmouse/6049440 to your computer and use it in GitHub Desktop.
varnish Drupal 7 configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
acl internal { | |
"127.0.0.0"/24; | |
} | |
backend web1 { .host = "192.168.1.1"; } | |
backend web2 { .host = "192.168.1.2"; } | |
director default_director round-robin { | |
{ .backend = web1; } | |
{ .backend = web2; } | |
} | |
sub vcl_recv { | |
set req.backend = default_director; | |
if (!req.backend.healthy) { | |
unset req.http.Cookie; | |
} | |
set req.grace = 6h; | |
if (req.url ~ "^/status\.php$" || | |
req.url ~ "^/phpmyadmin/.*$" || | |
req.url ~ "^/update\.php$" || | |
req.url ~ "^/admin/build/features" || | |
req.url ~ "^/info/.*$" || | |
req.url ~ "^/flag/.*$" || | |
req.url ~ "^.*/ajax/.*$" || | |
req.url ~ "^.*/ahah/.*$") { | |
return (pass); | |
} | |
if (req.url ~ "^/admin/content/backup_migrate/export") { | |
return (pipe); | |
} | |
if (req.url ~ "^/(cron|install)\.php$" && !client.ip ~ internal) { | |
error 404 "Page not found."; | |
} | |
if (req.http.Accept-Encoding) { | |
if (req.http.Accept-Encoding ~ "gzip") { | |
set req.http.Accept-Encoding = "gzip"; | |
} | |
else if (req.http.Accept-Encoding ~ "deflate") { | |
set req.http.Accept-Encoding = "deflate"; | |
} | |
else { | |
unset req.http.Accept-Encoding; | |
} | |
} | |
if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm)(\?[a-z0-9]+)?$") { | |
unset req.http.Cookie; | |
} | |
if (req.http.Cookie) { | |
set req.http.Cookie = ";" + req.http.Cookie; | |
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";"); | |
set req.http.Cookie = regsuball(req.http.Cookie, ";(SESS[a-z0-9]+|NO_CACHE)=", "; \1="); | |
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", ""); | |
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", ""); | |
if (req.http.Cookie == "") { | |
unset req.http.Cookie; | |
} | |
else { | |
return (pass); | |
} | |
} | |
} | |
sub vcl_hash { | |
# Include cookie in cache hash. | |
# This check is unnecessary because we already pass on all cookies. | |
# if (req.http.Cookie) { | |
# set req.hash += req.http.Cookie; | |
# } | |
} | |
sub vcl_fetch { | |
if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm)(\?[a-z0-9]+)?$") { | |
unset beresp.http.set-cookie; | |
} | |
set beresp.grace = 6h; | |
} | |
sub vcl_error { | |
#if (req.url ~ "^/?$") { | |
# set obj.status = 302; | |
# set obj.http.Location = "http://www2.drupalsite.com/"; | |
#} | |
set obj.http.Content-Type = "text/html; charset=utf-8"; | |
synthetic {" | |
<html> | |
<head> | |
<title>Page Unavailable</title> | |
<style> | |
body { background: #53B1EA; text-align: center; color: white; } | |
#page { border: 1px solid #CCC; width: 500px; margin: 100px auto 0; padding: 30px; } | |
a, a:link, a:visited { color: #CCC; } | |
.error { color: #222; } | |
</style> | |
</head> | |
<body onload="setTimeout(function() { window.location = '/' }, 5000)"> | |
<div id="page"> | |
<h1 class="title">Page Unavailable</h1> | |
<p>The page you requested is temporarily unavailable.</p> | |
<p>We're redirecting you to the <a href="/">homepage</a> in 5 seconds.</p> | |
<div class="error">(Error "} + obj.status + " " + obj.response + {")</div> | |
</div> | |
</body> | |
</html> | |
"}; | |
return (deliver); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment