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.

Advertisements

Published by

Shawn Tan

Chip Doctor, Chartered Engineer, Entrepreneur, Law Graduate.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s