Search code examples
cachingapache2reverse-proxy

Apache Reverse Caching Proxy - why isn't it caching?


I am attempting to set up a reverse caching proxy for ad graphics (GIF, JPEG, SWF) serving. The proxying is working fine and sending the request on to the origin server, but I can’t seem to figure out why the content isn't being cached. My current config is below. The goal is to cache all requests that match the /ca/ URI prefix. The origin server is serving the files with clean URLs, no file extensions, Cache-control max-age=1 week set on the origin server headers.

ProxyRequests Off
<Proxy *>
 Order deny,allow
 Allow from all
</Proxy>
<IfModule mod_disk_cache.c>
 CacheEnable disk /
 CacheRoot "/var/cache/mod_proxy"
 CacheDirLevels 3
 CacheDirLength 5
 CacheIgnoreCacheControl On 
</IfModule>

RewriteCond %{REQUEST_URI} ^/ca/*
RewriteRule ^/(.*)$ http://origin.webserver.com/$1 [P,L]

Currently, the only caching I’ve seen actually happen is that of local files accessed on the proxy servers, I’m looking for what I’m missing to get content fetched from the origin server to be cached.

I’m wondering if it has to do with mod_cache not caching because the content is fetched from the origin server, and not on a location on disk.

I am looking for a way to force all requests matching that prefix to be cached.

P.S. It looks like I’m having this exact issue: http://mail-archives.apache.org/mod_mbox/httpd-users/200901.mbox/%3C497F6ED3.7080606@gmail.com%3E. I will be checking my permissions and go over debug messages…


Solution

  • Adding these directives seemed to kick the cache mechanism into gear. I figure it has to do with expiration and cache-control headers as sent from the origin server since I'm serving up images with Symfony/PHP5 instead of directly from the filesystem.

    <IfModule mod_disk_cache.c>
        CacheEnable disk /
        CacheRoot "/var/cache/mod_proxy"
        CacheDirLevels 3
        CacheDirLength 5
        CacheIgnoreCacheControl On
        CacheMaxFileSize 100000000
        CacheIgnoreNoLastMod On
        CacheMaxExpire 1209600
        CacheIgnoreQueryString On
    </IfModule>