Apache allows you to set up content caching for your website, thereby improving website speed and reducing server load. mod_headers is an essential Apache module for content caching. Let us look at how to enable mod_headers in Apache.
What is mod_headers?
mod_headers is a useful Apache module required to set up content caching in Apache. It provides directive control and allows you to modify HTTP headers for requests & responses. For example, you can use mod_headers to set Cache-control: public,s-maxage=2592000 for every image on your website. So this will make your proxy server cache these images for 1 month.
How to Enable mod_headers in Apache
Before we proceed, please ensure you have installed Apache on your Linux system. Basically, you need SSH into your server, enable mod_headers module and restart the server to apply changes.
1. Enable mod_headers module
mod_headers is installed during Apache installation. You just have to enable it.
Log into your server via SSH, or open a terminal
Enable mod_headers with the following command
$ sudo a2enmod headers
You might also want to enable mod_expires, to set Expires header for caching.
$ sudo a2enmod expires
2. Restart Apache Server
Once you have enabled an Apache module, you need to restart Apache server to apply changes
$ sudo systemctl restart apache2 [Ubuntu/Debian]
That’s it! You have enabled mod_headers module in Apache.