【发布时间】:2016-08-18 09:52:16
【问题描述】:
我在 tomcat 服务器前使用 apache2 作为loadbalancer 和frontend-proxy,通过mod_ajp 连接。现在,我想添加缓存。
不幸的是,tomcat 服务器的应用程序发回了很多标头,根据 RFC,这会阻止 pragma: no-cache 等缓存。但主要问题是错误消息:
HTTP/1.1 200 OK
Date: Thu, 18 Aug 2016 09:44:33 GMT
Server: Apache/2.4.10 (Debian)
X-Magnolia-Registration: Registered
Set-Cookie: JSESSIONID=xxxxxxx; Path=/form-cms/; Secure; HttpOnly
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Content-Encoding: gzip
Vary: Accept-Encoding
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Last-Modified: Thu, 18 Aug 2016 09:44:33 GMT
Content-Language: en
X-Cache: MISS from fqdn.example.com
X-Cache-Detail: "Broken expires header: Thu, 01 Jan 1970 00:00:00 GMT" from fqdn.example.com
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html;charset=UTF-8
缓存配置如下所示:
CacheRoot "/var/cache/apache2/mod_cache_disk"
CacheDirLevels 2
CacheDirLength 1
CacheMaxExpire 60
CacheDefaultExpire 60
CacheHeader on
CacheDetailHeader on
CacheIgnoreHeaders Expires
CacheIgnoreCacheControl on
CacheStoreNoStore On
CacheStorePrivat On
CacheQuickHandler off
<LocationMatch "^/my-app/.*">
CacheEnable disk
</LocationMatch>
我不知道如何解决这个问题,并且无法更改应用程序在 tomcat 服务器上的行为。我尝试通过 mod_headers 取消设置 expires-header,但无济于事。
有什么想法吗?
【问题讨论】:
-
从标签中我假设您使用 Magnolia CMS。在这种情况下,问题可能(我不是 100% 确定)是 Magnolia 和 Apache 的缓存标头之间的冲突 - Magnolia 实现了高级缓存算法(请参阅documentation),因此恕我直言,无需在前面放置另一个缓存其中。相反,它可能会在额外的缓存 和 Magnolia 中导致非常意外的行为。
-
@JozefChocholacek 不幸的是,我们的 Magnolia 5.4 没有正确缓存 html 模板。我们正在检查 magnolia 支持是否可行 - 因此是 apache 负载均衡器中的 apache-cache。几天前我能够用 nginx 解决问题,但由于客户端在 apache 上拥有一切,我别无选择,只能用 apache 解决它 - 我做到了,请参阅接受的答案。
标签: tomcat caching apache2 magnolia ajp