【问题标题】:Cloudfront cache-control headers missing缺少 Cloudfront 缓存控制标头
【发布时间】:2012-04-06 21:16:56
【问题描述】:

我设置 Cloudfront 为 www.lottoresults.ie 提供静态图像、js、css 文件。我使用了自定义源服务器。

我设置的云端域名是icdn.lottoresults.ie。我使用 Bind9 dns 进行了设置,其中 icdn.lottoresults.ie 是 Cloudfront 发行版的 CNAME。

没关系。

但是,对于网站性能优化(Yslow、google pagespeed 等),我想要设置 Cache-control 和 Expires 标头,并且我不想要 Etags。

为此,我在我的 htaccess 文件中为 www.lottoresults.ie 的 doc_root 提供了以下内容:

Header unset Pragma
FileETag none
Header unset ETag

<FilesMatch "(.*)\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresActive on
ExpiresDefault "access plus 1 year"
Header set Cache-Control "max-age=1864000, public"
Header unset Last-Modified
</FilesMatch>

问题是,对于来自云端发行版 (icdn) 的资产,我没有 Cache-control 或 Expires 标头,但我有 Etags - 但对于www 我确实有 Cache-control 和 Expires 标头,但没有 Etag。

当我从我的云端域查询资产时,我没有 Cache-control 或 Expires 标头,但我有 Etags。

curl -I -L http://icdn.lottoresults.ie/images/green-header.jpg

HTTP/1.0 200 OK
Date: Sun, 01 Apr 2012 22:58:30 GMT
Server: Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny13 with Suhosin-Patch
Last-Modified: Mon, 08 Aug 2011 20:23:00 GMT
**ETag**: "28a213-19b-4aa0436a1b100"
Accept-Ranges: bytes
Content-Length: 411
Content-Type: image/jpeg
Age: 22137
X-Cache: Hit from cloudfront
X-Amz-Cf-Id: AV55dR4_vWHtlTbU6E9M2tkh9reoAwZcHlD4y9csetK6B6Ey8gDPJA=
Via: 1.0 8adf6ec3585d73c680b4a6d5052988d8.cloudfront.net (CloudFront)
Connection: close

然而,当我从源服务器查询相同资产时,我得到以下信息,其中包括缓存控制、过期和无 Etag。

curl -I -L http://www.lottoresults.ie/images/green-header.jpg

HTTP/1.1 200 OK
Date: Fri, 06 Apr 2012 20:50:08 GMT
Server: Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny13 with Suhosin-Patch
Accept-Ranges: bytes
Content-Length: 411
**Cache-Control**: max-age=1864000, public
**Expires**: Sat, 06 Apr 2013 20:50:08 GMT
Content-Type: image/jpeg

非常感谢任何帮助或建议。

谢谢 保罗

【问题讨论】:

    标签: apache cache-control amazon-cloudfront


    【解决方案1】:

    对于可能有同样问题的其他人,我想我知道这是什么。

    有点像PEBKAC - 我必须在资产获得新标头之前使资产无效。

    例如我添加了一个新文件 images/zoom2.gif,它看起来是正确的:

    curl -I -L http://icdn.lottoresults.ie/images/zoom2.gif

    HTTP/1.0 200 OK
    Date: Fri, 06 Apr 2012 23:00:24 GMT
    Server: Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny13 with Suhosin-Patch
    Accept-Ranges: bytes
    Content-Length: 1849
    Cache-Control: max-age=1864000, public
    Expires: Sat, 06 Apr 2013 23:00:24 GMT
    Content-Type: image/gif
    Age: 29
    X-Cache: Hit from cloudfront
    X-Amz-Cf-Id:         vPPBdJpw0ZI_J2trHyECnE2UBeQO9NsQZD9GSvl3GIVAZuQN5lz1ZQ==,J4bBHfF5lKEpjRPLZVYpS9HUdAKEOLEe-Gy3-a_x4PsLPrdWuRg93Q==
    Via: 1.0 00204466f749ba432b50dc49d604c534.cloudfront.net (CloudFront)
    Connection: close
    

    【讨论】:

    • 网址不再有效。 =(
    • 所以添加缓存控制 max-age 不会显示,除非您使文件无效?即使文件默认在 24 小时后过期也不行?
    猜你喜欢
    • 2011-10-28
    • 2019-03-26
    • 2015-04-20
    • 2011-01-13
    • 1970-01-01
    • 2017-01-10
    • 2013-08-17
    • 2010-10-31
    • 2020-07-17
    相关资源
    最近更新 更多