Apache Modules on A VPS ... are you getting a lost feel of the concepts. If yes... then don’t worry your on the right place. We will help you to refresh on the concepts. Here we will be explaining you from the basics. Every point explained will help you understand the concept in an detailed manner.
Let me first brief with you some basics.
What is Caching?
It is a method for improvement of server performance stored in a way which allows for faster access.
- This speeds up processing and delivery by cutting out some resource intensive operations.
- By creating effective caching rules to improve response times, conserve resources, and cut load.
- Apache provides a variety of caches suitable for speeding up different types of operations.
What is Web Caching ?
It is a way of improving server performance. It is done by allowing common request content to store in a simple location. This allows the user to access the content fast. The content suitable for caching will be stored to the resources. More active content will serve generally, by effective creating caching rules. Here, we will be discussing how to configure Apache using its caching modules.
Hope you have recollected the basic definition of Caching and Web caching
Now let us start with some detailed process
An Introduction to Caching in Apache
Apache has many different methods of caching content that is regularly accessed. The two most common modules that enable these are “mod_cache" and "mod_file_cache".
'''The mod_file_cache Apache Module'''
The mod_file_cache module is the simple caching mechanisms. The mod_file_cache module works by caching content that: requested often, Changes rarely.
The mod_cache Apache Module
The mod_cache module provides HTTP aware caching schemes. The files will be cached according to an instruction, how long a page can consider "fresh".
Using mod_file_cache with Apache
The mod_file_cache module is useful to cache files. The techniques of mod_file_cache module will cause the following changes. They are not to be applied till the server restarts. These caching mechanisms can used with usual files. The module provides two directions that are use to complete caching in different ways.
MMapFile is a command used to create a list of files and then record those files into memory. This will complete as server starts, so need to that none of the files set to use this type of caching changed.
You can set up this type of caching in the server configuration file. This is done by specifying files to cached in memory in a space-separated list:
MMapFile /var/www/index.html /var/www/otherfile.html var/www/static-image.jpg
These files will held in memory and served from there when the resource request. If any of the files changed, you need to restart the server.
This command work to opening handles to the files listed. It maintains a table of these open file descriptors and uses it to cut time it takes to open these files.
This command is used by specifying a space-separated list of files. These files should be cached with this method:
CacheFile /thisfile/file.html thatfile/file.html anotherfile/file/to/server.html
This will cause these files to be cached on server start.
Using mod_cache with Apache module
The mod_cache module is a flexible and influential caching module. It functions by implementing HTTP-aware caching of commonly accessed files.
All caching mechanisms rely on serving files in some persistent state. Only mod_cache can handle changing content by configuring how long a file is valid.
The module relies on two other modules to do the majority of the cache implementation. These are "mod_disk_cache" and "mod_mem_cache".
It is accomplished by placing this directive in server configuration or virtual host definition:
How to Configure Caching
If you look in the "/etc/apache/mods-available" directory, you can see some of the default configuration files for these modules.
Let's look at the mod_mem_cache configuration:
sudo nano /etc/apache/mods-available/mem_cache.conf
<IfModule mod_mem_cache.c> CacheEnable mem / MCacheSize 5120 MCacheMaxObjectCount 200 MCacheMinObjectSize 1 MCacheMaxObjectSize 3072
These directives are only read if the mod_mem_cache module is loaded. This can be done by typing the following:
sudo a2enmod mem_cache sudo service apache restart
This will enable mod_mem_cache and also mod_cache.
CacheEnable mem /
The "CacheEnable mem /" line tells apache to create a memory cache for contents stored under "/" which is everything.
MCacheSize 4096 MCacheMaxObjectCount 100
Now we will describe the total size of the cache and the kinds of objects. The "MCacheSize" command
"MCacheMaxOjectCount" command both describe the largest size of the cache. This is done in terms of memory usage, and the largest amount of objects.
MCacheMinObjectSize 1 MCacheMaxObjectSize 3072
The next two lines explain the data type that will be cached, in terms of memory usage.
We will learn about an altered set of directives by exploratory the mod_disk_cache configuration file:
sudo nano /etc/apache/mods-available/disk_cache.conf CacheRoot /var/cache/apache2/mod_disk_cache #CacheEnable disk / CacheDirLevels 5 CacheDirLength 3
This configuration is loaded if you enable the mod_disk_cache module. This can be done by typing:
sudo a2enmod disk_cache sudo service apache restart
This directive will also enable mod_cache in order to work accurately.
CacheRoot /var/cache/apache/mod_disk_cache #CacheEnable disk /
The "CacheRoot" command specifies where the cached content will be kept. The "CacheEnable disk /" command is disabled by default.
CacheDirLevels 5 CacheDirLength 3
Two commands find the caching structure within the cache root. Each cached aspect is hashed by the URL, and then use the hash as a file name and directory path.
Caching which is stored on disk can become great depending on the finishing dates of the content. Apache includes a tool called "htcacheclean" to pare the cache down to a configured size. This is outside the scope of this guide.
Hope all you guys have refreshed your knowledge. Now you must have learned How to Configure Content Caching Using Apache Modules on a VPS or Dedicated Server. If you still feel more points have to be added, it will be surely updated. Please Stay linked to my page so that you update your knowledge with more topics.