0

I've got mod_disk_cache working great in Apache. It's caching some of the requests coming out of Tomcat. But for various reasons I won't go into, we can't get Tomcat to drop the Expires and Cache-Control headers on other pieces of content. These headers are set to no-cache and 0. I need to modify or drop them, because Apache's mod_cache will not cache the content if it has those headers set.

My idea is to set up Apache to strip the headers, then forward on to mod_cache. Or if there's a way to tell mod_cache to ignore the cache-control headers, that would work too.

Two instances of Apache would do it. I'd rather just have two virtualhosts and have one proxy to another. Perhaps I can do it with just one VH. What would the config look like?

The following did not work. It strips the headers delivered to the client, but the ajp-proxied resource is not cached to disk. I think it's evaluating mod_cache first, seeing the nocache header, refusing to cache, then doing the header strip afterwards.

Header unset Expires
Header unset Cache-Control

LoadModule cache_module modules/mod_cache.so
<IfModule mod_cache.c>
    LoadModule cache_disk_module modules/mod_cache_disk.so
        <IfModule mod_cache_disk.c>
            CacheRoot "/www/cache"
            CacheEnable disk  "/"
            CacheDirLevels 5
            CacheDirLength 3
        </IfModule>
</IfModule>

ProxyPass "/myappdir" "ajp://localhost:8009/myappdir"
yetimoner
  • 151
  • 1
  • 7

2 Answers2

0

Look into Tomcat servlets https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/filters/ExpiresFilter.html. It works for both you cases.

Alternativelly Mod_cache has an ignore headers option.

Alex H
  • 1,814
  • 11
  • 18
  • This does not satisfy the question's requirement, which is for an Apache-only solution. We cannot insert an ExpiresHeader filter into our Tomcat. – yetimoner Feb 25 '16 at 19:07
  • Please state the requirement in the question – Alex H Feb 25 '16 at 20:28
  • Mod_cache has the option to ignore headers. Added it to the answer. *no link since I'm mobile, please look it up* – Alex H Feb 25 '16 at 20:35
0

I figured it out. Here's how to chain virtualhosts together via mod_proxy, and have the first one strip out headers, and forward to the second, which does the disk cache.

<VirtualHost *:80>
        CacheIgnoreCacheControl On
        CacheIgnoreNoLastMod On
        CacheHeader on
        CacheRoot "/var/www/cache"
        CacheEnable disk  "/"
        CacheDirLevels 5
        CacheDirLength 3

        ProxyPass "/" "http://localhost:81/"
        ProxyPassReverse "/" "http://localhost:81/"
</VirtualHost>

<VirtualHost *:81>
        Header unset Expires
        Header unset Cache-Control

        ProxyPass "/mytomcatapp" "ajp://localhost:8009/mytomcatapp"
</VirtualHost>
yetimoner
  • 151
  • 1
  • 7