繁体   English   中英

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

[英]Images ignoring Cache-Control in .htaccess

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

当我在该文件夹中卷曲图像时,得到以下信息(Notice 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指令被以下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";

暂无
暂无

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

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