If you don’t have a CDN and would like to improve the performance of some of your webpages, you can easily do it using Apache File Cache Module. Apache’s file cache module allows you to specify specific images and files for your Apache httpd to load into memory. This saves your machine from all of the read access needed to load the files each time they are requested by browsing clients. Instead, Apache will serve the requests for the cached objects directly from memory. To use Apache’s file cache module, you need to download and install mod_file_cache. Below are instructions for installing it in CentOS 6.
File_mod_cache Prerequisites
Install file_mod_cache prerequisites using yum:
# yum install gcc gcc-c++ kernel-devel httpd-devel |
Download and Install File_mod_cache
# mkdir -p /installs/mod_file_cache# cd /installs/mod_file_cache
# wget http://archive.apache.org/dist/httpd/httpd-2.2.15.tar.gz –2013-11-14 22:41:46– http://archive.apache.org/dist/httpd/httpd-2.2.15.tar.gz 100%[===========================================>] 6,593,633 955K/s in 13s 2013-11-14 22:42:00 (497 KB/s) – “httpd-2.2.15.tar.gz” saved [6593633/6593633]
# gunzip httpd-2.2.15.tar.gz # tar -xvf httpd-2.2.15.tar # cd httpd-2.2.15/modules/cache # apxs -i -a -c mod_file_cache.c
|
That should get mod_file_cache installed, now we need to edit the apache configuration files and list the files that we want it to load into cache when the Apache httpd starts up.
Setup Cached Files in the Apache Configuration Files
See the files added to the VirtualHost below using the “CacheFile /Path/Filename” syntax.
<VirtualHost *:80> ServerName www.uptimemadeeasy.com ServerAlias uptimemadeeasy.com DocumentRoot “/www/uptimemadeeasy.com/” CustomLog logs/uptimemadeeasy.com-access_log combined CacheFile /www/uptimemadeeasy.com/index.html CacheFile /www/uptimemadeeasy.com/image1.jpg CacheFile /www/uptimemadeeasy.com/image2.jpg CacheFile /www/uptimemadeeasy.com/contact-us.html CacheFile /www/uptimemadeeasy.com/contact-us1.jpg CacheFile /www/uptimemadeeasy.com/contact-us2.jpg <Directory “/www/uptimemadeeasy.com”> </VirtualHost> |
Before Apache can cache and serve the files, it needs to be restarted. Apache will find the files at startup and cache them then.
# service httpd restart |
That should do it.
One Thing to Remember
One thing to remember when you are editing your webpage later on, after you edit the files, you need to restart the Apache httpd to allow the changes to be displayed on your webpage. The file cache module loads the files at startup and then doesn’t look for them again until the httpd is restarted. You could even delete the files and there wouldn’t be a noticeable problem until the httpd was restarted and it couldn’t find the files.
Latest posts by Jeff Staten (see all)
- Configure Your HP Procurve Switch with SNTP - May 5, 2015
- Configuring HP Procurve 2920 Switches - May 1, 2015
- Troubleshooting Sendmail - November 28, 2014