Monitoring Varnish:
varnishtop: grouped list with the most usual entries from different logs.
varnishhist: a histogram that shows the time taken for the requests processing.
varnishsizes: it performs the same task as “varnishhist” but showing the size of the objects.
varnishstat: it shows many contents on cache hits, resource consumption, etc..
varnishlog: it allows us to see all the requests made to the web backend server.
Installing on Ubuntu
http://www.makeyouadmin.com/2014/10/install-varnish-cache-server-ubuntu.html
Configuring default.vcl for Wordpress:
http://www.makeyouadmin.com/2014/11/optimize-varnish-cache-server-wordpress-blog.html#comment-196
This didn't quite work for me so I used this more simple setup to start off with:
http://sharadchhetri.com/2013/09/30/varnish-vcl-file-wordpress/
A base setup to get you started:
backend default {
.host = "127.0.0.1";
.port = "8880";
}
##################################################
sub vcl_recv {
if (req.restarts == 0) {
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 == "PURGE") {
if ( client.ip != "192.241.190.251") {
error 405 "Not allowed.";
}
return (lookup);
}
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.url ~ "wp-(login|admin)") &&
!(req.url ~ "&preview=true" ) ) {
unset req.http.cookie;
}
if (req.http.Authorization || req.http.Cookie) {
return (pass);
}
return (lookup);
}
sub vcl_fetch {
if (!(req.url ~ "wp-(login|admin)")) {
unset beresp.http.set-cookie;
set beresp.ttl = 96h;
}
if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Vary == "*") {
set beresp.ttl = 120 s;
return (hit_for_pass);
}
return (deliver);
}
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
return (deliver);
}
sub vcl_miss {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
return (fetch);
}
Resolving the missing dashboard issue (needs purge) - a working config with wordpress:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
acl purge {
"localhost";
"41.185.26.155";
}
sub vcl_recv {
# Allow purging
if(req.request == "PURGE"){
if(!client.ip ~ purge){
error 405 "Purging not allowed.";
}
return(lookup);
}
# Always cache the following file types for all users.
if ( req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm)(\?[a-z0-9]+)?$" ) {
unset req.http.cookie;
}
# Don't serve cached pages to logged in users
if ( req.http.cookie ~ "wordpress_logged_in" || req.url ~ "vaultpress=true" ) {
return( pass );
}
# Drop any cookies sent to WordPress.
if ( ! ( req.url ~ "wp-(login|admin)" ) ) {
unset req.http.cookie;
}
# File type that we will always cache
if (req.request == "GET" && req.url ~ "\.(gif|jpg|css|swf|js|png|jpg|jpeg|gif|png|tiff|tif|svg|swf|ico|js|vsd|doc|ppt|pps|xls|pdf|mp3|mp4|m4a|ogg|mov|avi|wmv|sxw|zip|gz|bz2|tgz|tar|rar|odc|odb|odf|odg|odi|odp|ods|odt|sxc|sxd|sxi|sxw|dmg|torrent|deb|msi|iso|rpm)$") {
return(lookup);
}
# Handle compression correctly. Different browsers send different
# "Accept-Encoding" headers, even though they mostly all support the same
# compression mechanisms. By consolidating these compression headers into
# a consistent format, we can reduce the size of the cache and get more hits.
# @see: http://varnish.projects.linpro.no/wiki/FAQ/Compression
if ( req.http.Accept-Encoding ) {
if ( req.http.Accept-Encoding ~ "gzip" ) {
# If the browser supports it, we'll use gzip.
set req.http.Accept-Encoding = "gzip";
}
else if ( req.http.Accept-Encoding ~ "deflate" ) {
# Next, try deflate if it is supported.
set req.http.Accept-Encoding = "deflate";
}
else {
# Unknown algorithm. Remove it and send unencoded.
unset req.http.Accept-Encoding;
}
}
}
sub vcl_fetch {
# Allow items to be stale if needed.
set beresp.grace = 2m;
# Drop any cookies WordPress tries to send back to the client.
if ( ! req.url ~ "wp-(login|admin)" && ! req.http.cookie ~ "wordpress_logged_in" ) {
unset beresp.http.set-cookie;
}
}
sub vcl_miss {
if(req.request == "PURGE"){
purge;
error 200 "Purged";
}
}
sub vcl_hit {
if(req.request == "PURGE"){
purge;
error 200 "Purged";
}
}
sub vcl_deliver {
if(obj.hits > 0) {
set resp.http.X-Varnish-Cache = "HIT ("+obj.hits+")";
} else {
set resp.http.X-Varnish-Cache = "MISS";
}
}