简体   繁体   English

如何使用Route 53在AWS中使用单个弹性IP地址提供多个子域?

[英]How can I serve multiple sub-domains using a single Elastic IP Address in AWS using Route 53?

I have a single Elastic IP address on AWS and I want to use that IP address to route traffic to multiple distinct EC2 instances based on the sub-domain. 我在AWS上有一个弹性IP地址,我想使用该IP地址根据子域将流量路由到多个不同的EC2实例。 Basically, in the same manner as virtual hosts in an Apache httpd server. 基本上,与Apache httpd服务器中的虚拟主机相同。 For example: 例如:

  • example.com - ELB: xxx.xxx.xxx.xxx example.com - ELB:xxx.xxx.xxx.xxx
  • test.example.com points to EC2 Instance ID 1 test.example.com指向EC2实例ID 1
  • build.example.com point to EC2 Instance ID 2 build.example.com指向EC2实例ID 2

All traffic for each of the domains would go to xxx.xxx.xxx.xxx and then based on the sub-domain name Route 53 would send traffic to the correct instance. 每个域的所有流量都将转到xxx.xxx.xxx.xxx,然后根据子域名Route 53将流量发送到正确的实例。

I've been through the documentation for Route 53 and I can't see how this is done. 我已经浏览了Route 53的文档,但我看不出这是怎么做到的。 I also looked at Amazon ELB but was unsure if that would work. 我也看了亚马逊ELB,但不确定这是否有用。

Does anyone know how to set this up just using the AWS tools (Route 53 and/or ELB)? 有没有人知道如何使用AWS工具(Route 53和/或ELB)进行设置? I'd rather not have to script it or use a reverse proxy if I can avoid it. 如果我可以避免它,我宁愿不必编写脚本或使用反向代理。

Any ideas or help would be great. 任何想法或帮助都会很棒。 Thanks in advance. 提前致谢。

You don't need an elastic ip for each server. 每个服务器都不需要弹性ip。 Each server already comes with an IP, so you can use that (if you actually want to address servers by ip address) - but what you likely should be doing is setting up a cname on your domain for each server, and then addressing the server's by the dns name, not by the ip address. 每个服务器都已经附带一个IP,所以你可以使用它(如果你真的想通过ip地址来寻址服务器) - 但你可能应该做的是在你的域上为每个服务器设置一个cname,然后寻址服务器的由dns名称,而不是IP地址。

ie: 即:

server1.example.com
server2.example.com
server3.example.com 

etc 等等

You don't need to use any EIP's. 不需要使用任何EIP。

Maybe you could explain better why you think all the traffic needs to go thru a single IP address? 也许您可以更好地解释为什么您认为所有流量需要通过单个IP地址?

I can't say for sure why AWS limits you to just 5 EIPs, but I am pretty sure its because if you find out you need hundreds of EIP's then you are probably doing it wrong - and forcing you to request more than 5 gives them the ability to open up a discussion with you and help you do it a better way. 我不能肯定为什么AWS限制你只有5个EIP,但我很确定它,因为如果你发现你需要数百个EIP,那么你可能做错了 - 并强迫你请求超过5个给他们能够与您开展讨论并帮助您更好地完成这项工作。

You'll need 1 Elastic IP address for each distinct EC2 instance that you want to redirect traffic to. 对于要将流量重定向到的每个不同EC2实例,您需要1个弹性IP地址。

  1. Create your CNAME or ALIAS record for example.com and point it to your ELB. 为example.com创建您的CNAME或ALIAS记录,并将其指向您的ELB。
  2. For each distinct EC2 instance that you need a sub-domain for, do the following: 对于您需要子域的每个不同EC2实例,请执行以下操作:
    1. Allocate an Elastic IP address. 分配弹性IP地址。
    2. Assign that Elastic IP address to the EC2 instance. 将该弹性IP地址分配给EC2实例。
    3. Create an A record in Route 53 pointing subdomain.example.com to that Elastic IP address. 在Route 53中创建A记录,将subdomain.example.com指向该弹性IP地址。

Note: Since your EC2 instances need to be accessed directly, they will need to reside inside a public subnet. 注意:由于您的EC2实例需要直接访问,因此它们需要驻留在公有子网内。

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

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