简体   繁体   English

同一个 S3 存储桶中的多个网站

[英]Multiple websites in the same S3 bucket

I am trying to host multiple websites with similar subdomains in the same S3 bucket under different folders with a cloudfront distribution that redirects to each folder.我正在尝试在不同文件夹下的同一个 S3 存储桶中托管多个具有相似子域的网站,并使用重定向到每个文件夹的 cloudfront 分发。

Suppose my bucket is example.com and I want to host my angular website at sub1.example.com and another one at sub2.example.com.假设我的存储桶是 example.com,我想在 sub1.example.com 上托管我的 angular 网站,在 sub2.example.com 上托管另一个网站。 I have created folders for each of them in the bucket named sub1 and sub2.我在名为 sub1 和 sub2 的存储桶中为每个文件夹创建了文件夹。 I have also created cloudfront distributions with the origin name points to the S3 bucket and added the origin path to the corresponding folder.我还创建了 Cloudfront 分配,源名称指向 S3 存储桶,并将源路径添加到相应的文件夹。

After doing this, if I try to go to sub1.example.com it works fine.这样做之后,如果我尝试去 sub1.example.com 它工作正常。 But if I try sub1.example.com/home I get a 404 page with Code: NoSuchKey.但是如果我尝试 sub1.example.com/home,我会得到一个带有代码的 404 页面:NoSuchKey。 I think this is because S3 is trying to look for sub1/home in the bucket rather than serving the angular file in the sub1 folder.我认为这是因为 S3 试图在存储桶中查找 sub1/home,而不是在 sub1 文件夹中提供角度文件。

Is this something that can corrected?这是可以纠正的吗? I need to do this with a single S3 bucket.我需要使用单个 S3 存储桶执行此操作。

I've managed to fix the issue by following these instructions .我已经按照这些说明设法解决了这个问题。 I was able to fix the issue after adding Default Root Object when creating the cloudfront distribution and adding custom error responses in the cloudfront distribution that redirects 404 and 403 error codes to index.html .在创建 cloudfront 分发时添加默认根对象并在将404403错误代码重定向到index.html的 cloudfront 分发中添加自定义错误响应后,我能够解决该问题。

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

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