忽略.htaccess中的Cache-Control的图像

时间:2018-12-14 18:10:17

标签: apache .htaccess caching cache-control

在我的图像文件夹中,我有一个带有以下内容的.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>

当我在该文件夹中卷曲图像时,得到以下信息(通知缓存控件缺少“ 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配置,找不到任何内容!

请帮助!!!

1 个答案:

答案 0 :(得分: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";