具有2个起源(不同存储桶)且都托管存储桶根的Cloudfront

时间:2020-10-07 09:46:10

标签: amazon-web-services amazon-s3 amazon-cloudfront

我有一个CDN和2个存储桶

  • 一个存储桶正在使用默认行为,因此可以通过CDN URL img.png

    访问cdn.com/img.png
  • 一个存储桶正在使用/path行为,因此CDN中路由到/ path的所有内容都应进入该存储桶。当我将其放在存储桶中时,它会起作用:path/test.png。我可以访问cdn.com/path/test.png

我想要的是将test.png放在我的存储桶的根中,而没有前缀path/。这可能(不使用lambda @ edge)吗?

1 个答案:

答案 0 :(得分:0)

如果要重写路径,则必须使用lambda @ edge。

如果可以使用301重定向,则可以尝试在S3存储桶和use the following redirection rule上启用静态网站托管:

<RoutingRules>
  <RoutingRule>
    <Condition>
      <KeyPrefixEquals>path/</KeyPrefixEquals>
    </Condition>
    <Redirect>
      <ReplaceKeyPrefixWith/>
    </Redirect>
  </RoutingRule>
</RoutingRules>