简体   繁体   English

使用mod_expires覆盖缓存标头

[英]Overwrite cache-headers with mod_expires

I want to set cache-headers using the mod_expires module from apache. 我想使用apache中的mod_expires模块设置cache-headers。 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. 这些标头使得无法使用mod_expires设置缓存标头。 http://httpd.apache.org/docs/2.2/mod/mod_expires.html tells us why: http://httpd.apache.org/docs/2.2/mod/mod_expires.html告诉我们原因:

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. 当Expires标头已经是服务器生成的响应的一部分时,例如,当由CGI脚本生成或从源服务器代理时,此模块不会更改或添加Expires或Cache-Control标头。

Is there any possible way to circumvent this rule and overwrite the headers with mod_expires? 是否有任何可能的方法来规避此规则并使用mod_expires覆盖标头?

Update: One possible solution, to avoid this limitation is to use only mod_headers to set the cache-headers. 更新:一种可能的解决方案是,为了避免此限制,仅使用mod_headers来设置缓存标头。 Unfortunately, this isn't an alternative because the values have to be calculated. 不幸的是,这不是一个替代方案,因为必须计算这些值。

Thanks it advance. 谢谢它提前。

不幸的是,这是一个已知的限制,我们不得不退回只使用mod_headers

Regilero's suggestion won't work because header directives will be processed very late in the response processing - after mod_expire directive. Regilero的建议不起作用,因为在mod_expire指令之后,在响应处理中很晚才会处理头指令。 So you'd unset the headers after mod_expires did (or didn't) what it was supposed to do. 因此,在mod_expires (或没有)它应该执行的操作后,您将取消设置标头。

If it's apache 2.2 you could try putting early at the end of each header directive. 如果它是apache 2.2,你可以尝试在每个header指令的末尾early放置。 That will tell it to do this in an early stage of response processing as opposed to at the end. 这将告诉它在响应处理的早期阶段而不是在最后阶段执行此操作。

so try: 所以尝试:

<LocationMatch ^/static >
  Header unset Cache-Control early
  Header unset Pragma early
  Header unset Expires early
  ExpiresDefault "access plus 1 years"
</LocationMatch>

Haven't tested tho, but give it a try... 没有测试过,但试一试......

Have you tried mixing it with mod_headers ? 你尝试过将它与mod_headers混合使用吗?

<LocationMatch ^/static >
  Header unset Cache-Control 
  Header unset Pragma
  Header unset Expires 
  ExpiresDefault "access plus 1 years"
</LocationMatch>

Not tested, but in case of... 未经测试,但在......的情况下

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM