Cloudfront缓存控制头丢失。

10

我设置了Cloudfront来提供www.lottoresults.ie的静态图片、js和css文件,并使用自定义源服务器。

我设置的Cloudfront域名是icdn.lottoresults.ie。我使用Bind9 DNS进行设置,将icdn.lottoresults.ie作为Cloudfront分发的CNAME。

这一切都很好。 但是,为了网站性能优化(Yslow、谷歌页面速度等),我想设置Cache-control和Expires头,并且不想使用Etags。

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

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>

问题是,针对来自CloudFront分发(icdn)的资源,我没有缓存控制或过期标头,但我确实有ETags - 但对于www,我确实具有Cache-control和Expires标头,并且没有ETags。

当我从我的CloudFront域查询资产时,我没有缓存控制或过期标头,但我确实有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

然而,当我从我的源服务器查询相同的资产时,我得到了以下结果,其中包括Cache-control、Expires和没有Etags。

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
任何帮助或建议都将不胜感激。
谢谢。 保罗
1个回答

16

我想我知道这是什么问题,对于其他可能遇到同样问题的人来说,这可能是一种 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

URL不再有效。 =( - Craig London
1
除非您使文件无效,否则添加缓存控制最大年龄不会显示出来?即使文件在默认情况下在24小时后过期也是如此吗? - drfence

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接