简体   繁体   English

Amazon CloudFront自定义源配置

[英]Amazon CloudFront custom origin configuration

I'd like CloudFront to first search S3 for a file, defaulting to my custom server if the image is not found. 我希望CloudFront首先搜索S3以查找文件,如果找不到图像,则默认为我的自定义服务器。 Is this possible? 这可能吗?

Unfortunately CloudFront does not have a flexible fallback mechanism. 不幸的是,CloudFront没有灵活的回退机制。

Depending on your specific use case, you could use an alternate approach where you configure CloudFront to pass all traffic trough your custom server and configure the server to proxy the request to S3 by default and, if that fails, to serve a local copy of the file. 根据您的特定用例,您可以使用备用方法,将CloudFront配置为通过自定义服务器传递所有流量,并将服务器配置为默认情况下将请求代理到S3,如果失败,则提供服务的本地副本文件。

It's also possible that, instead of actually proxying the content from S3, you just configure your server to redirect to the S3 object if it exists, to reduce the traffic that goes trough your server. 也有可能的是,您只需将服务器配置为重定向到S3对象(如果存在),而不是实际代理S3中的内容,以减少通过服务器传输的流量。

Another approach, that could possibly apply if you have a CloudFront distribution dedicated to serving images, is to set your S3 bucket as the distribution's origin and configure a custom error page for 404 errors to serve a default image that's also hosted on S3. 如果您有专门用于提供图像的CloudFront分配,则可能适用的另一种方法是将S3存储桶设置为分发的来源,并为404错误配置自定义错误页面以提供也在S3上托管的默认映像。 For this approach, see: 对于这种方法,请参阅:

http://aws.typepad.com/aws/2013/09/custom-error-pages-and-responses-for-amazon-cloudfront.html http://aws.typepad.com/aws/2013/09/custom-error-pages-and-responses-for-amazon-cloudfront.html

You could to try and set it up as a reverse proxy. 您可以尝试将其设置为反向代理。 I haven't tested it, but it falls back to your domain if the asset is missing. 我没有对它进行过测试,但如果资产丢失,它会回退到您的域名。 Who knows what the 'break' would be that you would need a fallback. 谁知道什么是'休息',你需要一个后备。 But this would help in a number of cases, such as a new admin accidentally deleting your cloudfront bucket. 但这在许多情况下会有所帮助,例如新管理员意外删除了您的云端存储桶。

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

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