Apache caching of static content (jpg, png, js, …) on the apache proxy server using mod_jk

apache-2.2mod-cache

I'm using an apache as frontend webserver that load balance users between 3 nodes of tomcat web servers. I use mod_jk to do that.

What I want is how can I configure apache on this presentation server so that it would cache all files with specific extensions (like .js, .png, .jpg) ? mod_cache ?

Thanks a lot.

edit: I can't change anythin on the tomcat web servers. So all the magic has to happen on the apache presentation load balancer server…

Best Answer

mod_cache is indeed the usual solution here if you want the Apache server to cache content for you.

You can not, as far as I'm aware, cache by file type or extension in mod_cache -- the caching is controlled by URL and Header information (so if you want to cache all your images the easiest way to accomplish this is to serve them from an /images directory, tell mod_cache to cache stuff coming out of that directory, and let it do its magic).


mod_file_cache is an alternative you can consider if the list of stuff you want to cache is static (a specific list of JS, images, CSS, etc.) -- there are some additional caveats there, particularly if you use MMapFile to keep the files hot in memory, but the improved performance can be substantial over "traditional" caches like mod_cache.


More good information on Apache's caching capabilities can be found in the caching section of the Apache docs, but I think the two options above are your best bets. If you need something better than those a CDN is probably more your speed.