CloudFront issue when using Load Balancer and Route 53

断了今生、忘了曾经 提交于 2019-12-11 05:14:39

问题


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

Here is the current scenario:

  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?

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/26569077/cloudfront-issue-when-using-load-balancer-and-route-53

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!