Lighttpd SimpleCDN

I have recently tried to enable CDN integration to a bunch of servers in order to reduce load. In some cases, the CMS used had a good CDN plugin/module, such as the one used on this blog. It will automatically rename urls in the output buffer before sending it to the client.

However, I longed for a more permanent and independent solution. So, I decided to use HTTP redirects to point things towards the CDN. Since I use lighttpd, the result is the following configuration snippet:


server.modules += ( "mod_redirect" )

$HTTP["host"] == "www.example.com" {
$HTTP["useragent"] !~ "^SimpleCDN" {
url.redirect = (
"^/(.*)\.(gif|jpg|jpeg|png|css|js|mp3|swf|wmv|mov|mp4)$"
=> "http://www.example.com.lg1.simplecdn.net/$1.$2"
)
}
}

That worked!

Now, all requests for various static files (like images and media), will be immediately redirected to the SimpleCDN mirror bucket that is an Origin Pull CDN. Sweet. This should take a whole load off my server and since this is done at the web-server level, it won’t even consume much resources.

Published by

Shawn Tan

Chip Doctor, Chartered/Professional Engineer, Entrepreneur, Law Graduate.

Leave a comment