Map multiple subdomains to same S3-bucket

左心房为你撑大大i 提交于 2019-12-20 09:38:35

问题


Is there some way to map multiple (thousands) of subdomains to one s3-bucket? If so is it also possible to map it to a specific path in the bucket for each subdomain?

I want test1.example.com to map to mybucket/test1 and test2.example.com to map to mybucket/test2.

I know the last part isn't possible with normal dns-records but maybe there is some nifty Route 53 feature?


回答1:


It's not possible with S3 directly. You can only use 1 subdomain with an S3 bucket.

However you can map multiple subdomains to a Cloudfront distribution.

Update (thanks to @SimonHutchison's comment below)

You can now map up to 100 alternate domains to a Cloudfront distribution - see http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html#limits_cloudfront

You can also use a wildcard to map any subdomain to your distribution:

Using the * Wildcard in Alternate Domain Names

When you add alternate domain names, you can use the * wildcard at the beginning of a domain name instead of specifying subdomains individually. For example, with an alternate domain name of *.example.com, you can use any domain name that ends with example.com in your object URLs, such as www.example.com, product-name.example.com, and marketing.product-name.example.com. The name of an object is the same regardless of the domain name, for example:

www.example.com/images/image.jpg

product-name.example.com/images/image.jpg

marketing.product-name.example.com/images/image.jpg




回答2:


Starting from October 2012 Amazon introduced a function to handle redirects (HTTP 301) for S3 buckets. You can read the release notes here and refer to this link for configuration via Console / API.

From AWS S3 docs :

  • Redirects all requests If your root domain is example.com and you want to serve requests for both http://example.com and http://www.example.com, you can create two buckets named example.com and www.example.com, maintain website content in only one bucket, say, example.com, and configure the other bucket to redirect all requests to the example.com bucket.

  • Advanced conditional redirects You can conditionally route requests according to specific object key names or prefixes in the request, or according to the response code. For example, suppose that you delete or rename an object in your bucket. You can add a routing rule that redirects the request to another object. Suppose that you want to make a folder unavailable. You can add a routing rule to redirect the request to another page, which explains why the folder is no longer available. You can also add a routing rule to handle an error condition by routing requests that return the error to another domain, where the error will be processed.



来源:https://stackoverflow.com/questions/6130985/map-multiple-subdomains-to-same-s3-bucket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!