简体   繁体   English

动态Route53子域转发

[英]Dynamic Route53 sub-domain forwarding

I'm trying to redirect a Route53 domain to another Route53 domain, while maintaining the subdomain. 我正在尝试将Route53域重定向到另一个Route53域,同时保持子域。

I have a Route 53 hosted zone for example.com that contains my main website. 我在example.com上有一个Route 53托管区域,其中包含我的主要网站。

I have another Route 53 hosted zone for example.co.uk which I redirect to example.com using the S3 static website redirection rules (as described on https://stackoverflow.com/a/14289082/918030 ) 我还有一个Route 53托管区域example.co.uk,它使用S3静态网站重定向规则(如https://stackoverflow.com/a/14289082/918030所述 )重定向到example.com。

This works great for the root domain but I would like to map subdomains as in the following examples: 这对于根域非常有用,但是我想映射子域,如以下示例所示:

sub1.example.co.uk   -->    sub1.example.com

sub2.example.co.uk   -->    sub2.example.com

...

sub999.example.co.uk -->    sub999.example.com

I know this can be done by creating a new S3 bucket for each sub-domain and configuring the appropriate S3 static website redirection rules but I was wondering if there is a way to do this dynamically so *.example.co.uk forwards to *.example.com. 我知道可以通过为每个子域创建一个新的S3存储桶并配置适当的S3静态网站重定向规则来做到这一点,但是我想知道是否有一种方法可以动态地做到这一点,因此* .example.co.uk转发给* .example.com。 Preferable without having to run a separate EC2 instance (running nginx) 最好无需运行单独的EC2实例(运行nginx)

Thanks! 谢谢!

Stijn 斯蒂金

There's not a simple way to do this with any combination of off-the-shelf AWS services (excluding EC2, of course)... other than creating a unique bucket for every subdomain you want to redirect. 除了现有的AWS服务(当然不包括EC2)的任何组合之外,没有一种简单的方法来实现此目的……除了为要重定向的每个子域创建唯一的存储桶之外。 The 100 buckets per account limit is now a soft limit rather than a hard limit, so you now can -- by presenting a reasonable use case -- request that AWS support increase your bucket limit. 每个帐户100个存储桶限制现在是一个软限制,而不是一个硬限制,因此您现在可以-通过提出一个合理的用例-要求AWS支持增加您的存储桶限制。

That doesn't solve the problem of having to provision them, of course, though a single wildcard CNAME in Route 53 would allow you to route then en masse to S3, using the root regional website endpoint as the target, at least the way S3 works at the moment, which means relying on some undocumented S3 behavior that seems unlikely to change, but could change nevertheless. 当然,这并没有解决必须提供它们的问题,尽管Route 53中的单个通配符CNAME允许您使用根区域网站终结点作为目标,然后至少以S3的方式将其整体路由到S3。目前可以正常工作,这意味着依赖于一些未记录的S3行为,这些行为似乎不太可能改变,但是仍然可以改变。

Requests for hostnames not matching already-created buckets would still go to S3 and return a "NoSuchBucket" error, which presents an issue of its own... in fact, it's food for thought in your pursuit of wildcards. 对与已创建的存储桶不匹配的主机名的请求仍将转到S3并返回“ NoSuchBucket”错误,这本身就是一个问题……实际上,这是您寻求通配符时的考虑因素。

Two paragraphs back, I mentioned leveraging some undocumented behavior with a wildcard CNAME pointing to S3. 在前两段中,我提到利用通配符CNAME指向S3的一些未记录的行为。 Imagining being called out by would-be commenters who have read the documentation but have not experimented with the actual behavior of S3, I set up a wildcard CNAME in one of my Route 53 hosted zones, pointing *.mysterystring.example.com to s3-website-us-west-2.amazonaws.com . 想象被已经阅读了文档但未尝试过S3实际行为的潜在评论者*.mysterystring.example.com ,我在Route 53托管区域之一中设置了通配符CNAME,将*.mysterystring.example.com指向s3-website-us-west-2.amazonaws.com This is not how the documentation says you should do it, but sure enough, that works exactly as I anticipated... whatever you put in place of the * , if you have a bucket named after the full domain name in us-west-2, S3 serves it up, on request. 这不是文档中所说的应该这样做的方式,但是可以肯定的是,它的工作方式完全符合我的预期……如果您用*替换了* ,那么如果您在us-west- 2,S3应要求提供服务。 If not, it's a "NoSuchBucket" error, complete with the bucket name S3 tried to find, but couldn't. 如果不是,则为“ NoSuchBucket”错误,并带有试图找到但未找到的存储桶名称S3。 So, why didn't I mention the actual test setup domain to prove my point? 那么,为什么我没有提到实际的测试设置域来证明我的观点呢? Well... Anybody sniffing around could create a bucket using one of unused hostnames matching that wildcard, and have a web site at my domain, hosted in S3 with that setup with no configuration on my part and without my knowledge. 好吧... 随便找一个人都可以使用一个与该通配符匹配的未使用主机名创建一个存储桶,并在我的域中拥有一个网站,该网站托管在S3中,并且该设置没有我的任何配置,并且我不知道。 (!?) Sure, they'll be billed for the bucket, but hey, free domain squatting! (!?)当然,他们会向您收取水桶的费用,但嘿,免费域名抢注! The next thing you know, they're impersonating me, stealing customers, who knows? 您知道的下一件事,他们在冒充我,窃取客户,谁知道呢?

So, red flag: do beware the implications of wildcard-redirecting unprovisioned resources. 因此,危险信号:请注意不要使用通配符重定向未配置资源的含义。

On the other hand, if you want to redirect everything (and you take steps to make sure the destination is genuinely a dead-end that can't be surreptitiously claimed for unused hostnames), an EC2 instance wouldn't be a bad deal. 另一方面,如果您想重定向所有内容(并采取步骤以确保目的地确实是一个死胡同,不能私自声明未使用的主机名),那么EC2实例将不是一件坏事。 A t2.micro can easily service hundreds of thousands of lightweight requests, like redirects, per day (I have one that routinely handles over 300k/day and always has spare CPU credits) for < $10/mo. 一个t2.micro每天可以轻松地为成千上万的轻量级请求提供服务,例如重定向(我的请求每天例行处理30万以上,并且总是有备用的CPU信用),而每月的费用却少于$ 10。

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

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