How redirect a domain to Amazon EC2 Machine?

2019-01-21 01:08发布

问题:

I'm using EC2 of Amazon to host a website built in JSP :

http://ec2-50-17-144-64.compute-1.amazonaws.com:8080/p2p

And I bought this domain: www.p2pbrasil.com

How can I redirect www.p2pbrasil.com to my website in Amazon EC2 ?

When someone type www.p2pbrasil.com it redirects to http://ec2-50-17-144-64.compute-1.amazonaws.com:8080/p2p ?

回答1:

You need to do two things

  1. In the Amazon Web Service admin panel, create an elastic IP in the same region as your instance and associate that IP with your that instance (IPs cost nothing while they are associated with an instance, but do cost if not).
  2. Add a A record to the DNS record of your domain mapping the domain to the elastic IP address assigned in (1). Your domain provide should either give you some way to set the A record (the IP address), or it will give you a way to edit the nameservers of your domain.

If they do not allow you to set the A record directly, find a DNS management service like ZoneEdit, register your domain as a zone there and ZoneEdit will give you the nameservers to enter in the admin panel of your domain provider. You can then add the A record for the domain in ZoneEdit.

I only mention ZoneEdit because the basic service is free, you could also use Amazon route 53 or a similar pay-for service, if you preferred.



回答2:

Create an Elastic IP on the AWS Panel, then associate it to your instance.

Then use a DNS management service to add your domain and Ip address (Elastic IP), then on the domain provider panel add the DNS provided from the DNS management service.

I recommend EntryDNS which is actually free.



回答3:

Put the public IP from your EC2 instance as an A name to your root domain in Route 53 hosted zone. This change might take some time.



回答4:

As you have your server on AWS best option is to use Route53 hosted zone.By doing this you can manage all your DNS entries using AWS. In future if you plan to use ELB's for your application, you can various traffic routing options using Route53.

  1. Create Hosted Zone and get the name servers.

  2. Replace current name servers with AWS nameservers from your Domain registrars DNS entries.

  3. Create an A record in AWS hosted zone and give your servers IP (Elastic IP) as value.

For detailed instruction, you can follow this blog post. Mapping Domain Name to EC2 Server



回答5:

Assuming this is a hobby website and your domain registrar isn't AWS.

If your registrar (for example godaddy.com) provides a DNS manager you simply need to add a CNAME record for www that points to the aws public DNS record for your instance. For example ec2-50-17-144-64.compute-1.amazonaws.com

This will make http://www.p2pbrasil.com display the same content as http://ec2-50-17-144-64.compute-1.amazonaws.com

Doing it this way you don't have to pay for an elastic IP, which is a dedicated resource. Your IP on your ec2 instance shouldn't change but could if you restart your instance.