簡體   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