我有一个本地 Apache 实例在启用 mod_cache(+磁盘和内存)的情况下运行,它似乎可以很好地缓存来自我的应用服务器的内容。我的应用服务器设置了 Expiration 标头和 Last-modified。然而,在启用相同模块的生产服务器上部署时,我的日志中出现以下错误:blablabla 未缓存。原因:查询字符串存在但没有明确的到期时间。节选自调试日志调用服务时的输出附加在这篇文章的末尾
有没有关于 Apache 为何不缓存内容的线索?我能分辨出的唯一区别是 Apache 版本。我在本地运行的是 2.2.22,在生产环境中运行的是 2.2.11。
这是我的配置
ServerName my-front-end.server.com
CacheEnable mem /
<Location "/rest-api/myservice" >
ProxyPass http://my-backend.appserver.com:8180/rest-api/myservice
ProxyPassReverse http://my-backend.appserver.com:8180/rest-api/myservice
</Location>
这是示例输出
< HTTP/1.1 200 OK
< Date: Mon, 19 Nov 2012 16:09:13 GMT
< Server: Sun GlassFish Enterprise Server v2.1.1
< X-Powered-By: Servlet/2.5
< Expires: Tue Nov 20 05:00:00 CET 2012
< Last-Modified: Mon Nov 19 17:09:13 CET 2012
< Cache-Control: no-transform
< Content-Type: application/x-javascript
< Transfer-Encoding: chunked
这是来自我的 apache 日志(更改了服务器名称和应用程序 uri):
[Tue Nov 20 09:58:29 2012] [debug] proxy_util.c(1968): proxy: initialized single connection worker 47 in child 9879 for (my-backend.appserver.com)
[Tue Nov 20 09:58:29 2012] [debug] proxy_util.c(1855): proxy: grabbed scoreboard slot 48 in child 9879 for worker http://my-backend.appserver.com:8080/rest
[Tue Nov 20 09:58:29 2012] [debug] proxy_util.c(1874): proxy: worker http://my-backend.appserver.com:8080/rest already initialized
[Tue Nov 20 09:58:29 2012] [debug] proxy_util.c(1968): proxy: initialized single connection worker 48 in child 9879 for (my-backend.appserver.com)
[Tue Nov 20 09:58:34 2012] [info] Initial (No.1) HTTPS request received for child 5 (server my-front-end.server.com:80)
[Tue Nov 20 09:58:34 2012] [debug] mod_cache.c(131): Adding CACHE_SAVE filter for rest-api/myservice
[Tue Nov 20 09:58:34 2012] [debug] mod_cache.c(138): Adding CACHE_REMOVE_URL filter for rest-api/myservice
[Tue Nov 20 09:58:34 2012] [debug] mod_proxy_http.c(56): proxy: HTTP: canonicalising URL //my-backend.appserver.com:8180:rest-api/myservice
[Tue Nov 20 09:58:34 2012] [debug] proxy_util.c(1489): [client 172.16.9.92] proxy: http: found worker http://my-backend.appserver.com:8180/cfp/6 for http://my-backend.appserver.com:8180:rest-api/myservice?_jsonp=unique_4_&myParam=2
[Tue Nov 20 09:58:34 2012] [debug] mod_proxy.c(988): Running scheme http handler (attempt 0)
[Tue Nov 20 09:58:34 2012] [debug] mod_proxy_http.c(1924): proxy: HTTP: serving URL http://my-backend.appserver.com:8180:rest-api/myservice?_jsonp=unique_4_&myParam=2
[Tue Nov 20 09:58:34 2012] [debug] proxy_util.c(2045): proxy: HTTP: has acquired connection for (my-backend.appserver.com)
[Tue Nov 20 09:58:34 2012] [debug] proxy_util.c(2103): proxy: connecting http://my-backend.appserver.com:8180:rest-api/myservice?_jsonp=unique_4_&myParam=2 to my-backend.appserver.com:8180
[Tue Nov 20 09:58:34 2012] [debug] proxy_util.c(2201): proxy: connected rest-api/myservice?_jsonp=unique_4_&myParam=2 to my-backend.appserver.com:8180
[Tue Nov 20 09:58:34 2012] [debug] proxy_util.c(2356): proxy: HTTP: fam 2 socket created to connect to my-backend.appserver.com
[Tue Nov 20 09:58:34 2012] [debug] proxy_util.c(2468): proxy: HTTP: connection complete to 183.14.15.233:8180 (my-backend.appserver.com)
[Tue Nov 20 09:58:34 2012] [debug] mod_proxy_http.c(1701): proxy: start body send
[Tue Nov 20 09:58:34 2012] [debug] mod_cache.c(528): cache: rest-api/myservice?_jsonp=unique_4_&myParam=2 not cached. Reason: Query string present but no explicit expiration time
[Tue Nov 20 09:58:34 2012] [debug] mod_proxy_http.c(1790): proxy: end body send
[Tue Nov 20 09:58:34 2012] [debug] proxy_util.c(2063): proxy: HTTP: has released connection for (my-backend.appserver.com)
答案1
发现答案就在版本号中。事实证明,首先修复此行为的版本是 2.2.12 - 这是我们生产中使用的版本号之后的次版本号...
来自2.2.x 版本的变更日志在 Apache 中,“Apache 2.2.12 的变化”部分
*) mod_cache: When an explicit Expires or Cache-Control header is set, cache
normally non-cacheable response statuses. PR 46346.
[Alex Polvi <alex polvi.net>]
可以找到提交这里