简体   繁体   English

如何使用Route53将子域指向相同的S3存储桶?

[英]How to point a subdomain to the same S3 bucket using Route53?

I am creating a white-label website hosted on an S3 Static Website, for clothes stores that based on subdomain will fetch different data from the database. 我正在创建一个托管在S3静态网站上的白标网站,用于基于子域的服装店将从数据库中获取不同的数据。 But I want all to point to the same S3 Static Website, the subdomain only purpose is to differ logo and some other information. 但是我希望所有人都指向同一个S3静态网站,该子域的唯一目的是为了区分徽标和其他一些信息。 For example: 例如:

store1.maindomain.com store2.maindomain.com store1.maindomain.com store2.maindomain.com

How do I do that in Route53? 如何在Route53中做到这一点? Below is my configuration, trying CNAME pointing to wwww.maindomain.com did not worked, keep saying '404 not found'. 以下是我的配置,尝试使用CNAME指向wwww.maindomain.com无效,一直说“找不到404”。

在此处输入图片说明

The storeone.atacadapp.com CNAME will resolve to one of the AWS S3 endpoints, but there is not an S3 bucket called storeone.atacadapp.com , so S3 rejects the request. storeone.atacadapp.com CNAME将解析到一个AWS S3终端节点,但是没有名为storeone.atacadapp.com的S3存储桶,因此S3拒绝了该请求。 The key here is the host name used in the browser is the one the S3 service tries to match, not some intermediary host name. 此处的关键是浏览器中使用的主机名,这是S3服务尝试匹配的主机名,而不是某些中间主机名。

I think that your best bet is to use CloudFront to create a distribution that knows about all of the host names that you are using. 我认为最好的选择是使用CloudFront创建一个知道您正在使用的所有主机名的发行版。 In CloudFront register an origin for your S3 Static Website. 在CloudFront中注册您的S3静态网站的来源。 All requests will be forwarded to that S3 Bucket, no matter which of the registered host names has been used. 无论使用了哪个注册主机名,所有请求都将转发到该S3存储桶。

Then use some code in your application to identify the host name that was used and load properties from your database for that hostname. 然后,在应用程序中使用一些代码来标识所使用的主机名,并从数据库中为该主机名加载属性。 In JavaScript use window.location.hostname 在JavaScript中使用window.location.hostname

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

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