[英]Overwrite cache-headers with mod_expires
我想使用apache中的mod_expires模塊設置cache-headers。 我的配置看起來像這樣:
<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來設置緩存標頭。 不幸的是,這不是一個替代方案,因為必須計算這些值。
謝謝它提前。
不幸的是,這是一個已知的限制,我們不得不退回只使用mod_headers
。
Regilero的建議不起作用,因為在mod_expire
指令之后,在響應處理中很晚才會處理頭指令。 因此,在mod_expires
(或沒有)它應該執行的操作后,您將取消設置標頭。
如果它是apache 2.2,你可以嘗試在每個header指令的末尾early
放置。 這將告訴它在響應處理的早期階段而不是在最后階段執行此操作。
所以嘗試:
<LocationMatch ^/static >
Header unset Cache-Control early
Header unset Pragma early
Header unset Expires early
ExpiresDefault "access plus 1 years"
</LocationMatch>
沒有測試過,但試一試......
你嘗試過將它與mod_headers混合使用嗎?
<LocationMatch ^/static >
Header unset Cache-Control
Header unset Pragma
Header unset Expires
ExpiresDefault "access plus 1 years"
</LocationMatch>
未經測試,但在......的情況下
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.