问题
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:
- Route 53 with A alias pointing to CloudFront (for my naked domain and www)
- CloudFront with Origin Domain Name = load balancer DNS name, also the cname are configured to naked domain and www
- Load Balancer with EC2
- 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