简体   繁体   English

AWS ELB 或域 url 重定向到 EC2 实例公共 DNS

[英]AWS ELB or Domain url redirects to EC2 instance public DNS

I am new to AWS and trying to map domain(registered in Godaddy) to AWS instance, here is what I have tried:我是 AWS 的新手,并试图将域(在 Godaddy 中注册)映射到 AWS 实例,这是我尝试过的:

  1. Created an EC2 instance and elastic IP.创建了一个 EC2 实例和弹性 IP。 Mapped elastic IP to instance.将弹性 IP 映射到实例。
  2. Using Route 53 created hosted zone.使用 Route 53 创建的托管区域。 Updated Godaddy name servers to have newly allocated name servers.更新 Godaddy 名称服务器以具有新分配的名称服务器。
  3. Created record set(A record) in AWS hosted zone to point my domain for eg www.example.com and mapped it to elastic public IP在 AWS 托管区域中创建记录集(A 记录)以指向我的域,例如 www.example.com 并将其映射到弹性公共 IP
  4. Created an ELB and added instance of step#1 to it.创建了一个 ELB 并向其添加了 step#1 的实例。
  5. Created another record set(CNAME) for eg test.example.com and mapped it to ELB public DNS为例如 test.example.com 创建另一个记录集(CNAME)并将其映射到 ELB 公共 DNS

Both www.example.com and test.example.com redirects to EC2 instance public DNS( http://ec2-52-11-xxx-xxx.us-west-2.compute.amazonaws.com/ ) If I hit ELB url(test-elb-34243545.us-west-2.elb.amazonaws.com) directly that also redirects to EC2 instance public DNS( http://ec2-52-11-xxx-xxx.us-west-2.compute.amazonaws.com/ ) www.example.com 和 test.example.com 都重定向到 EC2 实例公共 DNS( http://ec2-52-11-xxx-xxx.us-west-2.compute.amazonaws.com/ ) 如果我点击 ELB url(test-elb-34243545.us-west-2.elb.amazonaws.com) 也重定向到 EC2 实例公共 DNS( http://ec2-52-11-xxx-xxx.us-west-2. compute.amazonaws.com/ )

With redirect I mean url changes in address bar and also Chrome console shows 302 redirect.重定向是指地址栏中的 url 更改,Chrome 控制台也显示 302 重定向。

I don't want url to change in address bar.我不希望 url 在地址栏中更改。 Not sure what I am doing wrong, any help would be appreciated.不知道我做错了什么,任何帮助将不胜感激。

Thanks in advance!提前致谢!

If you want traffic to go via the ELBs (this is a good thing) and not direct to the EC2 instance underneath then you don't need your elastic IP.如果您希望流量通过 ELB(这是一件好事)而不是直接到达下面的 EC2 实例,那么您不需要弹性 IP。

Instead create a CNAME in your Route53 Hosted Zone for www.example.com that points to the ELB name (which will look like ${load_balancer_name}-${account_id}.${region}.elb.amazonaws.com ).而是在您的 Route53 托管区域中为www.example.com创建一个 CNAME,指向 ELB 名称(看起来像${load_balancer_name}-${account_id}.${region}.elb.amazonaws.com )。

Now when you go to www.example.com you will hit the ELB which will then load balance traffic to any attached EC2 instances underneath it.现在,当您访问www.example.com您将访问 ELB,然后将流量负载均衡到其下的任何附加 EC2 实例。 You can also leave the EC2 instances with purely private IP addresses so it's impossible to hit the EC2 instance directly without going through the ELB.您还可以将 EC2 实例保留为纯私有 IP 地址,这样不通过 ELB 就不可能直接访问 EC2 实例。

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

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