Project

General

Profile

Using Lighttpd with Coral Cache

This quick howto shows what to add to your configuration file to take advantage of Coral Cache. Coral Cache is a free content distribution network commonly used to survive being dugg/slashdotted.

Coral Cache Basics

Coral Cache is easy to use. Just add ".nyud.net" to the end of any domain (e.g. http://www.google.com.nyud.net), and everything else is handled for you. Of course, caching means that whatever content you cache becomes static. By default, content is cached for 12 hours, which is probably fine for most uses, epically if you only cache your images.

Config File Sample

Coral Cache builds its cache automatically, by requesting the content from your server. Because of this, we can't just redirect everything, we have to actually answer requests from Coral Cache. Coral Cache also has a fault-tolerance of sorts... If for some reason it can't handle the request, it sends the request back to your server. So, we have to test for this.

You will need mod_redirect enabled:

server.modules = ( "mod_redirect" )

Now, here's the meat & potatoes of the code (thanks to freenode#lighttpd for the tips):

# make sure this isn't CoralCache requesting content
$HTTP["useragent"] !~ "^CoralWebPrx" {
    # make sure that this wasn't sent back to us from CoralCache
    $HTTP["querystring"] !~ "(^|&)coral-no-serve$" {
        url.redirect = ( "^/.*" => "http://www.example.com.nyud.net$0" )
    }
}

If you want to do this for many hostnames at once, try this:

# make sure this isn't CoralCache requesting content
$HTTP["useragent"] !~ "^CoralWebPrx" {
    # make sure that this wasn't sent back to us from CoralCache
    $HTTP["querystring"] !~ "(^|&)coral-no-serve$" {
        # capture hostname
        $HTTP["host"] =~ "^[^:]*" {
            url.redirect = ( "^/.*" => "http://%0.nyud.net$0" )
        }
    }
}