Using mod_alias to Share Assets

Posted by Pat Thu, 26 Jan 2006 07:19:00 GMT

In awstats – The Static Way, I showed you how to generate static stats pages using awstats. Shane quickly pointed out that the icons won’t work properly. I hadn’t noticed this, because awstats has very nice alt tags, but he’s absolutely right. There’s a much easier way to fix it though, and it involves using a nice (though apparently poorly documented) feature of our favorite webserver – mod_alias.

mod_alias is kind of like a simple mod_rewrite, but instead of rewriting the URL, it takes the incoming URL and maps it to a different location on the file system. This allows you to set up an single alias in your lighty config file, and use that path among all your sites. In the case of awstats, the HTML files all link to images in /awstatsicons/. If you followed my instructions though, that won’t exist. mod_alias to the rescue.

First just add mod_alias to the list of modules in lighttpd.conf. It’ll end up looking something (though perhaps not exactly) like this:
server.modules              = (
                                "mod_rewrite",
                                "mod_redirect",
                                "mod_proxy",
                                "mod_access",
                                "mod_fastcgi",
                                "mod_alias", # Add this line
                                "mod_compress",
                                "mod_accesslog" )
The next thing to do is set up an alias. In our case, we want /awstatsicons/ to be accessible to every site we run, and the icons are stored in /usr/local/www/awstats/icons. So in your config file, before any virtual hosts are defined, add this line:
alias.url = ( "/awstatsicons/" => "/usr/local/www/awstats/icons/" )

Now load up your stats page, and you’ll see the pretty icons!

Final Thoughts

As you can see, mod_alias is a pretty useful module for sharing static assets. If you have a bunch of images or CSS files that you want to share among a number of different web sites, you can simply use mod_alias to set up a common URL path. Pretty slick.

Posted in  | Tags , ,  | no comments

Comments

(leave url/email »)

   Preview comment