I am trying to set up Apache as a forward proxy with caching, but it does not seem to be working correctly. Getting Apache working as a forward proxy was no problem, but no matter what I do it is not caching anything, to disk or memory. I already checked to make sure nothing is conflicting in the mods_enabled directory with mod_cache (ended up commenting it all out) and also I tried moving all of the caching related fields to the configuration file for mod_cache. In addition I set up logging for caching requests, but nothing is being written to those logs. Below is my Apache config, any help would be greatly appreciated!!

ProxyRequests On
ProxyVia On
#ErrorLog "/var/log/apache2/proxy-error.log"
#CustomLog "/var/log/apache2/proxy-access.log" common
CustomLog "/var/log/apache2/cached-requests.log" common env=cache-hit
CustomLog "/var/log/apache2/uncached-requests.log" common env=cache-miss
CustomLog "/var/log/apache2/revalidated-requests.log" common env=cache-revalidate
CustomLog "/var/log/apache2/invalidated-requests.log" common env=cache-invalidate
LogFormat "%{cache-status}e ..."

        # This path must be the same as the one in /etc/default/apache2
        CacheRoot /var/cache/apache2/mod_disk_cache

        # This will also cache local documents. It usually makes more sense to
        # put this into the configuration for just one virtual host.

        CacheEnable disk /
        #CacheHeader on
        CacheDirLevels 3
        CacheDirLength 5
##<IfModule mod_mem_cache.c>
#        CacheEnable mem /
#        MCacheSize 4096
#        MCacheMaxObjectCount 100
#        MCacheMinObjectSize 1
#        MCacheMaxObjectSize 2048

<Proxy *>
Order deny,allow
Deny from all
Allow from x.x.x.x
#IP above hidden for this post

<filesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"

  • What version of Apache are you using? I am attempting the same with latest Apache 2.4.3 and it doesn't work for me either. Similar config - proxy and cache within same vhost. This may be due to a bug – user147152 Nov 27 '12 at 4:33

This is an old post, but I found it in hopes of finding my own answers, so I will share what I can, maybe it's useful.

Given what you've said, I would:

  1. Ensure that apache has write access to /var/cache/apache2/mod_disk_cache
  2. Confirm it can even cache something by forcing it to cache everything and checking to see that the cache directory is not empty (full example):

    CacheIgnoreNoLastMod On

    CacheDefaultExpire 7200

  3. If the above doesn't work then I believe the issue is not with mod_cache or mod_disk_cache. Stop here if so, else keep going:

  4. Ensure that the requests to xml|txt|html|js|css are GET requests (doubtful they are something else).
  5. Ensure there is no "Authorization" header.
  6. Ensure there is not already a Cache-Control private or no-store header. If there is, add the following before your "Header append":

    Header unset Cache-Control

  7. Ensure there is a "Etag", "Last-Modified" or "Expires" header. (Which, perhaps you could make a request from the public side of the proxy to check that mod_expire is actually setting an expires header?)

  8. Read through the "What Can Be Cached?" section of the apache caching docs overview.

On a side note, I have disk cache working but I also haven't been able to figure out how to get the %{cache-status} to show in the logs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.