[英]How can I host my website on an EC2 Server using Apache but host my images on S3 under the same sub domain?
So I have my website hosted on an EC2 server running apache. 因此,我将网站托管在运行apache的EC2服务器上。 All works fine and well.
一切正常。
The issue I'm having is that I want my images hosted on S3 (and possibly cached on CloudFront), not on my EC2 server, but want both accessible under the same domain/subdomain. 我遇到的问题是我希望将图像托管在S3上(并且可能缓存在CloudFront上),而不是在EC2服务器上,但是希望两者都可以在同一域/子域下访问。
For example say my website is www.helloworld.com
. 例如,说我的网站是
www.helloworld.com
。 I want my images to be accessible at www.helloworld.com/images/foobar.png
. 我希望可以在
www.helloworld.com/images/foobar.png
上访问我的图像。 I want foobar.png
to be hosted on S3 and not each one of my EC2 servers though. 我希望将
foobar.png
托管在S3上,而不是每个EC2服务器上。 How can I go about doing this? 我该怎么做呢?
Is there and configuration I can do in the AWS console or are there any rewrite rules I can use in Apache? 我可以在AWS控制台中进行配置吗?还是可以在Apache中使用任何重写规则? I know I could always just set up a controller that will download the images from S3 and forward them to the user, but this seems wrong to me.
我知道我总是可以设置一个控制器来从S3下载图像并将其转发给用户,但这对我来说似乎是错误的。
For that you need to put a load-balancer/proxy in front to intercept all requests and dispatch accordingly. 为此,您需要在前面放置一个负载平衡器/代理以拦截所有请求并进行相应调度。 That may not be a bad idea anyway (for availability reasons), but a separate host name for images should not be a problem, either (it's not like users will have to see or type those URL).
无论如何(出于可用性的原因)这可能不是一个坏主意,但是为图像使用单独的主机名也不应该成为问题(这不像用户必须查看或键入这些URL)。
Using CloudFront, you can have CloudFront receive the initial requests, then based on the path, forward the request to either your EC2 instance or to your S3 bucket. 使用CloudFront,您可以让CloudFront接收初始请求,然后根据路径将请求转发到EC2实例或S3存储桶。
For example, you could setup the following: 例如,您可以设置以下内容:
/images/
would use an S3 origin, and /images/
下的路径上将使用S3起源的CloudFront行为,并且
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.