[英]Cloudfront not caching despite Cache-Control
I have a Cloudfront distribution that points to a server that resizes images from an S3 bucket. 我有一个Cloudfront发行版,指向服务器来调整S3存储桶中图像的大小。 The server returns a
Cache-Control
header with public, max-age=31104000
, but I keep getting miss from Cloudfront
so the images are not cached in Cloudfront. 服务器返回一个带有
public, max-age=31104000
的Cache-Control
标头,但是我一直miss from Cloudfront
因此图像不缓存在Cloudfront中。
To test, I set up another Cloudfront distribution that points directly to the S3 bucket, and that indeed caches the images with hit from Cloudfront
. 为了进行测试,我设置了另一个Cloudfront发行版,该发行版直接指向S3存储桶,并且确实缓存了
hit from Cloudfront
的图像。
I compared the request and response headers, and the only difference is that the miss has a Last-Modified
header response, which is missing from the good request. 我比较了请求标头和响应标头,唯一的区别是未命中具有
Last-Modified
标头响应,这是好请求所缺少的。 However, I'm not sure that's the problem. 但是,我不确定这是问题所在。
Do you have any idea of what is happening? 您是否知道发生了什么? Here are the headers:
这是标题:
Good Response:
Age:10
Cache-Control:public, max-age=31104000
Connection:keep-alive
Date:Sat, 05 Sep 2015 16:15:51 GMT
ETag:"51dbe11a5fa320c4495221b69df1d860"
Server:AmazonS3
Via:1.1 b7bc8b4c398aa9f5a08980055c497334.cloudfront.net (CloudFront)
X-Amz-Cf-Id:4KE-cAoFrTmcjkRW3goZAImvyQE5i1Vl4KZyrWL8HyCk6GcJZ9N7Kw==
X-Cache:Hit from cloudfront
Bad Response:
Cache-Control:public, max-age=31104000
Connection:keep-alive
Date:Sat, 05 Sep 2015 16:16:42 GMT
ETag:"51dbe11a5fa320c4495221b69df1d860"
Last-Modified:Sat, 05 Sep 2015 16:07:41 GMT
Server:nginx/1.6.2
Via:1.1 45578d14a69df96accaab0d1aba82a5a.cloudfront.net (CloudFront)
X-Amz-Cf-Id:FGMRwDI0vOJQ7aPj83s-RGTO0fg_Zesu7FLo7Ia5vwCxcTZI97ri5A==
X-Cache:Miss from cloudfront
Good Request:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0 .8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,da;q=0.6
Cache-Control:max-age=0
Connection:keep-alive
Host:assets.runemadsen.com
If-Modified-Since:Sat, 05 Sep 2015 16:07:41 GMT
If-None-Match:"51dbe11a5fa320c4495221b69df1d860"
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36
Bad Request:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0 .8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,da;q=0.6
Cache-Control:max-age=0
Connection:keep-alive
Host:images.runemadsen.com
If-Modified-Since:Sat, 05 Sep 2015 16:07:41 GMT
If-None-Match:"51dbe11a5fa320c4495221b69df1d860"
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36
Any help appreciated. 任何帮助表示赞赏。
Thanks for the comments. 感谢您的评论。 Here's the final update: The reason was that an older response without the
Cache-Control
was cached in Cloudfront, which somehow made cloudfront continously reload the image from the origin. 这是最后的更新:原因是在Cloudfront中缓存了一个没有
Cache-Control
的较旧响应,从而使Cloudfront不断从源中重新加载映像。 I'm not sure exactly how a cached response can trigger constant "miss", but that's what happened. 我不确定缓存响应如何触发常量“ miss”,但这就是发生的情况。 I invalidated the route, and Cloudfront started cahing the images.
我使路线无效,Cloudfront开始处理图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.