CloudFront的TTL不工作 [英] Cloudfront TTL not working

查看:1414
本文介绍了CloudFront的TTL不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,并试图在这里遵循的答案在论坛上,但没有成功的任何责任。

I'm having a problem and tried to follow answers here in forum, but with no success whatsoever.

为了生成缩略图,我已经设置了以下模式: S3账户的原始图像 使用NGINX和Thumbor Ubuntu服务器 CloudFront的

In order to generate thumbnails, I have set up the following schema: S3 Account for original images Ubuntu Server using NGINX and Thumbor Cloudfront

,用户上传的原始图像到S3,这将通过Ubuntu服务器在请求前被拉出带的Cloudfront:

The user uploads original images to S3, which will be pulled through Ubuntu Server with Cloudfront in front of the request:

HTTP://cloudfront.account/thumbor-server/http:// s3.aws ...

大不了的,我们经常在的Cloudfront松散物,我希望他们留360天,高速缓存。 我得到下面通过的Cloudfront的URL响应:

The big deal is, that we often loose objects in Cloudfront, I want them to stay 360 days in cache. I get following response through Cloudfront URL:

Cache-Control:max-age=31536000
Connection:keep-alive
Content-Length:4362
Content-Type:image/jpeg
Date:Sun, 26 Oct 2014 09:18:31 GMT
ETag:"cc095261a9340535996fad26a9a882e9fdfc6b47"
Expires:Mon, 26 Oct 2015 09:18:31 GMT
Server:nginx/1.4.6 (Ubuntu)
Via:1.1 5e0a3a528dab62c5edfcdd8b8e4af060.cloudfront.net (CloudFront)
X-Amz-Cf-Id:B43x2w80SzQqvH-pDmLAmCZl2CY1AjBtHLjN4kG0_XmEIPk4AdiIOw==
X-Cache:Miss from cloudfront

在一个新的刷新,我得到:

After a new refresh, I get:

Age:50
Cache-Control:max-age=31536000
Connection:keep-alive
Date:Sun, 26 Oct 2014 09:19:21 GMT
ETag:"cc095261a9340535996fad26a9a882e9fdfc6b47"
Expires:Mon, 26 Oct 2015 09:18:31 GMT
Server:nginx/1.4.6 (Ubuntu)
Via:1.1 5e0a3a528dab62c5edfcdd8b8e4af060.cloudfront.net (CloudFront)
X-Amz-Cf-Id:slWyJ95Cw2F5LQr7hQFhgonG6oEsu4jdIo1KBkTjM5fitj-4kCtL3w==
X-Cache:Hit from cloudfront

我的Nginx的答复如下:

My Nginx responses as following:

Cache-Control:max-age=31536000
Content-Length:4362
Content-Type:image/jpeg
Date:Sun, 26 Oct 2014 09:18:11 GMT
Etag:"cc095261a9340535996fad26a9a882e9fdfc6b47"
Expires:Mon, 26 Oct 2015 09:18:11 GMT
Server:nginx/1.4.6 (Ubuntu)

为什么不的Cloudfront保存我的对象指示?最大年龄设置? 提前很多感谢。

Why does Cloudfront not store my objects as indicated? Max-Age is set? Many thanks in advance.

推荐答案

你的第二个要求表明,该对象确实缓存。我假设你看到的,但问题并没有说清楚。

Your second request shows that the object was indeed cached. I assume you see that, but the question doesn't make it clear.

的Cache-Control:max-age的只指定的最大的的的Cloudfront缓存的对象的年龄在任何特定的边缘位置。有是,你的目标是保证坚持没有最小时间间隔......毕竟,的Cloudfront是的缓存的,它是挥发性的定义。

The Cache-Control: max-age only specifies the maximum age of your objects in the Cloudfront Cache at any particular edge location. There is no minimum time interval for which your objects are guaranteed to persist... after all, Cloudfront is a cache, which is volatile by definition.

如果在边缘位置的对象是不是经常请求,CloudFront的可能驱逐其到期日期,以腾出空间给那些更青睐的对象之前的对象,删除的对象。

If an object in an edge location isn't frequently requested, CloudFront might evict the object—remove the object before its expiration date—to make room for objects that are more popular.

—的http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html

此外,还有的Cloudfront的概念具有的对象的副本一个整体。每个边缘位置的缓存中出现的其他独立运作,所以它不是经常看到的相对青睐的对象来自不同的Cloudfront边沿位置来临多个请求。

Additionally, there is no concept of Cloudfront as a whole having a copy of your object. Each edge location's cache appears to operate independently of the others, so it's not uncommon to see multiple requests for relatively popular objects coming from different Cloudfront edge locations.

如果你正在试图调解后端服务器上的负载,它可能是有意义把某种缓存你控制的,在它面前,像漆,鱿鱼,另一nginx的或定制的解决方案,如何我在我的系统中实现这一点。

If you are trying to mediate the load on your back-end server, it might make sense to place some kind of cache that you control, in front of it, like varnish, squid, another nginx or a custom solution, which is how I'm accomplishing this in my systems.

另外,你可以每个结果S3存储处理后,再配置现有的服务器,检查S3,首先,试图再次调整对象的工作之前。

Alternately, you could store every result in S3 after processing, and then configure your existing server to check S3, first, before attempting the work of resizing the object again.

那为什么有记载最低TTL?

在上面引述同一页上,您还可以找到这样的:

On the same page quoted above, you'll also find this:

有关网络的分布,如果添加的Cache-Control或Expires头到你的对象,你也可以指定时间CloudFront的保存在缓存中的对象转发其他请求到原点之前的最低金额。

For web distributions, if you add Cache-Control or Expires headers to your objects, you can also specify the minimum amount of time that CloudFront keeps an object in the cache before forwarding another request to the origin.

我明白为什么这一点,尖端引语的评论,下面...

I can see why this, and the tip phrase cited on the comment, below...

的时间(以秒为单位)的对象是在缓存CloudFront的前CloudFront的转发其他请求到您的原产地确定一个更新的版本是否有可用的最低金额。

The minimum amount of time (in seconds) that an object is in a CloudFront cache before CloudFront forwards another request to your origin to determine whether an updated version is available. 

......似乎违背我的答案。然而,有没有矛盾。

...would seem to contradict my answer. There is no contradiction, however.

的最小TTL,简单来说,建立了内部跨$ P $ 的Cache-Control的ptation的下限:最大年龄,压倒一切 - 内的Cloudfront - 由原始服务器发送的较小值。服务器说缓存是1天,最大值,但配置的最小TTL为2天? CloudFront的忘掉它的最大年龄头看到,不得再次检查原点后续请求在未来2天,而不是1天后再次检查。

The minimum ttl, in simple terms, establishes a lower boundary for the internal interpretation of Cache-Control: max-age, overriding -- within Cloudfront -- any smaller value sent by the origin server. Server says cache it for 1 day, max, but configured minimum ttl is 2 days? Cloudfront forgets about what it saw in the max-age header and may not check the origin again on subsequent requests for the next 2 days, rather than checking again after 1 day.

缓存的性质规定所有的明显歧义的正确跨pretation:

The nature of a cache dictates the correct interpretation of all of the apparent ambiguity:

您配置限制了多久的Cloudfront可能成为一个对象的缓存副本,并点后,它不应该继续从本地缓存返回对象。他们并没有强制的Cloudfront必须多长时间保持缓存副本,因为的Cloudfront可随时驱逐的对象。

Your configuration limits how long Cloudfront MAY serve up cached copies of an object, and the point after which it SHOULD NOT continue to return the object from its cache. They do not mandate how long Cloudfront MUST maintain the cached copy, because Cloudfront MAY evict an object at any time.

如果您设置了的Cache-Control:头正确,的Cloudfront会考虑较大的最大年龄或您的最小TTL为时间最长,你希望他们来提供缓存的副本,而无需再次征询源服务器。

If you set the Cache-Control: header correctly, Cloudfront will consider the larger of max-age or your Minimum TTL as the longest amount of time you want them to serve up the cached copy without consulting the origin server again.

随着网站流量的增加,这应该成为不再是一个问题,因为你的对象会更流行,但根本没有办法强制要求的Cloudfront维护对象的副本。

As your site traffic increases, this should become less of an issue, since your objects will be more "popular," but fundamentally there is no way to mandate that Cloudfront maintain a copy of an object.

这篇关于CloudFront的TTL不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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