缺少Cloudfront缓存控制标头

时间:2012-04-06 21:16:56

标签: apache cache-control amazon-cloudfront

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

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

这一切都很好。

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

为此,我在www.tottoresults.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)的资产,我没有Cache-control或Expires标头,但我确实有Etags - 但是www我有Cache-control和Expires标题,没有Etags。

当我从我的cloudfront域查询资产时,我没有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

然而,当我从我的原始服务器查询相同的资产时,我得到以下内容,其中包括Cache-control,Expires和no 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 个答案:

答案 0 :(得分:16)

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

有点PEBKAC - 在获取新标题之前,我必须使资产无效

E.g。我添加了一个新文件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