How to force caching headers with apache and squid reverse proxy

Last Updated on April 18, 2021 by admin

If you use a squid reverse proxy in front of your apache webserver to reduce the load, it might happen that pages are not cached correctly because the website script running on the apache web server sends wrong caching headers. I had this problem with a WordPress install, WordPress had always sent pragma no-cache headers with the pages so squid reported a cache miss for every page request. A simple solution for this is to use apache mod_headers to delete the no-cache header and replace it with a header for 10 minute cache period.

First, ensure that mod_headers is enabled. To do this in Debian and Ubuntu, run the command:

a2enmod headers

Then create a .htaccess file in the website root directory which contains the following lines:

Header unset Pragma
Header set Cache-Control "must-revalidate, max-age=0, s-maxage=600"
Header set Vary "Accept-Encoding"

Leave a Comment