Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register GoDaddy Domain with AWS ec2 instance

My Problem is as below.

  1. I have a domain registered with GoDaddy [ assume : mytest.com ]
  2. I have a EC2 ALM instance at AWS
  3. I have elastic IP associated with my Instance [ assume : 111.222.333.444]
  4. I have developed a nodejs application and deployed in instance
  5. That node application is running at port 8181
  6. Application is accesable using http://111.222.333.444:8181/
  7. I want to configure my domain so that http://mytest.com will point to http://111.222.333.444:8181/

  8. I have few knowledge to configure using Route53 also but not able to solve the mapping with port 8181.

Need kind help to resolve this issue

Thanks in advance

Note : For time being i am not looking for AWS PaaS Elastic Beanstalk for node js deployment

Ajoy

like image 209
ajoy sinha Avatar asked Dec 28 '16 17:12

ajoy sinha


People also ask

Does GoDaddy host on AWS?

(AWS), an Amazon.com company (NASDAQ:AMZN), today announced that GoDaddy Inc. (NYSE: GDDY) is going all-in on AWS, migrating the vast majority of its infrastructure as part of a multi-year transition.


2 Answers

You actually have to do several things to make your thing work.

1. Change DNS nameservers to point to your Route53 Hosted Zone

Since you registered your hostname with GoDaddy, and you want to use Route53 as your DNS, you have to do several things.

First, go to Route53 and create a hosted zone for your domain. For demonstrative purposes, I will be using stackoverflowexample.com as my domain.

After you've created your hosted zone, click into it and you should be presented with the NS and SOA records. The NS record lists 4 unique nameservers that you will need to configure with GoDaddy.

The image below is an example of the NS record set (AWS Route53 calls it the delegation set). Hosted zone nameserver example

Then you will have to go to your registrar and follow their directions to change nameservers for your domain, using the 4 nameservers Route 53 assigned you as your custom nameserver.

Then create a new A record in route 53 pointing at your elastic IP address. In the end your Route 53 zone will look something like this, with an A record mapping your domain to your elastic IP address.

Route53 zone after adding A record for TLD

2. Hosting/proxying your application on default HTTP port

After you have set up the DNS records (and waited a while for DNS to propagate), then you should be able to hit your server on port 8181.

But you want to hit it without a port number, so how do you do that?

DNS itself doesn't care about ports, it really just provides information about IP addresses and domain names. What you need now is to set up a proxy or other mechanism to direct traffic on your server. I will provide a few solutions.

Use nginx to reverse proxy

Since you control your own instance, you could install nginx (a web/proxy server) on the instance and configure it so that when it gets requests, it knows how to direct the traffic.

Here are generic instructions for configuring nginx for reverse proxy operation.

nginx example for Debian/Ubuntu

If you are using Debian or Ubuntu, a simple set up is as follows:

# Install nginx
sudo apt-get update && sudo apt-get install nginx

# By default, nginx runs a default site on port 80 you don't care about
# This removes the symlink for the default nginx site
sudo rm /etc/nginx/sites-enabled/default

Then you will want to create your own configuration in sites-available.

sudo vim /etc/nginx/sites-available/mainsite

The contents of your file will look probably like this:

server {
    listen 80;
    server_name stackoverflowexample.com;

    location / {
        proxy_set_header  X-Forwarded-For $remote_addr;
        proxy_set_header  Host $http_host;

        # Proxy all requests to the NodeJS app on port 8181
        proxy_pass        http://localhost:8181;
    }
}

After you're done, execute the next two steps

# symlink your new nginx config to sites-enabled, which nginx
# automatically discovers and loads.
sudo ln -s /etc/nginx/sites-available/mainsite /etc/nginx/sites-enabled/mainsite

# Reload nginx configuration
sudo service nginx reload

Now try hitting your site without the port - you should reach your application.

Use Elastic Load Balancer

AWS offers a load balancer service (at an additional cost of ~$20 USD per load balancer per month) which lets you configure an HTTP and/or HTTPS load balancer for your application, allowing you to map incoming request ports to ports on your instance.

It's also automatically provided to you if you use Elastic Beanstalk.

They have their own tutorial which should help.

Configure your application to run on port 80

I do not do this myself and this is only useful if your instance will only ever host one app that controls all its own routing.

You could run your Node app directly on port 80 without needing a reverse proxy in front. If you go down this route, I'd recommend not allowing the service to run as root and instead configuring something like authbind to allow non-privileged access to port 80.

I will defer to other answers like this SuperUser one if you want to bind your service to port 80.

Additional Notes

  • You'll note that I excluded configuring HTTPS. That requires more steps like provisioning an SSL cert, though AWS or LetsEncrypt provide them for free now. Configuration also differs if you're using an Elastic Loadbalancer or a server on your instance, or if you're exposing your app directly.

  • I suggested nginx, and I would still recommend it in almost all general cases, but there are multiple different servers you could use to act as a reverse proxy. Other popular ones are haproxy or apache httpd with mod_proxy.

like image 84
逆さま Avatar answered Sep 28 '22 20:09

逆さま


You can use any AWS public gateway provider such as EC2, ELB, S3 to serve your website or server to the public domain you have on GoDaddy. The AWS usually charges about .51 USD per month to maintain this zone entry as well.

the following steps set up your domain.

  1. Obtain the Elastic IP or EC2 IP for the website or service.
  2. Create a Hosted Zone on Route53.
  3. Update the domain name records on Hosted Zone.
  4. Update name servers on GoDaddy for discovery.

Check this tutorial

like image 38
ricky Avatar answered Sep 28 '22 19:09

ricky