caching wikileaks with varnish

Download this article as an e-bookDownload this article as an e-book

In times like these I like to remind everyone that truth is a virtue and that the best resistance to corruption is decentralization.

With that in mind I quickly threw together a cache for wikileaks at wikileaks.uplink.li. This is not a full mirror obviously but it will stay up even though the main sites go down.

The host in question isn’t really specced for high loads but that is beside the point. The point is that you can do this in your own varnish instance. Here is how you do the same, in VCL:

# help wikileaks stay online by providing caching
# helps more if you have persistent storage.                                                                                                
#
# comotion@krutt.org 2010-12-03
# http://kacper.blog.linpro.no
 
backend wikileaks2 {
   .host = "213.251.145.96";
   .probe = {
      .url = "/img/favicon.ico";
      .interval = 60s;
   }
}
backend wikileaks3 {
   .host = "wikileaks.ch";
   .probe = {
      .url = "/img/favicon.ico";
      .interval = 60s;
   }
}

# won't work while the DNS name is taken out
#backend wikileaks1 {
#   .host = "wikileaks.org";
#   .probe = {
#      .url = "/img/favicon.ico";
#   }
#}
director wikileaks round-robin {
   #{ .backend = wikileaks1; }
   { .backend = wikileaks2; }
   { .backend = wikileaks3; }
   { .backend = wikileaks4; }
}
 
sub vcl_recv {
   if (req.http.host ~ "^(wiki)?leaks" ||
       req.url ~ "^/(wiki)leaks" ||
       req.http.referer ~ "leaks"){
      set req.backend = wikileaks;
      if(req.backend.healthy){
         set req.grace = 7d;
      }else{
         set req.grace = 365d;
      }
   }
}
 
sub vcl_miss {
   if(req.url ~ "^/(wiki)?leaks"){
      set bereq.url = regsub(req.url,"^/(wiki)?leaks","/");
   }
}
sub vcl_fetch {
   if(req.url ~ "^/(wiki)?leaks"){
      set beresp.grace = 365d;
   }
}
 

You can save that to /etc/varnish/default.vcl and reload varnish.
Or, if your Varnish instance has other sites on it, you could save it to /etc/varnish/wikileaks.vcl and add the following near the top of your default.vcl:

include "/etc/varnish/wikileaks.vcl";

Isn’t it beautiful?
You may not be able to set up a full mirror, but now you can go set up your varnish to cache Wikileaks!

PS.
The opinions expressed here are not necessarily those of my employer nor anyone else associated with me, Varnish or anything really.

Download this article as an e-bookDownload this article as an e-book

Tags: , , ,

Leave a Reply