Caching Apache-缓存来自app server的响应

Caching Apache-缓存来自app server的响应,caching,apache,reverse-proxy,Caching,Apache,Reverse Proxy,我在Apache2.4.2后面有一个反向代理配置的web应用服务器。应用程序服务器返回包含以下标题的响应: Pragma: no-cache Vary: Accept-Encoding Cache-Control: no-cache Expires: Mon, 07 Jan 2013 01:21:30 GMT 我让Apache2.4.2在这个应用服务器前面充当反向代理,并希望缓存来自应用服务器的响应。我无法修改应用程序服务器。在Apache中如何实现这一点?我对CacheStoreExpire

我在Apache2.4.2后面有一个反向代理配置的web应用服务器。应用程序服务器返回包含以下标题的响应:

Pragma: no-cache
Vary: Accept-Encoding
Cache-Control: no-cache
Expires: Mon, 07 Jan 2013 01:21:30 GMT
我让Apache2.4.2在这个应用服务器前面充当反向代理,并希望缓存来自应用服务器的响应。我无法修改应用程序服务器。在Apache中如何实现这一点?我对CacheStoreExpired和CacheIgnoreCacheControl抱有希望,但它们在这里没有帮助,因为Apache向后端发出有条件的请求,而应用服务器总是希望用“现在”过期的新内容刷新缓存。我想知道是否可以重写从应用服务器返回的头

我正在使用mod_缓存(无效)进行此配置:

CacheEnable disk /
CacheRoot "C:/Program Files/Apache Software Foundation/Apache2.4/cache/"

CacheIgnoreCacheControl On
CacheIgnoreNoLastMod On
CacheStoreNoStore On
CacheStoreExpired On

CacheStaleOnError on

LogLevel debug
CacheHeader on
CacheDetailHeader on

CacheDefaultExpire 120
CacheMaxExpire 120

SetEnv proxy-nokeepalive 1
ProxyPass / http://localhost:8080/
Apache的调试日志也有点令人担忧:

[Fri Jan 04 16:27:52.113857 2013] [cache:debug] [pid 2824:tid 964] cache_storage.c(624): [client 192.168.4.36:51783] AH00698: cache: Key for entity /browse?(null) is http://192.168.4.189:80/browse?, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:52.113857 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(159): [client 192.168.4.36:51783] AH00750: Adding CACHE_SAVE filter for /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:52.113857 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(169): [client 192.168.4.36:51783] AH00751: Adding CACHE_REMOVE_URL filter for /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.503049 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(1190): [client 192.168.4.36:51783] AH00769: cache: Caching url: /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.503049 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(1196): [client 192.168.4.36:51783] AH00770: cache: Removing CACHE_REMOVE_URL filter., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.643529 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(1318): [client 192.168.4.36:51783] AH00737: commit_entity: Headers and body for URL http://192.168.4.189:80/browse? cached., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache:debug] [pid 2824:tid 964] cache_storage.c(624): [client 192.168.4.36:51783] AH00698: cache: Key for entity /browse?(null) is http://192.168.4.189:80/browse?, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(569): [client 192.168.4.36:51783] AH00709: Recalled cached URL info header http://192.168.4.189:80/browse?, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(865): [client 192.168.4.36:51783] AH00720: Recalled headers for URL http://192.168.4.189:80/browse?, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache:debug] [pid 2824:tid 964] cache_storage.c(320): [client 192.168.4.36:51783] AH00695: Cached response for /browse isn't fresh.  Adding/replacing conditional request headers., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(159): [client 192.168.4.36:51783] AH00750: Adding CACHE_SAVE filter for /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(169): [client 192.168.4.36:51783] AH00751: Adding CACHE_REMOVE_URL filter for /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.235637 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(1190): [client 192.168.4.36:51783] AH00769: cache: Caching url: /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.235637 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(1196): [client 192.168.4.36:51783] AH00770: cache: Removing CACHE_REMOVE_URL filter., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.298072 2013] [cache_disk:warn] [pid 2824:tid 964] (OS 5)Access is denied.  : [client 192.168.4.36:51783] AH00699: rename tempfile to file failed: C:/Program Files/Apache Software Foundation/Apache2.4/cache/aptmpcJvfPV -> C:/Program Files/Apache Software Foundation/Apache2.4/cache/A/3/xM0hz_t8XPQaojszgaGA.data, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.298072 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(617): [client 192.168.4.36:51783] AH00711: Deleting C:/Program Files/Apache Software Foundation/Apache2.4/cache/A/3/xM0hz_t8XPQaojszgaGA.header from cache., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.298072 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(634): [client 192.168.4.36:51783] AH00713: Deleting C:/Program Files/Apache Software Foundation/Apache2.4/cache/A/3/xM0hz_t8XPQaojszgaGA.data from cache., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.298072 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(674): [client 192.168.4.36:51783] AH00715: Deleting directory C:/Program Files/Apache Software Foundation/Apache2.4/cache/A/3 from cache, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.298072 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(1313): [client 192.168.4.36:51783] AH00736: commit_entity: URL 'http://192.168.4.189:80/browse?' not cached due to earlier disk error., referer: http://192.168.4.189/browse

您可以使用mod_缓存来执行此操作

请考虑补充:

CacheIgnoreQueryString On
默认情况下,不缓存具有查询字符串参数的请求

查看日志,最后一行出现错误:
由于先前的磁盘错误而未缓存

可能是您的apache服务器没有写入缓存目录的正确权限,或者您的磁盘已满…

您应该仔细检查是否正确创建了apache memcache目录。

您可以使用CacheIgnoreHeaders忽略来自后端应用服务器的不需要的头:

例如:

CacheIgnoreHeaders Set-Cookie Cookie Cookie2 X-Forwarded-For X-Forwarded-Host

谢谢你的意见。我正在使用mod_缓存,但您建议使用什么配置?(编辑原始帖子以显示我当前的配置。)您的配置似乎正确。为了理解错误,我还需要apache的responseThat返回的HTTP头,它实际上是apache返回的头。也许更有趣的是,我将添加一段Apache调试日志的摘录,其中显示了请求;取来隐藏物使无效再蚀刻;由单个浏览器的请求引起的服务。嗨,dave,你知道你的配置有什么问题吗?您是否修复了由于先前的磁盘错误而未缓存的错误
?我放弃了!我认为“将tempfile重命名为file failed”警告是Apache在Windows()上的一个错误。Mod_headers从源服务器(Header unset Expires)剥离了反缓存响应(Header unset Expires),这允许Apache启动缓存,但Mod_Expires无法设置计算的过期时间,我也无法将无缓存头重新插入缓存提供的响应(以防止在web中的其他位置进行缓存)。然后,当浏览器的请求包含max age=0时,Apache从缓存中提供了一些服务(吓坏了我)。最终我意识到我需要的是应用层的缓存,而不是HTTP。