在 AmazonRoute53中设置基于 DNS 的 URL 转发

我正在设置亚马逊路由53的转发。我的上一个域名服务(Nettica)允许我将请求路由到“ aws.example.com”到“ https://myaccount.signin.aws.amazon.com/console/”。

Route53支持这个功能吗?

Nettica 是如何做到这一点的? 它是否插入了一个特殊的 a、 CNAME、 PTR 或 TXT 记录?

195468 次浏览

更新

虽然我的原始答案下面仍然是有效的,可能有助于理解的原因,基于 DNS 的网址转发不能通过 亚马逊53号公路开箱即用,我强烈建议检查 Vivek M。 Chawla 的 绝对聪明的间接解决方案通过同时介绍 Amazon S3对网站重定向的支持,实现一个自包含服务器少,因此免费解决方案在 AWS 只有这样。

  • 实现一个自动化的解决方案来生成这样的重定向是留给读者的一个练习,但是请通过发布您的解决方案来赞扬 Vivek 的史诗般的答案;)

原始答案

Nettica 必须为此运行一个自定义重定向解决方案,这里有一个问题:

您可以为 myaccount.signin.aws.amazon.com创建类似于 aws.example.com的 CNAME 别名,但是,在本例中,DNS 没有为类似于 console的子目录提供官方别名支持。

  • 遗憾的是,AWS 在触发 https://myaccount.signin.aws.amazon.com/时似乎并没有默认地这样做(我刚刚尝试了) ,因为它会立即解决你的问题,并且在第一时间就很有意义; 此外,在它们那一端配置应该非常容易。

出于这个原因,一些 DNS 提供商显然已经实现了一个自定义解决方案,允许重定向到子目录; 我大胆猜测,他们基本上是促进了 CNAME 别名为自己的域,并再次从那里重定向到最终目的地通过一个立即 HTTP 3xx 重定向

因此,要实现相同的结果,需要有一个运行这些重定向的 HTTP 服务,当然这不是人们所希望的简单解决方案。也许/但愿有人能想出一个更聪明的方法。

我能够使用 nginx 处理301重定向到 awssignin 页面。

转到 nginx conf 文件夹(在我的例子中是 /etc/nginx/sites-available,我在其中为启用的 conf 文件创建到 /etc/nginx/sites-enabled的符号链接)。

然后添加一个重定向路径

server {
listen 80;
server_name aws.example.com;
return 301 https://myaccount.signin.aws.amazon.com/console;
}

如果您正在使用 nginx,那么很可能需要额外的服务器块(apache 术语中为 viralhosts)来处理区域顶点(example.com) ,或者以任何方式设置它。确保将其中一个设置为默认服务器。

server {
listen 80 default_server;
server_name example.com;
# rest of config ...
}

在路线53中,为 aws.example.com添加一个 A record,并将该值设置为用于区域顶点的相同 IP。

我遇到了和 Saurav 描述的完全相同的问题,但我真的需要找到一个解决方案,不需要任何东西,除了53号公路和 S3公路。我为我的博客创建了一个指南,详细介绍了我所做的事情。

这是我想到的。


目的

仅使用 Amazon S3和 Amazon Route 53中提供的工具,创建一个 URL 重定向,自动将 http://url-redirect-example.vivekmchawla.com转发到 AWS 控制台登录页面,该登录页面别名为“ MyAccount”,位于 https://myaccount.signin.aws.amazon.com/console/

本指南将教您设置 URL 转发到任何 URL,而不仅仅是来自亚马逊的 URL。您将学习如何设置转发到特定文件夹(如我的示例中的“/sole”) ,以及如何将重定向的协议从 HTTP 更改为 HTTPS (反之亦然)。


第一步: 创建 S3存储桶

Open the S3 Management Console and click "Create Bucket"

打开 S3管理控制台并单击“ CreateBucket”。


第二步: 命名你的 S3桶

Name your S3 Bucket

  1. 选择一个桶名。这一步真的很重要!必须将 bucket 的名称与要设置用于转发的 URL 完全相同。在本指南中,我将使用“ url-redirect-example.vivekmchawla.com”这个名称。

  2. 选择最适合你的区域。如果你不知道,保持默认。

  3. 不用担心设置日志,准备好后点击“创建”按钮就可以了。


步骤3: 启用静态网站托管并指定路由规则

Enable Static Website Hosting and Specify Routing Rules

  1. 在属性窗口中,打开“静态网站托管”的设置。
  2. 选择“启用网站托管”选项。
  3. 输入“ Index Document”的值。S3永远不会为这个对象(文档)提供服务,您也永远不必上传它。随便用什么名字。
  4. 打开“编辑重定向规则”的设置。
  5. 完整地粘贴下面的 XML 片段。

    <RoutingRules>
    <RoutingRule>
    <Redirect>
    <Protocol>https</Protocol>
    <HostName>myaccount.signin.aws.amazon.com</HostName>
    <ReplaceKeyPrefixWith>console/</ReplaceKeyPrefixWith>
    <HttpRedirectCode>301</HttpRedirectCode>
    </Redirect>
    </RoutingRule>
    </RoutingRules>
    

If you're curious about what the above XML is doing, visit the AWM Documentation for "Syntax for Specifying Routing Rules". A bonus technique (not covered here) is forwarding to specific pages at the destination host, for example http://redirect-destination.com/console/special-page.html. Read about the <ReplaceKeyWith> element if you need this functionality.


Step 4: Make Note of Your Redirect Bucket's "Endpoint"

Make a note of your Redirect Bucket's Endpoint

Make note of the Static Website Hosting "endpoint" that Amazon automatically created for this bucket. You'll need this for later, so highlight the entire URL, then copy and paste it to notepad.

CAUTION! At this point you can actually click this link to check to see if your Redirection Rules were entered correctly, but be careful! Here's why...

Let's say you entered the wrong value inside the <Hostname> tags in your Redirection Rules. Maybe you accidentally typed myaccount.amazon.com, instead of myaccount.signin.aws.amazon.com. If you click the link to test the Endpoint URL, AWS will happily redirect your browser to the wrong address!

After noticing your mistake, you will probably edit the <Hostname> in your Redirection Rules to fix the error. Unfortunately, when you try to click the link again, you'll most likely end up being redirected back to the wrong address! Even though you fixed the <Hostname> entry, your browser is caching the previous (incorrect!) entry. This happens because we're using an HTTP 301 (permanent) redirect, which browsers like Chrome and Firefox will cache by default.

If you copy and paste the Endpoint URL to a different browser (or clear the cache in your current one), you'll get another chance to see if your updated <Hostname> entry is finally the correct one.

To be safe, if you want to test your Endpoint URL and Redirect Rules, you should open a private browsing session, like "Incognito Mode" in Chrome. Copy, paste, and test the Endpoint URL in Incognito Mode and anything cached will go away once you close the session.


Step 5: Open the Route53 Management Console and Go To the Record Sets for Your Hosted Zone (Domain Name)

Open the Route 53 Management Console to Add Record Sets to your Hosted Zone

  1. Select the Hosted Zone (domain name) that you used when you created your bucket. Since I named my bucket "url-redirect-example.vivekmchawla.com", I'm going to select the vivekmchawla.com Hosted Zone.
  2. Click on the "Go to Record Sets" button.

Step 6: Click the "Create Record Set" Button

Click the Create Record Set button

Clicking "Create Record Set" will open up the Create Record Set window on the right side of the Route53 Management Console.


Step 7: Create a CNAME Record Set

Create a CNAME Record Set

  1. In the Name field, enter the hostname portion of the URL that you used when naming your S3 bucket. The "hostname portion" of the URL is everything to the LEFT of your Hosted Zone's name. I named my S3 bucket "url-redirect-example.vivekmchawla.com", and my Hosted Zone is "vivekmchawla.com", so the hostname portion I need to enter is "url-redirect-example".

  2. Select "CNAME - Canonical name" for the Type of this Record Set.

  3. For the Value, paste in the Endpoint URL of the S3 bucket we created back in Step 3.

  4. Click the "Create Record Set" button. Assuming there are no errors, you'll now be able to see a new CNAME record in your Hosted Zone's list of Record Sets.


Step 8: Test Your New URL Redirect

Open up a new browser tab and type in the URL that we just set up. For me, that's http://url-redirect-example.vivekmchawla.com. If everything worked right, you should be sent directly to an AWS sign-in page.

Because we used the myaccount.signin.aws.amazon.com alias as our redirect's destination URL, Amazon knows exactly which account we're trying to access, and takes us directly there. This can be very handy if you want to give a short, clean, branded AWS login link to employees or contractors.

All done! Your URL forwarding should take you to the AWS sign-in page.


Conclusions

I personally love the various AWS services, but if you've decided to migrate DNS management to Amazon Route 53, the lack of easy URL forwarding can be frustrating. I hope this guide helped make setting up URL forwarding for your Hosted Zones a bit easier.

If you'd like to learn more, please take a look at the following pages from the AWS Documentation site.

Cheers!

AWS 支持指出了一个更简单的解决方案。它基本上与@Vivek M. Chawla 提出的想法相同,只是实现更简单。

AWS S3:

  1. 创建一个名为桶与您的完整域,如 aws.example.com
  2. 在 bucket 属性中,选择 Redirect all requests to another host name并输入 URL: https://myaccount.signin.aws.amazon.com/console/

AWS 路线第53号:

  1. 创建一个记录集类型 A。将 Alias 更改为 Yes。单击 < code > Alias 目标 字段,并选择您在前面的 台阶。

参考资料: 如何使用 AmazonWebServices 重定向域

AWS 官方文档: 有没有一种方法可以使用亚马逊路由53将一个域重定向到另一个域?

如果您仍然有问题的简单方法,创建一个空桶,然后 Redirect all requests to another host name下静态网络托管属性通过控制台。确保你在53号公路上设置了2个 A 记录,一个是 final-destination.com,一个是 redirect-to.final-destination.com。每个工具的设置都是相同的,但是名称不同,所以它与您为桶/URL 设置的名称相匹配。