[英]Serve S3 behind cloudfront with 2 origins
I've a CF distribution with 2 origins:我有 2 个来源的 CF 发行版:
This distribution has an alternate CNAME.此分配有一个备用 CNAME。
Depending on the path, I want some files being served by S3, other by the ALB.根据路径,我希望 S3 提供一些文件,而 ALB 提供其他文件。
I've 3 behaviours with the following paths:我有以下路径的 3 种行为:
assets/*
with S3 as origin assets/*
以 S3 为来源uploads/*
with the alb as origin uploads/*
以 alb 为原点default
with the same uploads/*
's origin but with a different cache policy default
具有相同的uploads/*
的来源,但具有不同的缓存策略In the S3 bucket there are 2 folders: svg
and v2
在 S3 存储桶中有 2 个文件夹:
svg
和v2
when I try当我尝试
curl -I https://myalternate.domain.name/assets/svg/mysvg.svg
or curl -I https://myalternate.domain.name/assets/svg/mysvg.svg
或curl -I https://xxxxxx.cloudfront.net/assets/svg/mysvg.svg
I've 404.我有404。
If I get them from web I can see如果我从 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>
For the other paths everything is alright.对于其他路径,一切都很好。
What did I miss?我错过了什么?
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
. 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
. That's why it returns 404 since the actual key of that object is svg/mysvg.svg
.这就是它返回 404 的原因,因为 object 的实际键是
svg/mysvg.svg
。 The solution is to either add assets/
prefix to every object in S3 or use a Lambda@Edge function to rewrite the origin request.解决方案是向 S3 中的每个 object 添加
assets/
前缀,或者使用 Lambda@Edge function 重写源请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.