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 webserver sends wrong caching headers. I had this problem with a wordpress install, wordpress had always send 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 chache header and replace it with a header for 10 minute cache period.

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

a2enmod headers

Then create a .htaccess file in the website root directoyr 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"

How to force caching headers with apache and squid reverse proxy
Tagged on:

Leave a Reply

Your email address will not be published. Required fields are marked *

*