Cache-control header configuration

The goal of this change is to add the following line of code into the headers section of your config file:

Cache-Control: public, max-age=31557600 

This change allows us to cache your files for the above specified time in seconds.

Enable mod_headers module (it is usually disabled by default). In Debian and Ubuntu Linux distributions use the following command:

 a2enmod headers 

For Linux distributions or other Unix systems without additional module handling infrastructure add the following line to web servers httpd.conf :

 LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so

Now, we need to tell the web server to send specific headers for those specific situations.

Open your virtual server configuration:

vi /etc/apache2/sites-available/ 

For example: If you want to cache all your .pdf and .jpg files for a year, add the following code into your configuration.

<FilesMatch "\.(pdf|jpg)$">
Header set Cache-Control max-age=31557600
</FilesMatch> 

Make sure that you don't have any duplicate headers before we proceed to the last step.

Restart your web server for changes to take effect with following command:

/etc/init.d/apache2 restart 

Related guides:

Troubleshooting error messagesOverview of various error messages.Long-tailFile compression Gzip & BrotliOverview of compressed content types and methodsHTTP/2 Server PushLoad your website faster with HTTP/2 Server pushCross Domain Name Fonts ( CORS )How to configure CORS headers & solve missing fonts.Headers added by CDN77HTTP Request headers sent from CDN77 to Origin server.Understanding HTTP HeadersOverview of HTTP response headers