Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link a Google Domain to Amazon ec2 server

I am using an Amazon EC2 instance to serve a node.js app. I recently purchased a domain name through Google Domains and I want to use that domain name to access my node.js app.

The Google Domains console allows you to forward your domain traffic to another website. I set it to forward traffic to the public IP address of my EC2 instance. I can access my app just fine now, but when I type www.myDomainName.com into a web browser, the URL bar immediately changes and displays the digits of my EC2 IP address.

I would like the URL bar to display the name of my domain instead.

Note:
I have read a few SO questions related to this and can't figure it out. Some of them are a bit over my head. Many of them say to use an Amazon Elastic IP, but I don't understand why this is necessary if the public IP of my EC2 instance seems to work just fine. If the solution here is to use Amazon Elastic IP, I would really appreciate an explanation as to why that is necessary,

like image 677
Dsel Avatar asked Sep 08 '15 21:09

Dsel


3 Answers

It sounds like you are using Google Domains to redirect to another site once the request has hit the Google servers. This is fine and dandy if you have another domain you are wanting to redirect to.

If you want it to stay under your domain name, but point to another location you need to actually change the DNS entries for your domain.

Go to Google Domain services and change your master(*) (A) record, as well as your WWW (A) record, to point at your public IP address. That way when a DNS request is sent for your domain it will just ask Amazons' servers what to do instead of using a redirect from Google.

Exact Steps:

  1. From the Google Domain Website, click the Middle Tab (enter image description here) to open DNS settings
  2. Fill out the form near the bottom of the page titled, Custom Resource Record
    • Name: In this scenario we want to use "@" or "www"
      • @ is the root record (or anything not specifically set)[all]
      • www is the record for when people type www.example.com
    • Type: There are two types; A refers to IPv4 address and AAAA refers to IPv6 address
      • You can set both of them separately, generally you want to use the A [IPv4]
    • TTL: Time to live, recommend leaving 1hr (this is an advanced attribute)
    • Data: The actual IP address you are wanting to point to (your website)
      • Example: 8.8.8.8 [Google Nameserver]
  3. Now that are the blanks are filled out, press the "Add" button
  4. Wait for the records to be updated publicly
    • This will take approx. 1hr (as long as you kept TTL at 1hr)
      • This step can take longer depends on Google's servers
    • Check your website www.example.com to confirm it has updated
like image 156
ZaxLofful Avatar answered Nov 06 '22 17:11

ZaxLofful


Addendum to Zax's Answer

While Zax's answer is fully accurate, it looks like it wasn't sufficient to help out the OP, and maybe not for others, too.

  1. When you go to Google Domains (at least as of March 2017), you'll see several different tabs. The middle tab, which looks like enter image description here is the tab to configure the DNS. Chose that tab.
  2. Near the bottom of the page on the DNS tab you'll see a section Custom resource records. Within that section, you can add more entries. An entry consists of:
    • Name: this is briefly described by Google, but in short, likely you'll either want to use @ or www, where the former means "root level" and the latter means "www subdomain".
      • For instance, if you registered imsocool.com, then @ points to imsocool.com whereas www points to www.imsocool.com.
    • Type: you'll probably either want A which is an IPv4 Address or you'll want AAAA, which is an IPv6 Address. (That's assuming you're trying to point to a website, not an e-mail server or whatever else.)
    • TTL: time-to-live, I don't think you'll need to worry about it much, so just use the 1h (one hour) default.
    • data: again, presuming you are pointing to a website, that will be the actual IP address. E.g., 54.49.66.128, or whatever your IPv4 (or v6) server address is.
  3. Once you've filled in all the blanks, simply hit the blue "Add" button.
  4. Wait a while for the DNS update to happen.
    • The most it should take is 1 hour, if that's what you had placed above. But it could potentially be much quicker.
    • Then check to see that all is working by visiting your site using the name, e.g., imsocool.com.
like image 15
Mike Williamson Avatar answered Nov 06 '22 15:11

Mike Williamson


In your google domain admin dashboard, select the dns configuration of your domain name.

Go to Custom resource records and set a new record with the subdomain you require: for the site webapp.example.com use webapp and select Type A. Leave blank the ttl field and add you public IP from the amazon EC2 instance. Then just browse the site webapp.example.com and it will retrieve the site on your EC2 under the domain name.

If you need to redirect the www.example.com domain then just add a record with www, also selecting the type A and adding your public IP from your EC2 instance.

like image 3
BFlores Avatar answered Nov 06 '22 17:11

BFlores