简体   繁体   English

S3 + Cloudfront + Route53 奇怪的缓存问题

[英]S3 + Cloudfront + Route53 weird caching issue

I have a static website using S3, Cloudfront and Route53.我有一个使用 S3、Cloudfront 和 Route53 的 static 网站。 I had version 1 and now I updated to version 2.我有版本 1,现在更新到版本 2。

  • If I view the website using the S3 endpoint ( http://abc.s3-website-eu-west-1.amazonaws.com/ ) I see version 2.如果我使用 S3 端点 ( http://abc.s3-website-eu-west-1.amazonaws.com/ ) 查看网站,我会看到版本 2。
  • If I use the Cloudfront endpoint ( https://xyz.cloudfront.net/ ) I see version 2 again.如果我使用 Cloudfront 端点 ( https://xyz.cloudfront.net/ ),我会再次看到版本 2。
  • If I use the domain I have configured in Route53 (A record pointing to the cloudfront distribution) I see version 1. I have not setup any TTL for the DNS records (default behavior) and this has been going on for ~1 week now.如果我使用我在 Route53 中配置的域(指向云端分布的记录),我会看到版本 1。我没有为 DNS 记录(默认行为)设置任何 TTL,这已经持续了大约 1 周。

Some extra checks:一些额外的检查:

dig A xyz.cloudfront.net and dig A mydomain.com point to the same IPs. dig A xyz.cloudfront.netdig A mydomain.com指向相同的 IP。

And the output of curl is describing the previous situation (version 1) where mydomain.com was configured to point to www.example.com . curl 的 output 描述了之前的情况(版本 1),其中 mydomain.com 配置为指向www.example.com Now I have it pointing directly to the cloudfront distribution现在我让它直接指向云端分布

curl -sD - https://example.com -o /dev/null
HTTP/1.1 302 Moved Temporarily
Content-Length: 0
Connection: keep-alive
Server: CloudFront
Location: https://www.example.com/
X-Cache: Miss from cloudfront
Via: 1.1 qwe.cloudfront.net (CloudFront)
...
curl -sD - https://xyz.cloudfront.net -o /dev/null
HTTP/2 200
content-type: text/html
content-length: 537
date: Fri, 18 Nov 2022 20:35:41 GMT
last-modified: Tue, 15 Nov 2022 10:09:03 GMT
etag: "..."
server: AmazonS3
x-cache: Miss from cloudfront
via: 1.1 bla.cloudfront.net (CloudFront)
...

Is there anything else I could check to find out what is misconfigured?还有什么我可以检查以找出配置错误的东西吗?

The DNS server (Route53) and the TTL on those DNS records are entirely irrelevant here. DNS 服务器 (Route53) 和那些 DNS 记录上的 TTL 在这里完全不相关。 Those have nothing to do with content caching.这些与内容缓存无关。

Your curl commands show your requests are being routed to different CloudFront edge nodes ( qwe.cloudfront.net and bla.cloudfront.net ).您的curl命令显示您的请求被路由到不同的 CloudFront 边缘节点( qwe.cloudfront.netbla.cloudfront.net )。

It appears that one of those nodes had served a request for your website before, so it had a cached version stored, which it is still serving when you make new requests that hit that CloudFront edge node now.看起来这些节点中的一个之前曾为您的网站提供过请求,因此它存储了一个缓存版本,当您现在发出新请求命中该 CloudFront 边缘节点时,它仍在提供服务。 The other node didn't have a cached version stored, so when your request hit it, it went back to the origin (S3) and pulled in the latest version.另一个节点没有存储缓存版本,因此当您的请求命中它时,它会返回到原点 (S3) 并提取最新版本。

This is pretty much the expected behavior of CloudFront, or any other CDN, when you publish new content on your origin server without notifying the CDN that it needs to clear the old cached content.当您在原始服务器上发布新内容而不通知 CDN 它需要清除旧的缓存内容时,这几乎是 CloudFront 或任何其他 CDN 的预期行为。 You need to tell CloudFront to invalidate the cache , which will cause it to remove the cached version of your content from all edge locations.您需要告诉 CloudFront 使缓存无效,这将导致它从所有边缘位置删除内容的缓存版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM