缺少Cloudfront缓存控制标头 [英] Cloudfront cache-control headers missing

查看:103
本文介绍了缺少Cloudfront缓存控制标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我设置的云前域名是icdn.lottoresults.ie。我使用Bind9 dns和icdn.lottoresults.ie(即用于云端发行版的CNAME)进行设置。



一切都很好。



但是,为了优化网站性能(Yslow,google pagespeed等),我希望设置Cache-control和Expires标头,并且我不希望使用Etags。

p>

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

 标头未设置语法
FileETag无
标头未设置ETag

< FilesMatch(。*)\。(ico | jpg | jpeg | png | gif | js | css | swf)$>
ExpiresDefault on
ExpiresActive访问权限加1年
标头设置了Cache-Control max-age = 1864000,公共
标头未设置最后修改的
< / FilesMatch>

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



当我从云端域查询资产时,我没有缓存控制标头或Expires标头,但确实有Etags。



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

  HTTP / 1.0 200 OK 
日期:2012年4月1日星期日22:58:30 GMT
服务器:Apache / 2.2.9(Debian)PHP / 5.2.6-1 + lenny13 with Suhosin-Patch
最后修改时间:2011年8月8日星期一20:23:00 GMT
** ETag **: 28a213-19b-4aa0436a1b100
接受范围:字节
内容长度:411
内容类型:image / jpeg
年龄:22137
X缓存:从云端
命中X-Amz-Cf-Id:AV55dR4_vWHtlTbU6E9M2tkh9reoAwZcHlD 4y9csetK6B6Ey8gDPJA =
通过:1.0 8adf6ec3585d73c680b4a6d5052988d8.cloudfront.net(CloudFront)
连接:close

但是,当我从原始服务器查询同一资产时,会得到以下内容,其中包括Cache-control,Expires和No Etags。



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

  HTTP / 1.1 200 OK 
日期:2012年4月6日,星期五20 :50:08 GMT
服务器:Apache / 2.2.9(Debian)PHP / 5.2.6-1 + lenny13 with Suhosin-Patch
Accept-Ranges:字节
内容长度:411
**缓存控制**:最大年龄= 1864000,公共
**有效期**:星期六,2013年4月6日20:50:08 GMT
内容类型:image / jpeg

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



感谢
Paul

解决方案

我想我知道这对任何其他权利有同样的问题。



它是 PEBKAC -我必须先使资产失效,然后资产才能获得新的标题。



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



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

  HTTP / 1.0 200 OK 
日期:2012年4月6日星期五23:00:24 GMT
服务器:Apache / 2.2.9(Debian)PHP / 5.2.6-1 + lenny13 with Suhosin-Patch
接受范围:字节
内容长度:1849
缓存控制:max-age = 1864000,公共
过期时间:2013年4月6日,星期六23:00:24 GMT
内容类型:image / gif
年龄:29
X缓存:来自云端的命中
X-Amz-Cf-Id:vPPBdJpw0ZI_J2trHyECnE2UBeQO9NsQZD9GSvl3GIVAZuQ = 5lz1Z ,J4bBHfF5lKEpjRPLZVYpS9HUdAKEOLEe-Gy3-a_x4PsLPrdWuRg93Q ==
通过:1.0 00204466f749ba432b50dc49d604c534.cloudfront.net(CloudFront)
连接:close
$ b

I setup Cloudfront to serve static images, js, css files for www.lottoresults.ie. I used a custom origin server.

The cloudfront domain name I setup is icdn.lottoresults.ie. I set this up using Bind9 dns, with icdn.lottoresults.ie a CNAME for the cloudfront distro.

That's all fine.

However, for website performance optimization (Yslow, google pagespeed etc), I want to have Cache-control and Expires headers set, and I do not want Etags.

To do this, I have the following in my htaccess file for the doc_root of www.lottoresults.ie:

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>

The problem is that for assets coming from the cloudfront distro (icdn), I have no Cache-control or Expires headers, but I do have Etags - yet for www I do have Cache-control and Expires headers, and no Etags.

When I query an asset from my cloudfront domain, I have no Cache-control or Expires headers, but I do have 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

Yet when I query the same asset from my origin server, I get the following, which includes Cache-control, Expires, and 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

Any help or advice greatly appreciated.

Thanks Paul

解决方案

I think I know what this was, for anyone else who might have same issue.

It is kind of PEBKAC - I have to invalidate the assets before they acquire new headers.

E.g. I added a new file, images/zoom2.gif, and it looks correct:

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

这篇关于缺少Cloudfront缓存控制标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆