我在反向代理配置中有一个位于Apache 2.4.2后面的Web应用程序服务器。应用服务器返回包含以下标题的响应:
Pragma: no-cache
Vary: Accept-Encoding
Cache-Control: no-cache
Expires: Mon, 07 Jan 2013 01:21:30 GMT
我在此应用程序服务器前面使用Apache 2.4.2作为反向代理,并希望缓存来自应用程序服务器的响应。我无法修改应用程序服务器。我如何在Apache中执行此操作?我对CacheStoreExpired和CacheIgnoreCacheControl充满希望,但是他们在这里没有帮助,因为Apache向后端发出了条件请求 - 而应用服务器总是希望用“现在”到期的新内容刷新缓存。我想知道我是否可以重写从应用程序服务器返回的标头?
我使用mod_cache(无效)使用此配置:
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
答案 0 :(得分:0)
您可以使用mod_cache
执行此操作http://httpd.apache.org/docs/current/mod/mod_cache.html
请考虑添加:
CacheIgnoreQueryString On
默认情况下,不会缓存带有查询字符串参数的请求。
查看您的日志,最后一行出现错误:not cached due to earlier disk error
可能是您的apache服务器没有正确的权限写入缓存目录,或者您的磁盘已满...
您应该仔细检查是否正确创建了apache memcache目录。
答案 1 :(得分:0)
您可以使用CacheIgnoreHeaders忽略来自后端应用程序服务器的不需要的标头: http://httpd.apache.org/docs/current/mod/mod_cache.html#cacheignoreheaders
例如:
CacheIgnoreHeaders Set-Cookie Cookie Cookie2 X-Forwarded-For X-Forwarded-Host