使用Load Balancer和Route 53时出现CloudFront问题 [英] CloudFront issue when using Load Balancer and Route 53

查看:206
本文介绍了使用Load Balancer和Route 53时出现CloudFront问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的想法是使用Cloudfront缓存EC2中的整个站点。但是我这样做很麻烦。如果我将cloudfront选项 Forward Headers (转发标题)设置为 none (无),则会缓存apache中的默认index.html(可能是因为CF正在缓存LB URL)。如果我将转发标题设置为白名单,并在白名单标题中添加主机,则网站将正常显示,但我可以在响应标头:

My idea is to use cloudfront to cache one entire site that is in EC2. But I am having a lot of trouble to do that. If I set the cloudfront option Forward Headers to none, the default index.html from apache is cached (probably because the CF is caching the LB URL). If I set Forward Headers to whitelist and add host in Whitelist Headers the site displays normally but I can see in the Response Header:

X-Amz-Cf-Id:Ij8TsEU2hPehG53Op6LX1zFDmZfYWBOVFn8el8ApicCQYdYEi69HsQ==
X-Cache:Miss from cloudfront

这是当前情况:


  1. Route 53的别名为CloudFront的 A (对于我的裸域和 www

  2. CloudFront具有原始域名 =负载均衡器DNS名称,也将 cname 配置为裸域,并且将www

  3. 带有EC2的负载均衡器

  4. 带有多个站点的EC2(我只想在其中一个站点中使用CF)

  1. Route 53 with A alias pointing to CloudFront (for my naked domain and www)
  2. CloudFront with Origin Domain Name = load balancer DNS name, also the cname are configured to naked domain and www
  3. Load Balancer with EC2
  4. EC2 with several sites (I just want use CF in one of them)

有人可以帮忙吗?我如何正确配置它?

Could anyone help me how to configure it correctly?

更新1
快速浏览一下,该站点位于WordPress中。但是,我认为使用任何CDN模块(例如W3 Total Cache)都是不必要的,因为我希望整个站点都被缓存。

Update 1 Just a quick observation, the site is in WordPress. But, I don't think that is necessary to use any cdn module (like W3 Total Cache) because I want that the entire site be cached.

推荐答案

看看CloudFront发行版的行为部分。有一个对象缓存设置。如果将其设置为使用原始缓存标题,则需要返回每个请求的Cache-Control 标头。如果您的应用程序未设置Cache-Control标头,则将对象缓存设置为自定义,然后在最小TTL字段中为您的对象设置适当的TTL。

Take a look at the Behavior section of your CloudFront distribution. There's a setting there for Object Caching. If it's set to "Use Origin Cache Headers" then you need to be returning a Cache-Control header for each request. If your application isn't setting a Cache-Control header then set Object Caching to "Customize" and in the "Minimum TTL" field set an appropriate TTL for your objects.

如果您未设置自己的Cache-Control标头,而将此设置保留为默认值 Use Origin Cache Headers,那么您实际上将无法达到CDN的目的,因为通过CDN发出的每个请求都会立即失效因此通过CDN进行的每个请求仍将从源中获取。

If you are not setting your own Cache-Control header and you leave this setting to the default of "Use Origin Cache Headers" then you'll essentially be defeating the purpose of a CDN since each request made through the CDN will effectively expire immediately so every request through the CDN will still fetch from the origin.

这篇关于使用Load Balancer和Route 53时出现CloudFront问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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