简体   繁体   English

使用 AWS 负载均衡器的 A(主机)记录

[英]A(Host) Records with AWS Load Balancer

I have a question regarding AWS Load Balancers.我有一个关于 AWS 负载均衡器的问题。

I can point my CNAME www to my load balancer's DNS perfectly and i know it will always work, BUT I also need to point the @ record to the load balancer so people can access mysite.com instead of www.mysite.com and hit the loadbalancer.我可以完美地将我的CNAME www 指向我的负载均衡器的 DNS 并且我知道它总是可以工作,但我还需要将 @ 记录指向负载均衡器,以便人们可以访问mysite.com而不是www.mysite.com负载均衡器。

The problem is that the A Records have to point an IP Address so i can't point to the DNS and the IP of the load balancer keeps changing so mysite.com stops working. The problem is that the A Records have to point an IP Address so i can't point to the DNS and the IP of the load balancer keeps changing so mysite.com stops working.

Can anyone recommend me a work around for this?谁能推荐我解决这个问题?

Here are the steps.以下是步骤。

  1. Click create record set点击创建记录集
  2. For zone apex record just leave the name field blank对于区域顶点记录,只需将名称字段留空
  3. Select the type of alias you want to make A or AAAA (all steps after this are the same for both types) Select 您想要创建 A 或 AAAA 的别名类型(这两种类型之后的所有步骤都相同)
  4. Select the yes radio button. Select 是单选按钮。
  5. Open the EC2 console in another tab and navigate to the list of your load balancers.在另一个选项卡中打开 EC2 控制台并导航到负载均衡器列表。 Click on the load balancer and look at the description tab in the pane below the list.单击负载均衡器并查看列表下方窗格中的描述选项卡。 Sample output below样品 output 下面

在此处输入图像描述

You need a web server that does a redirect instead.您需要一个执行重定向的 web 服务器。 ie you want to send a 301 "Moved Permanently" from the web server that mysite.com points to, redirecting to www.mysite.com.即您想从 mysite.com 指向的 web 服务器发送 301“永久移动”,重定向到 www.mysite.com。 Then you CNAME www.mysite.com over to Amazon.然后您将 www.mysite.com 命名为 Amazon。

Some DNS hosting providers will do this for you, I think GoDaddy does.一些 DNS 托管服务提供商会为您执行此操作,我认为 GoDaddy 会这样做。 Otherwise you need to set up a web server you can configure to do this.否则,您需要设置一个 web 服务器,您可以配置执行此操作。

The Apache configuration in .htaccess could be for example: .htaccess 中的 Apache 配置可以是例如:

RewriteEngine on
RewriteCond %{HTTP_HOST} mysite.com
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=permanent]

If you have a generic Apache-hosting site that supports .htaccess then you could do that.如果您有一个支持 .htaccess 的通用 Apache 托管站点,那么您可以这样做。

Anyway what you're looking for is a redirect.无论如何,您正在寻找的是重定向。

Technically, it can't be done.从技术上讲,这是做不到的。 You can only refer to an Amazon load balancer using a CNAME and it breaks DNS rules to assign a CNAME to the root of the domain because of issues this causes with MX records.您只能使用 CNAME 引用 Amazon 负载均衡器,它会违反 DNS 规则以将 CNAME 分配给域的根目录,因为这会导致 MX 记录出现问题。

That said, some DNS provider do allow you to do this, Amazon's route 53 doesn't, but Zoneedit allows it (with a warning).也就是说,一些 DNS 提供商确实允许您这样做,亚马逊的 53 号路线不允许这样做,但Zoneedit允许这样做(带有警告)。 If you don't need your email to work for that domain, this is a solution.如果您不需要 email 为该域工作,这是一个解决方案。 If you do need email, mine did happen to work using Zoneedit, but the DNS rules says you can't rely on this.如果您确实需要 email,我的确实使用 Zoneedit 工作,但 DNS 规则说您不能依赖这个。

Edit: After my post Amazon added the ability to map the root of a domain (aka the zone apex) to a load balancer using Route 53. See this blog post .编辑:在我的帖子之后,亚马逊添加了 map 的功能,使用 Route 53 将域的根(又名区域顶点)添加到负载均衡器。请参阅此博客文章

As David points out, you can't do it and still remain within DNS RFC.正如大卫指出的那样,您不能这样做并且仍然保留在 DNS RFC 中。 You could just build a small no load balanced instance somewhere that just redirecs mysite.com -> www.mysite.com.您可以在某处构建一个小型无负载平衡实例,该实例仅重定向 mysite.com -> www.mysite.com。 Not a totally elegant solution, but a work around..不是一个完全优雅的解决方案,而是一个解决方法..

Amazon now has functionality in Route53 that provides a mechanism for binding A records to ELBs: http://www.allthingsdistributed.com/2011/05/aws_ipv6.html Amazon 现在在 Route53 中提供了一种将 A 记录绑定到 ELB 的机制: http://www.allthingsdistributed.com/2011/05/aws_ipv6.html

You do NOT need a redirect, and yes it CAN be done.您不需要重定向,是的,它可以完成。 It's just not in the normal mode of working with DNS, so many people aren't comfortable using zone apexes with ELB aliases yet.它只是不在使用 DNS 的正常模式下,所以很多人还不习惯使用带有 ELB 别名的区域顶点。

See the links given in other answers here, especially https://serverfault.com/questions/342904/how-do-you-create-a-zone-apex-alias-that-points-to-a-elastic-load-balancer-in-th请参阅此处其他答案中给出的链接,尤其是https://serverfault.com/questions/342904/how-do-you-create-a-zone-apex-alias-that-points-to-a-elastic-load-平衡器

Amazon has added a special alias option in their route 53 DNS service.亚马逊在其路线 53 DNS 服务中添加了一个特殊的别名选项。 You can point an A record as an alias to the load balancer dns.您可以将 A 记录作为别名指向负载均衡器 dns。 I ran into this same problem because I host my own DNS servers using Bind 9. I didn't want to use the CNAME with redirect solution.我遇到了同样的问题,因为我使用 Bind 9 托管了自己的 DNS 服务器。我不想将 CNAME 与重定向解决方案一起使用。 The route 53 solution is better and Amazon is great at propagating DNS info across the globe.路线 53 解决方案更好,亚马逊擅长在全球传播 DNS 信息。

Here is an explanation of how to use route 53 with the special alias record for elastic load balancers.这里解释了如何将路由 53 与弹性负载均衡器的特殊别名记录一起使用。

https://serverfault.com/questions/342904/how-do-you-create-a-zone-apex-alias-that-points-to-a-elastic-load-balancer-in-th https://serverfault.com/questions/342904/how-do-you-create-a-zone-apex-alias-that-points-to-a-elastic-load-balancer-in-th

The redirect from DNS service provider didn't work for me.来自 DNS 服务提供商的重定向对我不起作用。 I decided to give up the use of load balancer (from the beginning i created it only to try to hack the mentioned certificate problem).我决定放弃使用负载均衡器(从一开始我创建它只是为了尝试破解提到的证书问题)。 If you must use LB read the opt #2 bellow i didn't try it but i think it's should work.如果您必须使用 LB,请阅读下面的 opt #2,我没有尝试过,但我认为它应该可以工作。

Opt #1 (without LB) Take the certificate you got from the trusted issuer and install it directly on the server.选项 #1(无 LB)获取您从受信任的颁发者处获得的证书并将其直接安装在服务器上。 Give redirect order from the server (http to https) it will handle www as well.服务器(http 到 https)给出重定向命令,它也将处理 www。 I used image of bitnami so i could use bncert-tool for that.我使用了 bitnami 的图像,所以我可以为此使用 bncert-tool。

Opt #2 (with LB you should have certificate body and private key) You should do Opt #1 and go to certificate manager at AWS-> import certificate and then use that certificate with your LB that way you have the same certificate with both cases I never tried opt #2选项 #2(使用 LB,您应该有证书正文和私钥)您应该对 AWS-> 导入证书的证书管理器执行选项 #1go,然后将该证书与您的 LB 一起使用,这样您就可以在两种情况下都拥有相同的证书我从未尝试过选择 #2

Good luck祝你好运

For someone who is not using Amazon Route 53 it seems like a recommended solution is to create a Network Load Balancer which then points to an Application Load Balancer, which then points to our EC2 instances.对于不使用 Amazon Route 53 的人来说,似乎推荐的解决方案是创建一个网络负载均衡器,然后指向一个应用程序负载均衡器,然后再指向我们的 EC2 实例。

The Network Load Balancer has a static IP Address, which is what you want.网络负载均衡器有一个 static IP 地址,这正是您想要的。

Source: https://aws.amazon.com/premiumsupport/knowledge-center/alb-static-ip/资料来源: https://aws.amazon.com/premiumsupport/knowledge-center/alb-static-ip/

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

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