Cloudfront:设置与 Origin 的 s3 路径差异
Cloudfront: setting s3 path difference from Origin
缓存行为设置,我用
s3/*
将请求重定向到 s3 文件夹,但我不想将我的图像放在名为 s3 的文件夹下,而是在 s3 存储桶下重定向,如下所示:
xxxx.cloudfront.com/s3/images/1.png -> bucket_name/images/1.png
不是
xxxx.cloudfront.com/s3/images/1.png -> bucket_name/s3/images/1.png
请教我如何这样配置。
很遗憾,这是不可能的。 Cloudfront 会将确切的请求路径映射回原点。它为操纵原始路径提供的唯一选项是添加前缀 - 它不允许从路径中删除任何内容。
Origin Path 包含有关源路径设置的详细信息 - 但您会从该页面看到没有选项可以删除请求路径的任何部分。
我认为这是不可能的。原始路径可以重定向到子目录(例如 index.htm
-> production/index.htm
),但 CloudFront 无法去除路径部分。
查看文档:Origin Path
部分选项:
- 使用单独的分发而不是路径前缀
s3
- 只需将
s3/
放在文件名的前面(实际上使用完整路径)
您可以这样做with lambdas这是相关的 lambda 代码段。
exports.handler = (event, context, callback) => {
// this is the request we want to re-map
var request = event.Records[0].cf.request;
// the request has a 'uri' property which is the value we want to overwrite
// rewrite the url applying your custom logic
request.uri = 'some custom logic here to rewrite the url';
// quit the lambda and let the request chain continue
callback( null, request );
};
缓存行为设置,我用
s3/*
将请求重定向到 s3 文件夹,但我不想将我的图像放在名为 s3 的文件夹下,而是在 s3 存储桶下重定向,如下所示:
xxxx.cloudfront.com/s3/images/1.png -> bucket_name/images/1.png
不是
xxxx.cloudfront.com/s3/images/1.png -> bucket_name/s3/images/1.png
请教我如何这样配置。
很遗憾,这是不可能的。 Cloudfront 会将确切的请求路径映射回原点。它为操纵原始路径提供的唯一选项是添加前缀 - 它不允许从路径中删除任何内容。
Origin Path 包含有关源路径设置的详细信息 - 但您会从该页面看到没有选项可以删除请求路径的任何部分。
我认为这是不可能的。原始路径可以重定向到子目录(例如 index.htm
-> production/index.htm
),但 CloudFront 无法去除路径部分。
查看文档:Origin Path
部分选项:
- 使用单独的分发而不是路径前缀
s3
- 只需将
s3/
放在文件名的前面(实际上使用完整路径)
您可以这样做with lambdas这是相关的 lambda 代码段。
exports.handler = (event, context, callback) => {
// this is the request we want to re-map
var request = event.Records[0].cf.request;
// the request has a 'uri' property which is the value we want to overwrite
// rewrite the url applying your custom logic
request.uri = 'some custom logic here to rewrite the url';
// quit the lambda and let the request chain continue
callback( null, request );
};