如何仅从s3和EC2提供静态/媒体内容(仅限)? [英] How to serve static/media contents (only) from s3 and others from EC2?

查看:101
本文介绍了如何仅从s3和EC2提供静态/媒体内容(仅限)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从S3提供我的静态/媒体内容(现在是图像),但是我的网址应该是现在的样子。例如:

I want to serve my static/media contents ( images for now) from S3 but my url should be as it is now. For example:

http: //b.example.com/resources/img/me.jpg
是我当前的图像网址之一,该网址现在由本机服务器提供(EBS存储是EC2附带的)。现在,我要将这个me.jpg文件存储在s3的存储桶中,然后如果有人键入上面的URL,那么它将是从那里带来的。

http://example.com/resources/img/me.jpg is one of my current image url which is now being served from the native server (EBS storage came with EC2). Now I want to store this me.jpg file in a bucket of s3 and then if someone types the above url it is brought from there.

我知道这样做是可能的创建一个存储段名称作为example.com和www.example.com,然后为 s3-website-region.amazonaws.com

I know this is possible by creating a bucket name as example.com and www.example.com and then configuring Route 53 CNAME (Alias) for s3-website-region.amazonaws.com

但是,当我输入 http://example.com时会发生什么/ blog / cool-stuff-blog 吗?
这不是静态/媒体内容!它需要执行服务器端代码(Python / PHP)。

但是使用我当前工作域的上述配置,将会发生什么?它会尝试从S3提供一些内容并失败吗?

我该如何完成?请不要说拥有static.example.com之类的子域,并向其提供所有静态文件请求。对我来说,这是不可接受的。我要使用完全相同的域名。

How can I get it done? Please don't say have a subdomain like static.example.com and serve all static file requests to that. For me that's unacceptable now. I want to use the exact same domain name.

推荐答案

创建CloudFront分配。

Create a CloudFront distribution.

配置2个原始服务器,一个是您的主服务器,另一个是您的S3存储桶。

Configure 2 "origin" servers, one being your main server, the other as your S3 bucket.

配置默认的 * 路径模式以路由到主服务器,并配置 / resources / * 指向存储桶(或任何需要的路径,您可以配置

Configure the default * path pattern to route to your main server, and configure /resources/* to point to your bucket (or whatever paths you need, you can configure more than one).

CloudFront将每个请求与路径模式进行匹配,并根据第一个匹配模式将每个请求转发到适当的后端。

CloudFront matches each request against the path patterns, and will forward each request to the appropriate back-end, based on the first matching pattern.

如果您不想使用CloudFront的缓存功能,可以通过配置选项将所有请求标头转发到源来禁用它。

If you don't want to use CloudFront's caching capability, you can disable it by configuring the option to "forward all request headers to the origin."

将您的域名添加到与您的分布关联的备用域名列表中。

Add your domain name to the list of alternate domain names associated your distribution.

选择适合您的工作负载的CloudFront定价层和预算-如果您的受众群体不在您身边,可以通过禁用更昂贵的CloudFront边缘位置来降低成本。

Select the CloudFront pricing tier that is appropriate for your workload and budget -- you can potentially keep costs a little lower by disabling more expensive CloudFront edge locations if that isn't where your audience is.

经过测试后,将您的域名指向CloudFront发行版,并在Route 53中带有别名A记录。

After testing, point your domain name to the CloudFront distribution, with an Alias A-Record in Route 53.

如果要通过单个主机名从多个存储桶或后端服务器群集中的不同路径提供内容,也可以添加其他来源。

You can also add additional "origins" if you want to serve content from different paths out of multiple buckets or back-end server clusters, through a single hostname.

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html

这篇关于如何仅从s3和EC2提供静态/媒体内容(仅限)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆