使用 mod_expires 覆盖缓存标头
我想使用 apache 的 mod_expires 模块设置缓存头。我的配置看起来有点像这样:
<LocationMatch ^/static >
ExpiresDefault "access plus 1 years"
</LocationMatch>
问题是,这些文件是由我无法控制的第三个系统生成的。这些系统提供具有以下标头的文件:
Date Mon, 24 Oct 2011 08:39:02 GMT
Cache-Control no-cache,no-store,must-revalidate
Pragma no-cache
Expires Thu, 01 Dec 1994 16:00:00 GMT
这些标头使得无法使用 mod_expires 设置缓存标头。 http://httpd.apache.org/docs/2.2/mod/mod_expires.html 告诉我们原因:
当 Expires 标头已经是服务器生成的响应的一部分时,例如由 CGI 脚本生成或从源服务器代理时,此模块不会更改或添加 Expires 或 Cache-Control 标头。
有没有可能的方法来规避此规则并用 mod_expires 覆盖标头?
更新: 为了避免此限制,一种可能的解决方案是仅使用 mod_headers 来设置缓存头。不幸的是,这不是一个替代方案,因为必须计算这些值。
谢谢它提前。
I want to set cache-headers using the mod_expires module from apache. My configuration looks somewhat like this:
<LocationMatch ^/static >
ExpiresDefault "access plus 1 years"
</LocationMatch>
The problem is, that the files are generated by a third system I don't control. These system provides files with the following headers:
Date Mon, 24 Oct 2011 08:39:02 GMT
Cache-Control no-cache,no-store,must-revalidate
Pragma no-cache
Expires Thu, 01 Dec 1994 16:00:00 GMT
These headers makes it impossible to set the cache-headers with mod_expires. http://httpd.apache.org/docs/2.2/mod/mod_expires.html tells us why:
When the Expires header is already part of the response generated by the server, for example when generated by a CGI script or proxied from an origin server, this module does not change or add an Expires or Cache-Control header.
Is there any possible way to circumvent this rule and overwrite the headers with mod_expires?
Update:
One possible solution, to avoid this limitation is to use only mod_headers to set the cache-headers. Unfortunately, this isn't an alternative because the values have to be calculated.
Thanks it advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是,这是一个已知的限制,我们不得不只使用
mod_headers
。Unfortunately, it's a known limitation and we had to fall back to use only
mod_headers
.Regilero 的建议行不通,因为标头指令将在响应处理的最后阶段(在
mod_expire
指令之后)进行处理。因此,您可以在mod_expires
执行(或未执行)其应执行的操作后取消设置标头。如果是 apache 2.2,您可以尝试将
early
放在每个标头指令的末尾。这将告诉它在响应处理的早期阶段而不是最后阶段执行此操作。所以尝试一下:
虽然还没有测试过,但尝试一下......
Regilero's suggestion won't work because header directives will be processed very late in the response processing - after
mod_expire
directive. So you'd unset the headers aftermod_expires
did (or didn't) what it was supposed to do.If it's apache 2.2 you could try putting
early
at the end of each header directive. That will tell it to do this in an early stage of response processing as opposed to at the end.so try:
Haven't tested tho, but give it a try...
您是否尝试过将其与 mod_headers 混合?
未经测试,但如果...
Have you tried mixing it with mod_headers?
Not tested, but in case of...