digitalspeed logo

How to connect a domain name to your website hosted on AWS EC2 instance

connect domain name to ec2 instance

“In today’s digital world, hosting your website on a virtual server like AWS EC2 is increasingly popular. However, connecting a domain name purchased from providers such as Namecheap or GoDaddy can pose a challenge, especially for those unfamiliar with available services.”

“The importance of domain names cannot be overstated. Without one, accessing your website is limited to your IP address alone. While customers and visitors may know your domain name, accessing your site via its IPV4 address is less convenient. Additionally, IP addresses may change, or your server could migrate to another cloud provider. However, by associating the same domain name with your new server, continuity is maintained.”

In this post, I’ll explain the steps you should take to connect a domain name to a website hosted on AWS EC2. I’ll show you screenshots of every step. I’ll be using a GoDaddy domain but you can use from any other domain provider.

Prerequisite

Connect to your EC2 instance

There are many ways to connect to EC2 instances using Linux, MacOS, and Windows as shown in the picture below.

options to connect to aws ec2 instance
Some of the ways to connect to AWS EC2

I have written a detailed article on the different ways of connecting to EC2 instances.

Setup server, update your package list

  • Update your package list with this command. sudo apt update

Install NGINX

  • Use this command to install NGINX sudo apt install nginx -y
  • Confirm NGINX installation, copy and paste your instance public IP address on a new browser tab. It should show you the default NGINX page.

NOTE: You can find your instance IP address on the command line where you type in your commands or on the instance details page. You should only use the public IPv4 address and not the private IP address. Which is shown in the screenshot below.

The NGINX default page you should see when you open your IPV4 address on a web browser is shown below.

Connecting a domain name to your Amazon EC2 instance simply means a domain name server that will convert your domain name to your EC2 instance IPV4 address, Route53 is an Amazon service that can do that for your instance.

Enable Route53 for DNS routing

Route53 is an AWS proprietary service that you can use for DNS (Domain Name Service) management. You can also buy domain names from AWS Route53 but that’s not only what you can do with it.

I have bought my domain name from GoDaddy but you can follow through if you bought your domain name from any other retail company like NameCheap, ROute53, etc it’s very similar procedure.

Follow the steps below to set up Route53 for Domain name routing.

  • Locate Route53 dashboard, From the AWS management console, search for Route53 or click service and select Route53 from the list of services shown.
  • Select Create hosted zones and Click on Get started from the dashboard.

    aws route53 dashboard
  • Fill out the details on the next page, for domain name you should use the domain name you bought from domain name retailer like GoDaddy. Also, give it a nice description.
  • Select Public hosted zone since your website needs to be accessible to the internet, click on Create hosted zone. You will see a notification at the top for successfully creating the hosted zone.
hosted zone record list

Add records to your hosted zone

Route 53 has automatically created two records for us; the NS (Name Server) and the SOA (Start of Authority) records. The NS record is what you will need for pointing your domain to this service from the domain retailer before you do that, you have create the records for the options.

Because our website is being hosted on an EC2 instance which can be accessed through its public IP address, you need to create an A record for it. Also just so you ensure that people who try accessing your website with the www subdomain are still able to access it, you will also need to add another record with an alias for it.

Follow the steps below to create the records.

  • For the A record, leave the subdomain input box empty, this record is meant for your . Make sure A – Routes traffic to an IPv4 address and some AWS resources is selected under the record type. You should paste or type the public IPV4 address of your EC2 instance in the textarea for Value. You can get your instance IPv4 address under your instance details page.
  • You can leave everything as default (NB: Check to ensure that the Routing policy is Simple routing).
  • Click on Create record and confirm the success of the record you created. You will see that it is added to the other records for your hosted zone.

    main domain route for hosted zone
  • Click on Create record to create the record for your subdomain when someone access your website using www.
  • For the subdomain input box in the options of these new record, type in www, select the alais option, when clicked a new set options (Route traffic to) will be made available.
  • For the Choose endpoint dropdown, select Alias to another record in this hosted zone and the Region will automatically be populated for you. But it also brings up another field labeled Choose record.
  • Go ahead and click within the Choose record field and it will suggest your domain name for you. Go ahead and select it.

    creating sub domain A record
  • Click on the create records button. You will get a success message and see that the new record has been added to the record table.

You’re done setting up the records, You can add more records based on certain requirements but these are what you need for now. You can now proceed to update your name servers with our Domain retailing company (GoDaddy, NameCheap, Route53).

Setup on your DNS Provider

If you already have a domain name registered, you will have some default nameservers. Your goal here is to change the default nameservers or whatever your nameservers currently are to the ones which Route53 will provide for you.

Follow the process below to c

  • Log in to your domain provider, for GoDaddy, select Portfolio, or find a way to list the domain on your account.
  • Select the domain name you want to use.
  • Select the DNS option and select the nameserver from the option, You will see a list of nameservers usually two or four.

    godaddy nameservers for my domain name
  • Click on change or edit nameservers, you will be provided with text box to change your nameservers.
  • On AWS hosted zone list, note the four NS (Nameservers) provided, copy them and paste it on the nameserver you want to change for your domain name provider.

    AWS route53 nameservers
  • Save or update the nameserver you have entered for your domain name provider.

You have successfully connected your domain name to your AWS EC2 instance, if you open your domain name on a browser you should be able to receive content from your EC2 instance.

Go to a new tab on your browser, type in your domain name and click enter for it to load, don’t expect your domain name to become connected to your nameserver immediately, it can take from 5 minutes to 24 hrs.

Check your nameserver settings again and be patient for the update to pull through.

Note: Route53 charges for hosting nameservers on its platform;

  • $0.5 per month for each nameserver hosted on the platform.
  • $0.4 per 1 million requests to the server.

See the full pricing model here, Pricing Model for Route53.

Conclusion

You have connected your EC2 instance to your domain name, You can upload a website or web content on your instance, share and market your domain name to others so they can access your content also you can switch your domain name to another instance if you need to.

Although you have connected your domain name, your website might still be connecting only with HTTP instead of HTTPS, you will need to enable HTTPS for your website for it to be accessible from most web browser, check out my previous post Enable HTTPS for your Lightsail instance

Let me hear your comments also check out other similar posts below.

Please share this article at the top of the page under the share this button. Thanks

Recent Post

Send Us A Message

Related Post

Join our newsletter to stay updated

digitalspeed-logo

At DIGITALSPEED, you can get updates, reviews and learn about new digital tools and features on existing tools. check us on social media.

Get In Touch

Lagos, Nigeria

DIGITALSPEED © All Rights Reserved.

2025

Scroll to Top

Seach for Articles