简体   繁体   English

标题缓存控制总是在 apache 上发送

[英]Header cache-control always sent on apache

I am facing an issue with an Apache Server.我正面临 Apache 服务器的问题。 For all the requests of static files such as images or css, it is always added the following response header: Cache-Control: private, max-age=0, must-revalidate, so the file is never cached by the explorer.对于所有静态文件如图片或css的请求,总是添加如下响应头:Cache-Control: private, max-age=0, must-revalidate,因此该文件永远不会被资源管理器缓存。

It is also added the header: Cache-Control: max-age=2592000, public This header is added because of the configuration I have with the expires module,but I can not manage to avoid the other header being set.它还添加了标头:Cache-Control: max-age=2592000, public 添加了这个标头是因为我对 expires 模块的配置,但我无法避免设置另一个标头。 I don't understand why the header Cache-Control: private, max-age=0, must-revalidate is set.我不明白为什么设置标头 Cache-Control: private, max-age=0, must-revalidate 。

I have tried to avoid the header being set using Header unset Cache-Control, but always the header "private, max-age=0, must-revalidate" is set.我试图避免使用 Header unset Cache-Control 设置标头,但始终设置标头“private, max-age=0, must-revalidate”。 I have tried to set the header manually (not using the expires module) using Header set Cache-Control "max-age=2592000, public", and it works but the other header is always set.我尝试使用 Header set Cache-Control "max-age=2592000, public" 手动设置标头(不使用 expires 模块),它可以工作,但始终设置另一个标头。 I have searched in every apache configuration file trying to determine in which part that header is set, but I couldn't find any place or code that sets that header.我在每个 apache 配置文件中都进行了搜索,试图确定该标头设置在哪个部分,但是我找不到任何设置该标头的位置或代码。

enable client caching of static content启用静态内容的客户端缓存

<IfModule mod_expires.c>
 ExpiresActive On
  ExpiresByType image/gif "access plus 27 days"
  ExpiresByType image/jpeg "access plus 27 days"
  ExpiresByType image/png "access plus 27 days"
  ExpiresByType text/css "access plus 27 days"
  ExpiresByType text/javascript "access plus 27 days"
  ExpiresByType application/javascript "access plus 27 days"
  ExpiresByType application/x-javascript "access plus 27 days"
</IfModule>

<ifModule mod_headers.c> 
    # One month for image and video files
    <filesMatch ".(flv|gif|ico|jpg|jpeg|mp4|mpeg|png|svg|swf|webp)$">
        Header unset Cache-Control
        Header set Cache-Control "max-age=2592000, public"
    </filesMatch>

    # One month for JavaScript and PDF files
    <filesMatch ".(js)$">
        Header unset Cache-Control
        Header set Cache-Control "max-age=2592000, public"
    </filesMatch>

    # One month for CSS files
    <filesMatch ".(css)$">
        Header unset Cache-Control
        Header set Cache-Control "max-age=2592000, public"
    </filesMatch>
</ifModule>

The response is always like this:回应总是这样:

HTTP/1.1 200 OK
Date: Fri, 16 Aug 2019 02:49:11 GMT
Server: Apache
Cache-Control: private, max-age=0, must-revalidate
Last-Modified: Sat, 04 May 2013 12:52:00 GMT
ETag: "108a-4dbe3eef5fc00-gzip"
Accept-Ranges: bytes
Cache-Control: max-age=2592000, public
Expires: Sun, 18 Aug 2019 02:49:11 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 4221
Keep-Alive: timeout=5, max=96
Connection: Keep-Alive
Content-Type: image/gif

The header hasn't been set by the expires module at the point where this configuration is applied, so your Header unset Cache-Control line doesn't do anything.在应用此配置时,标头尚未由 expires 模块设置,因此您的Header unset Cache-Control行不会执行任何操作。

Instead, just turn off the expires module in these sections.相反,只需关闭这些部分中的 expires 模块。 That is, replace this:也就是说,替换这个:

Header unset Cache-Control

With this:有了这个:

<IfModule mod_expires.c>
  ExpiresActive Off
</IfModule>

I decided to start from a new fresh installation of Apache and to replicate all the configuration I had until the error was reproduced, and the problem was with a Mellon directive.我决定从一个全新的 Apache 安装开始,并复制我拥有的所有配置,直到错误重现,问题出在 Mellon 指令上。 I use Mellon to authenticate against ADFS, so I had this directive:我使用 Mellon 对 ADFS 进行身份验证,所以我有这个指令:

MellonEnable "info"

Once I commented out that sentence, everything worked fine.一旦我注释掉那句话,一切都很好。

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

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