简体   繁体   English

如何在 CloudFront 行为中指定路径模式“/”?

[英]How can I specify a path pattern of "/" in a CloudFront behavior?

I have a CloudFront distribution with an S3 origin.我有一个带有 S3 源的 CloudFront 分配。 I want to create a behavior such that requests to the root path of the site will use a different origin (a webservice).我想创建一种行为,以便对站点根路径的请求将使用不同的来源(网络服务)。

So ideally my behaviors would be:所以理想情况下,我的行为是:

  • "/" - webservice origin “/” - 网络服务来源
  • Default (*) - S3 bucket默认 (*) - S3 存储桶

However, the above doesn't seem to work - the root request isn't caught by the first behavior.但是,上面的方法似乎不起作用——根请求没有被第一个行为捕获。

Is there any way I can accomplish what I want using path patterns?有什么方法可以使用路径模式完成我想要的吗?

The answer is that a Cache Behavior with a Path Pattern of '/' does work to only match the root url. 答案是路径模式为“/”的缓存行为确实只能匹配根URL。 In this particular case, the user also had a default root object set which gets matched before the behavior patterns. 在这种特殊情况下,用户还有一个默认的根对象集,它在行为模式之前匹配。 Removing the default root object is necessary if you wish to define a cache behavior on the root url using the '/' pattern. 如果要使用“/”模式在根URL上定义缓存行为,则必须删除默认根对象。

In addition to clearing my default root object like the other answer says, I had to set a different cache policy for my two behaviors.除了像另一个答案所说的那样清除我的默认根 object 之外,我还必须为我的两种行为设置不同的缓存策略。 This was because CloudFront was using default cache key for the object.这是因为 CloudFront 使用 object 的默认缓存键。

I first added a custom header to my origin configurations我首先在我的原始配置中添加了一个自定义 header 在此处输入图像描述

And then I made a new cache policy which referenced this custom header in the cache key.然后我制定了一个新的缓存策略,它在缓存键中引用了这个自定义 header。

在此处输入图像描述

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

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