图像忽略.htaccess中的Cache-Control

问题描述 投票:0回答:1

在我的images文件夹中,我有一个.htaccess文件,其中包含以下内容:

<IfModule mod_headers.c>

  # Browsers may cache images for 24 hours, including disk cache for SSL
  Header set Cache-Control "max-age=2628000, public, must-revalidate"

</IfModule>

当我卷曲该文件夹中的图像时,我得到以下内容(注意Cache-Control缺少“public”和“must-revalidate”):

HTTP/1.1 200 OK
Server: nginx/1.11.8
Date: Fri, 14 Dec 2018 17:57:00 GMT
Content-Type: image/jpeg
Content-Length: 46563
Last-Modified: Fri, 29 Sep 2017 03:16:20 GMT
Connection: keep-alive
ETag: "59cdbb04-b5e3"
Expires: Fri, 21 Dec 2018 17:57:00 GMT
Cache-Control: max-age=604800
Strict-Transport-Security: max-age=31536000
Accept-Ranges: bytes

我放在.htaccess文件中并不重要,我总是得到上面的响应。

如果我在该文件夹中创建一个新图像,我也会得到相同的上述响应。

如果我更改该文件夹(.bak)中图像的扩展名,我会得到预期的响应(Cache-Control是正确的):

HTTP/1.1 200 OK
Server: nginx/1.11.8
Date: Fri, 14 Dec 2018 17:59:35 GMT
Content-Type: image/gif
Content-Length: 19164
Connection: keep-alive
Last-Modified: Fri, 14 Dec 2018 16:07:12 GMT
ETag: "183ca-4adc-57cfd9fbbac00"
Accept-Ranges: bytes
Cache-Control: max-age=2628000, public, must-revalidate
Strict-Transport-Security: max-age=31536000

有什么想法在这里发生了什么?我查看了所有父.htaccess文件和apache配置,我找不到任何东西!

请帮忙!!!

apache .htaccess caching cache-control
1个回答
0
投票

对于遇到此问题的任何其他人,Apache .htaccess指令被以下Nginx配置覆盖:

location ~* ^(.+?)(?:\.\d+)?\.(jpe?g|gif|png|svg|ico|bmp|js|css|ttf|eot|woff2?)$ {
    root /var/www;
    try_files $1.$2 @apache;
    expires 7d;
}

替换“过期7d;”以下做了诀窍:

 add_header Cache-Control "max-age=2628000, public, must-revalidate";
© www.soinside.com 2019 - 2024. All rights reserved.