[英]Serve S3 behind cloudfront with 2 origins
我有 2 个来源的 CF 发行版:
此分配有一个备用 CNAME。
根据路径,我希望 S3 提供一些文件,而 ALB 提供其他文件。
我有以下路径的 3 种行为:
assets/*
以 S3 为来源uploads/*
以 alb 为原点default
具有相同的uploads/*
的来源,但具有不同的缓存策略在 S3 存储桶中有 2 个文件夹: svg
和v2
当我尝试
curl -I https://myalternate.domain.name/assets/svg/mysvg.svg
或curl -I https://xxxxxx.cloudfront.net/assets/svg/mysvg.svg
我有404。
如果我从 web 得到它们,我可以看到
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist</Message>
<BucketName>myalternate.domain.name or cloudfront endpoint</BucketName>
<RequestId>Q7Z1NAP8HV0PCEM4</RequestId>
</Error>
对于其他路径,一切都很好。
我错过了什么?
What the CloudFront does when it receives the https://myalternate.domain.name/assets/svg/mysvg.svg
request is that it will fetch the object stored in S3 using the key assets/svg/mysvg.svg
. 这就是它返回 404 的原因,因为 object 的实际键是svg/mysvg.svg
。 解决方案是向 S3 中的每个 object 添加assets/
前缀,或者使用 Lambda@Edge function 重写源请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.