Sweet. One more question. <br>
<br>
Currently. I'm testing my varnish environment, everything seems to be
working fine except one thing. I would like my cache to update every 30
seconds if the backend is healthy and serve stale content if the
backend goes down.<br>
<br>
The content is served perfectly when the backend is down, however the
cache is not updating every 30 seconds if the backend is healthy. Could
someone have a look at my config below and tell me what I'm missing?<br><br>Please and thank you<br>
<br>
=====================================<br>
# Define the internal network subnet.<br>
# These are used below to allow internal access to certain files while not<br>
# allowing access from the public internet.<br>
acl internal {<br>
"192.10.0.0"/24;<br>
}<br>
<br>
# Define the list of backends (web servers).<br>
# Port 80 Backend Servers<br>
backend web1 { .host = "<a href="http://testing.com">testing.com</a>"; .probe = { .url = "/"; .interval = 5s; .timeout = 1s; .window = 5;.threshold = 3; }}<br>
backend web2 { .host = "<a href="http://testing.com">testing.com</a>"; .probe = { .url = "/"; .interval = 5s; .timeout = 1s; .window = 5;.threshold = 3; }}<br>
<br>
# Port 443 Backend Servers for SSL<br>
backend web1_ssl { .host = "<a href="http://testing.com">testing.com</a>"; .port = "443"; .probe = { .url
= "/"; .interval = 5s; .timeout = 5s; .window = 5;.threshold = 3; }}<br>
backend web2_ssl { .host = "<a href="http://testing.com">testing.com</a>"; .port = "443"; .probe = { .url
= "/"; .interval = 5s; .timeout = 5s; .window = 5;.threshold = 3; }}<br>
<br>
# Define the director that determines how to distribute incoming requests.<br>
director default_director round-robin {<br>
{ .backend = web1; }<br>
{ .backend = web2; }<br>
}<br>
<br>
director ssl_director round-robin {<br>
{ .backend = web1_ssl; }<br>
{ .backend = web2_ssl; }<br>
}<br>
<br>
# Respond to incoming requests.<br>
sub vcl_recv {<br>
# Allow the backend to serve up stale content if it is responding slowly.<br>
if (req.backend.healthy) {<br>
<br>
set req.grace = 30s;<br>
<br>
} else {<br>
set req.grace = 5h;<br>
}<br>
}<br>
<br>
<br>
# Code determining what to do when serving items from the Apache servers.<br>
sub vcl_fetch {<br>
# Allow items to be stale if needed.<br>
set beresp.grace = 6h;<br>
set beresp.ttl = 12h;<br>
}<br>
<br>
# Respond to incoming requests.<br>
sub vcl_recv {<br>
# Set the director to cycle between web servers.<br>
if (server.port == 443) {<br>
set req.backend = ssl_director;<br>
}<br>
else {<br>
set req.backend = default_director;<br>
}<br>
<br>
# Use anonymous, cached pages if all backends are down.<br>
if (!req.backend.healthy) {<br>
unset req.http.Cookie;<br>
}<br>
<br>
# Allow the backend to serve up stale content if it is responding slowly.<br>
set req.grace = 6h;<br>
<br>
# Do not cache these paths.<br>
if (req.url ~ "^/status\.php$" ||<br>
req.url ~ "^/update\.php$" ||<br>
req.url ~ "^/ooyala/ping$" ||<br>
req.url ~ "^/admin/build/features" ||<br>
req.url ~ "^/info/.*$" ||<br>
req.url ~ "^/flag/.*$" ||<br>
req.url ~ "^.*/ajax/.*$" ||<br>
req.url ~ "^.*/ahah/.*$") {<br>
return (pass);<br>
}<br>
<br>
# Pipe these paths directly to Apache for streaming.<br>
if (req.url ~ "^/admin/content/backup_migrate/export") {<br>
return (pipe);<br>
}<br>
<br>
# Do not allow outside access to cron.php or install.php.<br>
if (req.url ~ "^/(cron|install)\.php$" && !client.ip ~ internal) {<br>
# Have Varnish throw the error directly.<br>
error 404 "Page not found.";<br>
# Use a custom error page that you've defined in Drupal at the path "404".<br>
# set req.url = "/404";<br>
}<br>
<br>
# Handle compression correctly. Different browsers send different<br>
# "Accept-Encoding" headers, even though they mostly all support the same<br>
# compression mechanisms. By consolidating these compression headers into<br>
# a consistent format, we can reduce the size of the cache and get more hits.=<br>
# @see: http:// <a href="http://varnish.projects.linpro.no/wiki/FAQ/Compression">varnish.projects.linpro.no/wiki/FAQ/Compression</a><br>
if (req.http.Accept-Encoding) {<br>
if (req.http.Accept-Encoding ~ "gzip") {<br>
# If the browser supports it, we'll use gzip.<br>
set req.http.Accept-Encoding = "gzip";<br>
}<br>
else if (req.http.Accept-Encoding ~ "deflate") {<br>
# Next, try deflate if it is supported.<br>
set req.http.Accept-Encoding = "deflate";<br>
}<br>
else {<br>
# Unknown algorithm. Remove it and send unencoded.<br>
unset req.http.Accept-Encoding;<br>
}<br>
}<br>
<br>
# Always cache the following file types for all users.<br>
if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm)(\?[a-z0-9]+)?$") {<br>
unset req.http.Cookie;<br>
}<br>
<br>
# Remove all cookies that Drupal doesn't need to know about. ANY remaining<br>
# cookie will cause the request to pass-through to Apache. For the most part<br>
# we always set the NO_CACHE cookie after any POST request, disabling the<br>
# Varnish cache temporarily. The session cookie allows all authenticated users<br>
# to pass through as long as they're logged in.<br>
if (req.http.Cookie) {<br>
set req.http.Cookie = ";" + req.http.Cookie;<br>
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");<br>
set req.http.Cookie = regsuball(req.http.Cookie, ";(SESS[a-z0-9]+|NO_CACHE)=", "; \1=");<br>
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");<br>
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");<br>
<br>
if (req.http.Cookie == "") {<br>
# If there are no remaining cookies, remove the cookie header. If there<br>
# aren't any cookie headers, Varnish's default behavior will be to cache<br>
# the page.<br>
unset req.http.Cookie;<br>
}<br>
else {<br>
# If there is any cookies left (a session or NO_CACHE cookie), do not<br>
# cache the page. Pass it on to Apache directly.<br>
return (pass);<br>
}<br>
}<br>
}<br>
<br>
# Routine used to determine the cache key if storing/retrieving a cached page.<br>
sub vcl_hash {<br>
# Include cookie in cache hash.<br>
# This check is unnecessary because we already pass on all cookies.<br>
# if (req.http.Cookie) {<br>
# set req.hash += req.http.Cookie;<br>
# }<br>
}<br>
<br>
# Code determining what to do when serving items from the Apache servers.<br>
sub vcl_fetch {<br>
# Don't allow static files to set cookies.<br>
if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm)(\?[a-z0-9]+)?$") {<br>
# beresp == Back-end response from the web server.<br>
unset beresp.http.set-cookie;<br>
}<br>
<br>
# Allow items to be stale if needed.<br>
set beresp.grace = 6h;<br>
}<br>
<br>
# In the event of an error, show friendlier messages.<br>
sub vcl_error {<br>
# Redirect to some other URL in the case of a homepage failure.<br>
#if (req.url ~ "^/?$") {<br>
# set obj.status = 302;<br>
# set obj.http.Location = "<a href="http://backup.example.com/">http://backup.example.com/</a>";<br>
#}<br>
<br>
# Otherwise redirect to the homepage, which will likely be in the cache.<br>
set obj.http.Content-Type = "text/html; charset=utf-8";<br>
synthetic {"<br>
<html><br>
<head><br>
<title>Page Unavailable</title><br>
<style><br>
body { background: #303030; text-align: center; color: white; }<br>
#page { border: 1px solid #CCC; width: 500px; margin: 100px auto 0; padding: 30px; background: #323232; }<br>
a, a:link, a:visited { color: #CCC; }<br>
.error { color: #222; }<br>
</style><br>
</head><br>
<body onload="setTimeout(function() { window.location = '/' }, 5000)"><br>
<div id="page"><br>
<h1 class="title">Page Unavailable</h1><br>
<p>The page you requested is temporarily unavailable.</p><br>
<p>We're redirecting you to the <a href="/">homepage</a> in 5 seconds.</p><br>
<div class="error">(Error "} + obj.status + " " + obj.response + {")</div><br>
</div><br>
</body><br>
</html><br>
"};<br>
return (deliver);<br>
}<br>
===================================<br>
<br>
Cheers<br>
<br>
Nick Tailor