简体   繁体   English

如何使用Apache在EC2服务器上托管网站,但在同一子域下的S3上托管映像?

[英]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: 例如,您可以设置以下内容:

  • A CloudFront behaviour that upon a path under /images/ would use an S3 origin, and /images/下的路径上将使用S3起源的CloudFront行为,并且
  • A default (for everything else) would go to your EC2 instance origin. 默认设置(对于其他所有设置)将进入您的EC2实例来源。

暂无
暂无

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

相关问题 两个域及其子域映射到相同的IP,所以如何将不同的应用程序托管到相同的tomcat服务器? - Two domain & their sub-domain are mapped to the same IP so how can i host my different application to the same tomcat server? Amazon EC2 如何托管我自己的内容? 坚持进行工作测试 apache 页面 - Amazon EC2 How Do I host My Own Content? Stuck on having a working test apache page 如何在我的 ec2 ami apache 服务器上启用 https - How to I enable https on my ec2 ami apache server 如何在一个Amazon EC2实例下托管多个网站? - How Can I Host Multiple Websites Under One Amazon EC2 Instance? 在EC2上使用Apache时,如何允许我的apache用户上载到用户目录? - How can I allow my apache user to upload to user directory when using Apache on EC2? 将顶级域移动到子目录以使用Apache在同一域上托管多个站点 - Move top level domain to sub-directory to host multiple sites on same domain using Apache 如何在带有Apache 2.4.18的ec2上添加虚拟主机? - How to add Virtual host on ec2 wiith Apache 2.4.18? 使用Vagrant,如何从主机操作系统的Web浏览器访问apache虚拟主机 - Using Vagrant, how can I access an apache virtual host from the host OS's web browser 如何同时在 Nginx 和 Apache 上托管网站(部分) - How do I host a website (parts of it) on Nginx and Apache at the same time 如何配置 AWS EC2 apache 服务器 - How I can make a configure AWS EC2 apache server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM