rjha
rjha

Reputation: 111

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:

  1. Created an EC2 instance and elastic IP. Mapped elastic IP to instance.
  2. Using Route 53 created hosted zone. Updated Godaddy name servers to have newly allocated name servers.
  3. Created record set(A record) in AWS hosted zone to point my domain for e.g. www.example.com and mapped it to elastic public IP
  4. Created an ELB and added instance of step#1 to it.
  5. Created another record set(CNAME) for e.g test.example.com and mapped it to ELB public 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/)

With redirect I mean url changes in address bar and also Chrome console shows 302 redirect.

I don't want url to change in address bar. Not sure what I am doing wrong, any help would be appreciated.

Thanks in advance!

Upvotes: 3

Views: 2799

Answers (1)

ydaetskcoR
ydaetskcoR

Reputation: 56987

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.

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).

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. 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.

Upvotes: 2

Related Questions