Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

How to Connect a Domain Name to AWS EC2

So far our websites opened at http://PUBLIC_IP/. Real websites open at a name, like instagram.com. In this chapter we learn why names matter, how DNS turns a name into an IP address, where to buy a domain and how to buy it safely, and how to point it at an EC2 server with an A record. Then we host several websites on one server: each gets its own subdomain, a CNAME record and an Nginx server block.

In this class

  • Why websites need domain names, and the problem with bare IP addresses
  • How DNS turns a name into an IP address
  • Registrars, choosing a good name, registration terms and the cart
  • Owner, admin, technical and billing details, and keeping control of your domain
  • Adding an A record (@ to your EC2 public IP) and opening your site by name
  • Why a stop and start breaks the A record, how long DNS changes take, and what fixes it
  • Virtual hosting: many websites on one server
  • TLD, domain and subdomain, and CNAME records for subdomains
  • Downloading templates, renaming folders with spaces, one Nginx server block per subdomain
  • Why capital letters don't matter in the domain but can matter in the path

1. Why: nobody remembers IP addresses

Our server answers at an IP address. Suppose we are Instagram: would people type a string of numbers every time they want to open the app's website? No. They type instagram.com. A name is easy to remember, to say aloud and to print on a visiting card.

There are two more problems with bare IPs:

  1. One IP shows one default site. With only an IP, Nginx can't tell which of your websites a visitor wants.
  2. The IP can change. If the server gets a new IP, every link and bookmark that used the old one breaks.
Why domain names: people remember names, notnumbers Only an IP address http://PUBLIC_IP/ 1. Hard to remember and to share. 2. One IP = one default site. 3. Changes if the server gets a new IP. A domain name http://example.com/ 1. Easy to remember, type and print. 2. Many names can point to one server. 3. If the IP changes, update one record.

Figure 1. A bare IP is hard to remember, shows one default site and can change. A name is easy, many names can point to one server, and if the IP changes you update one record.

Classroom line

Every one of us will need to buy a domain name.

2. What: DNS turns a name into an IP

Computers connect using IP addresses, not names. DNS (Domain Name System) is the internet's phone book: it answers the question "what is the IP address of this name?"

How it works, step by step:

  1. You type example.com in the browser. The browser has a name, but it needs an IP.
  2. Your computer asks a DNS resolver (usually run by your internet provider, or a public one): "What is the IP of example.com?"
  3. The resolver finds the domain's DNS records and gets the answer, for example PUBLIC_IP.
  4. The browser sends the request to PUBLIC_IP on port 80, and Nginx on your EC2 server answers.
How a name becomes an IP address (DNS) Your browser example.com 1. You type example.com. The browser has only a name, not anIP. DNS resolver ? 2. Your computer asks a DNS resolver: what is the IP ofexample.com? DNS records A  @  PUBLIC_IP 3. The resolver finds the domain records and gets the answer:PUBLIC_IP. EC2 server Nginx :80 4. The browser sends the request to PUBLIC_IP on port 80.Nginx answers.

Figure 2. Animation: the name goes to a DNS resolver, the domain's records give the IP, and the browser connects to that IP.

Example 1. Suppose we are Instagram. When you type instagram.com, steps 1 to 4 happen in a fraction of a second, and you never see the IP. That's the whole point.

Try it. On your own computer, run:

nslookup example.com

The Address: line in the answer is the IP that the name points to.

3. Where to buy a domain: registrars

A company that sells and manages domain names is a registrar. Common ones:

  1. GoDaddy
  2. Hostinger
  3. Amazon Route 53 (inside AWS)
  4. and many others

In this chapter we use GoDaddy screens, but every registrar has the same ideas: search, cart, and a page to manage DNS records.

4. Choosing a good name

The name is your address for years. Changing it later means new visiting cards, new links and lost visitors.

Two good kinds of names:

  1. A business keyword. Suppose we are building a shopping site: a word like cart or shop in the name tells people what you do.
  2. A unique brand word. Suppose we are Google or TikTok: those words meant nothing before; the brand gave them meaning. A unique word is easy to own everywhere.

Tips:

  1. Short, easy to spell, easy to say on the phone.
  2. Avoid words that shrink your audience, for example a word tied to one religion or one country, if you want everyone as customers.
  3. Pick the ending (.com, .in and so on) that suits your visitors. For practice, any cheap ending works.

When the name is taken. Suppose we want instagram.com. It's taken, and the search shows it isn't available.

  1. Some registrars offer a broker service: they contact the owner for you, for a fee. The owner may still say no.
  2. Some people, called domain investors, buy catchy names early to sell them later. That's why many good short names are already taken.
  3. Usually the easier way is a different name, or a different ending.

5. Registration: how long, and what to check in the cart

You don't buy a domain forever. You register it for a term of 1 to 10 years, then renew it.

  1. A longer term keeps the name safe for longer and protects you from renewal price rises during that term.
  2. If you forget to renew, the name expires and someone else can register it.

In the cart, step by step:

Step 1. Search the name and add it to the cart.

Step 2. Check the term. Big "first year" discounts often need a multi-year term. Set it to the number of years you actually want.

Step 3. Remove add-ons you don't need (extra email, website builders and so on). Now you see the real price.

Step 4. Read the renewal price, not only the first-year price.

Step 5. Check your contact details, then pay.

Buying a domain: where, which name, how long 1. Registrars GoDaddy · Hostinger · Amazon Route 53 · and many others 2. Pick a name A business keyword or a unique brand word. Short, easy to spell. Avoid words that shrink your audience. 3. Register it For 1 to 10 years, then renew. In the cart: check the term, remove add-ons you do not need, read therenewal price.

Figure 3. Pick a registrar, pick a short name, register it for 1 to 10 years, and clean up the cart before paying.

6. Owner, admin, technical, billing: keep control

A domain registration stores contact details:

  1. Owner (registrant): the person or business that owns the domain.
  2. Administrative: can change and transfer the domain.
  3. Technical: handles DNS and server settings.
  4. Billing: pays for registration and renewal.

Suppose we run a bakery and a developer builds our website. If the developer registers the domain in their own account, they control it. If they leave, or there's a fight about money, they can point it somewhere else or let it expire.

How to stay safe:

  1. The business owner registers the domain, in their own account and name.
  2. Owner and admin stay with the business owner.
  3. The developer gets limited access for the technical work (many registrars have a delegate or team-member option), never the owner's login.
Registration details: keep the owner and adminwith the business Owner The business that owns the domain. Administrative Can change and transfer the domain. Technical Handles DNS and server settings. Billing Pays for the registration and renewal. A developer may do the technical work, but the owner and adminstay in the business owner name and account. Give the developer limited access, not your login. Then nobody elsecan take or delete your domain.

Figure 4. Owner and admin stay with the business; the developer only gets limited technical access.

7. How: point the domain to EC2 with an A record

Connect the A record, the HTTP name and the server block

Use a lab domain you control. The A record for example.com can name the IPv4 address of your lab site. A CNAME on www.example.com can point to the name example.com. Resolving either name can lead to the same address. The browser keeps the name it requested when it sends HTTP, so Nginx can serve different folders for two names on one instance.

On paper, draw name → address → server block → directory. If the address is correct but the wrong site opens, start at the server block and compare the requested name. If you cannot reach the intended address at all, start at DNS and network checks. This avoids changing an A record to solve a wrong-folder problem.

An A record maps a name to an IPv4 address. The name @ means "the domain itself", so an A record @ -> PUBLIC_IP makes example.com go to your server.

Step 1. In the EC2 console, open Instances, select your server and copy its Public IPv4 address.

Step 2. In GoDaddy, open your products, pick the domain and choose Manage DNS (on other registrars: DNS settings or DNS records).

Step 3. Add a record:

  1. Type: A
  2. Name: @
  3. Value: the public IPv4 address you copied
  4. TTL: leave the default

If an A record for @ already exists (new domains often have one pointing to a parking page), edit it instead of adding a second one.

Step 4. Save.

Classroom line

Next, we have to add it inside GoDaddy.

8. Install Nginx and test the domain

Step 1. Connect to the server (Amazon Linux) with ssh. Make sure its Security Group allows HTTP on port 80.

Step 2. Install Nginx:

sudo yum install nginx -y

Step 3. Start it:

[ec2-user@ip-172-31-xx-xx ~]$ sudo service nginx start
Redirecting to /bin/systemctl start nginx.service

What that line means. On Amazon Linux the old service command hands the job to systemctl, the system's service manager, and tells you so. It is not an error: Nginx has started.

Step 4. Open http://PUBLIC_IP/, then http://example.com/. Both show the Welcome to nginx! page. If the name doesn't open yet, wait a few minutes (section 9).

Step 5. Make your own test page:

sudo nano /usr/share/nginx/html/hello.html

Type one line, for example Hello from my own domain, save with Ctrl+O, Enter, then Ctrl+X.

Step 6. Open http://example.com/hello.html. Your line shows. The name now works exactly like the IP did.

9. Two things to know: the IP can change, and DNS takes time

Problem 1: the public IP changes. When you stop an EC2 instance and start it again, AWS gives it a new public IP. A reboot keeps the IP; a stop and start doesn't. The A record still holds the old IP, so example.com stops working.

Problem 2: DNS changes take time. Resolvers remember (cache) an answer for the record's TTL (time to live). After you change a record, some visitors get the old answer until that time runs out. Usually it's minutes; GoDaddy's own message says most updates take effect within an hour but can take up to 48 hours.

Example 2, step by step:

  1. Monday: A record @ -> OLD_IP. The site opens.
  2. Evening: you stop the server to save money.
  3. Tuesday: you start it. EC2 shows a NEW_IP.
  4. example.com still points to OLD_IP: the site doesn't open.
  5. Quick fix: edit the A record to NEW_IP, save, and wait for the TTL.

The proper fix is an Elastic IP: a public IP that stays the same until you release it. That's the next chapter.

Stop and start gives a new public IP; the A recordstill has the old one 1. Today A  @  OLD_IP Site opens. All good. 2. Stop, then start EC2: NEW_IP AWS gives a new public IP. 3. Site broken A  @  OLD_IP The name still points to the old IP. Quick fix: put the new IP in the A record, then wait: DNS answersstay cached for the TTL. Proper fix: an Elastic IP, a public IP that stays the same. That isthe next chapter.

Figure 5. A stop and start gives a new public IP, but the A record still has the old one. Update the record, or use an Elastic IP (next chapter).

10. Why: many websites on one server (virtual hosting)

Every running server adds to the AWS bill. Most small websites are busy only a little each day.

Classroom line

Why should we host multiple websites inside one server?

Classroom line

The more servers you use, the bigger the bill you'll get.

Example 3: an idle server, with numbers. Suppose a small site gets visitors for about 100 minutes a day.

  1. A day has 24 × 60 = 1,440 minutes.
  2. Busy: 100 minutes. Idle: 1,440 − 100 = 1,340 minutes.
  3. 1,340 ÷ 1,440 ≈ 0.93, so the server sits idle about 93% of the day.

Classroom line

So out of 24 hours it's used only about a hundred minutes, which means your server is sitting idle.

Example 4. Four small sites on four servers means four servers on the bill. The same four sites on one server means one. This is virtual hosting: one server, one Nginx, a folder per site, and Nginx picks the folder by the name the visitor typed. Shared hosting plans are cheap for the same reason: many small sites share one big server.

Virtual hosting: many websites on one server One EC2 server, one Nginx /usr/share/nginx/ musicplayer/ music.example.com videoplayer/ video.example.com photogallery/ photo.example.com Why Each server adds to the bill. Small sites are busy only a little each day; the rest of the time theserver idles. Share one server: less cost, better use. Shared hosting plans work thesame way.

Figure 6. Virtual hosting: three names, one EC2 server, one Nginx, one folder per site.

11. What: TLD, domain and subdomain

Read a name from right to left. Take onepage.example.com:

  1. .com is the top-level domain (TLD). Others: .in, .org, .net.
  2. example.com is the domain: the part you register and renew.
  3. onepage is a subdomain. You create subdomains yourself, as many as you need, with DNS records. No extra registration.

Example 5. Suppose we are Google: mail.google.com, maps.google.com and drive.google.com are subdomains of one domain, google.com, and each opens a different service.

Reading a name from right to left onepage.example.com .com Top-level domain (TLD)   .in, .com, .org and more. The last part of thename. example Domain   example.com: the name you register and renew. onepage Subdomain   You create it yourself, free, with a DNSrecord. Suppose we are Google: mail.google.com, maps.google.com anddrive.google.com are subdomains of one domain.

Figure 7. TLD, domain and subdomain in onepage.example.com.

12. How: CNAME records for subdomains

A CNAME record says "this name is another name for that name". A CNAME onepage -> example.com makes onepage.example.com follow example.com, which already has the A record with the IP.

Why CNAME and not more A records? All subdomains follow the one A record. When the IP changes, you edit one record, not one per subdomain.

Step 1. In GoDaddy's Manage DNS, click to add a new record.

Step 2. Fill in:

  1. Type: CNAME
  2. Name: onepage (only the subdomain part)
  3. Value: example.com (some registrars also accept @)
  4. TTL: default
GoDaddy new-record form: the note that CNAME records point a subdomain or alias to another domain name, then Type set to CNAME, an empty Name field, an empty Value field, a TTL drop-down, and the Add More Records, Save and Cancel buttons.

Console: Adding a CNAME record in GoDaddy: Type CNAME, the subdomain in Name, the domain in Value, then Save.

Step 3. Save, then repeat for each site: landing, scroll, animated.

Step 4. Delete old records you no longer use, so the list stays clean.

Now your records look like this:

Type    Name       Value
A       @          PUBLIC_IP
CNAME   landing    example.com
CNAME   onepage    example.com
CNAME   scroll     example.com
CNAME   animated   example.com
DNS records for one server and its subdomains Type Name → Value A @ → PUBLIC_IP CNAME music → example.com CNAME video → example.com CNAME photo → example.com A record @ means the domain itself. It points to an IP address. CNAME record A subdomain points to another name, here the domain, which has the IP.

Figure 8. One A record for the domain, one CNAME per subdomain.

13. How: get the website templates onto the server

We need four different sites. A quick way is a public GitHub repository that holds several HTML templates, one per folder.

Step 1. Go to Nginx's folder:

cd /usr/share/nginx

Step 2. Download the repository as a ZIP (copy the link from Code > Download ZIP). sudo is needed because this folder belongs to root:

sudo wget https://github.com/OWNER/REPO/archive/refs/heads/master.zip

The ZIP has only the files, without the project's history; git clone is the other way to get a repository.

Step 3. Unzip it and give the folder a short name:

sudo unzip master.zip
sudo mv REPO-master websites
cd websites

Step 4. List the folders:

[ec2-user@ip-172-31-xx-xx websites]$ ls
'Animated Template'  'Landing Page Template'  'One Page Template'  'Scroll Template'

Why rename them. Names with spaces are painful in commands and in nginx.conf. In the shell, a space separates words, so a backslash before each space (\) says "this space is part of the name". Quotes do the same job.

Step 5. Rename each folder to one short word:

sudo mv Animated\ Template animated
sudo mv Landing\ Page\ Template landing
sudo mv "One Page Template" onepage
sudo mv Scroll\ Template scroll

Tip: type the first letters and press Tab; the shell adds the backslashes for you.

Step 6. Check:

[ec2-user@ip-172-31-xx-xx websites]$ ls
animated  landing  onepage  scroll
[ec2-user@ip-172-31-xx-xx websites]$ ls landing
index.html  ...

Each folder has its own index.html. Use the folder that holds index.html as the site's folder, as in the previous chapter.

14. How: one Nginx server block per subdomain

In nginx.conf, each server { ... } block is one website. Two settings (directives) decide which one:

  1. server_name: the name this block answers to.
  2. root: the folder it serves.

Classroom line

Notice that inside the server block there's something called server_name.

How Nginx picks a block. The browser sends the name it asked for along with the request. Nginx compares it with each server_name. If one matches, that block's root is served. If none matches, for example a visit by bare IP, the default block answers; in the Amazon Linux nginx.conf that's the first server block.

Classroom line

Whenever Nginx can't match the name, it simply goes into the first server block it sees.

How Nginx picks the site: the name asked for vsserver_name Browser asks for http://landing.example.com/ The name travels with the request (the Host header). server_name _; root /usr/share/nginx/html; No server_name matches the bare IP, so the default (first)block answers. server_name landing.example.com; root .../websites/landing; landing.example.com matches the second block: Nginx serves thelanding folder. server_name onepage.example.com; root .../websites/onepage; onepage.example.com matches its own block: the onepage folder. server_name scroll.example.com; root .../websites/scroll; scroll.example.com matches its own block: the scroll folder.

Figure 9. Animation: each name matches its own server_name and gets its own folder; a bare IP gets the default (first) block.

Step 1. Open the settings file:

sudo nano /etc/nginx/nginx.conf

Step 2. Leave the existing server block (with server_name _;) as it is. Below its closing }, still inside the http { ... } block, add one block per site:

server {
    listen       80;
    listen       [::]:80;
    server_name  landing.example.com;
    root         /usr/share/nginx/websites/landing;
}

server {
    listen       80;
    listen       [::]:80;
    server_name  onepage.example.com;
    root         /usr/share/nginx/websites/onepage;
}

Add the same for scroll and animated. Only server_name and root change from block to block. Save with Ctrl+O, Enter, then Ctrl+X.

nano editing nginx.conf: a server block with listen 80, listen [::]:80, server_name scroll.example.com and root /usr/share/nginx/websites/scroll.

Console: One server block in nginx.conf: listen on port 80, server_name set to the subdomain, root set to that site's folder.

Classroom line

Okay, all four server blocks are done.

Step 3. Test the file, then reload:

[ec2-user@ip-172-31-xx-xx ~]$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[ec2-user@ip-172-31-xx-xx ~]$ sudo service nginx reload
Redirecting to /bin/systemctl reload nginx.service

reload applies the new settings without stopping the sites that are already running.

15. Test each subdomain

Verify HTTPS for each subdomain you actually serve

Once the lab names answer over HTTP, list the names that also need HTTPS. During the TLS connection the browser expects a valid certificate for the name it requested. Two subdomains can share an IP address but still need certificate coverage for both names. A certificate only for shop.example.com cannot be assumed to cover docs.example.com.

Test each planned URL separately. Check the certificate name and the page body. A valid certificate with the wrong page means you should inspect the selected server block and document root. A certificate warning sends you to the TLS configuration and name coverage. Test before asking users to enter private information.

Step 1. Open each address:

  1. http://landing.example.com/ shows the landing template.
  2. http://onepage.example.com/ shows the one-page template.
  3. http://scroll.example.com/ shows the scroll template.
  4. http://animated.example.com/ shows the animated template.
  5. http://PUBLIC_IP/ still shows the default page from /usr/share/nginx/html.

If one doesn't open:

  1. Wait a few minutes after adding the CNAME (TTL), then try again.
  2. Check the CNAME's Name has only the subdomain (landing, not landing.example.com).
  3. Check server_name and root in that block, and that the folder holds index.html.
  4. Run sudo nginx -t again and reload.

Example 6: five sites, one bill. Five names (the domain plus four subdomains), five server blocks counting the default one, and five DNS records (one A, four CNAME), all on one EC2 server.

16. Capital letters: the domain doesn't care, the path can

Q: Does LANDING.Example.COM work? Yes. The domain part of a web address is not case-sensitive; browsers turn it into small letters before asking DNS.

But the path can be. The part after the domain is a file path on the server. On a Linux server /Images/Logo.png and /images/logo.png are two different files, so a wrong capital letter gives 404 Not Found.

Habit. Use small letters for folder and file names, and type links exactly as the files are named.

Capital letters: the domain part does not care, thepath can http://Landing.Example.COM   /Images/Logo.png Domain part Not case-sensitive. LANDING.example.com and landing.example.comreach the same site; browsers turn it into small letters. Path after the domain Can be case-sensitive. On a Linux server /Images/Logo.png and/images/logo.png are different files.

Figure 10. The domain part is not case-sensitive; the path after it can be.

17. The whole flow on one page

  1. Buy a domain; keep owner and admin in your own account.
  2. A record: @ -> PUBLIC_IP.
  3. sudo yum install nginx -y, sudo service nginx start; open http://example.com/.
  4. For each site: a CNAME name -> example.com.
  5. sudo wget the templates, sudo unzip, rename folders to short names.
  6. One server block per subdomain with server_name and root.
  7. sudo nginx -t, sudo service nginx reload, open each subdomain.
  8. Stop and start changes the IP: update the A record, or use an Elastic IP (next chapter).

Hands-on lab: domain, A record, CNAME and subdomains on one Nginx server

A name only works when every link is right: record, wait, server block, folder. This lab builds and checks each link in order.

  1. Copy the server's public IP
    • Do: EC2 → Instances → select the server → copy Public IPv4 address. Security tab: inbound HTTP 80 from 0.0.0.0/0 is present.
    • You should see: An IP like 13.233.x.x.
    • Check: http://PUBLIC_IP/ already opens Nginx.
    • Why: Fix the server first; DNS can't fix a closed port.
  2. Add the A record
    • Do: Registrar (e.g. GoDaddy) → My Products → your domain → DNS / Manage DNS → Add New Record → Type A, Name @, Value PUBLIC_IP, TTL 1/2 Hour (or default) → Save. If an A @ parking record exists, Edit it instead.
    • You should see: The record list shows A @ PUBLIC_IP.
    • Check: Only one A record for @.
    • Why: @ = the bare domain; two A records would split visitors.
  3. Add CNAME records for subdomains
    • Do: Add New Record → Type CNAME, Name music, Value @ (or example.com) → Save. Repeat for video and www.
    • You should see: CNAME music example.com, etc.
    • Check: Each subdomain points to the domain, not straight to the IP.
    • Why: If the IP changes, you fix only the A record.
  4. Check DNS from your laptop
    • Command:
      nslookup example.com
      nslookup music.example.com
    • You should see: Name: example.com Address: PUBLIC_IP; for music: canonical name = example.com then the same Address.
    • Check: Matches the EC2 IP. If not, wait for the TTL and retry.
    • Why: Separates a DNS problem from a server problem.
  5. Make one folder per site
    • Command: sudo mkdir -p /usr/share/nginx/{music,video} && echo '<h1>Music</h1>' | sudo tee /usr/share/nginx/music/index.html && echo '<h1>Video</h1>' | sudo tee /usr/share/nginx/video/index.html
    • You should see: Each tee echoes its line.
    • Check: ls /usr/share/nginx/music → index.html.
    • Why: Virtual hosting = one folder per name on one server.
  6. Add a server block per subdomain
    • Command:
      sudo nano /etc/nginx/conf.d/music.conf   # server { listen 80; server_name music.example.com; root /usr/share/nginx/music; index index.html; }
      sudo nano /etc/nginx/conf.d/video.conf   # same with video
    • You should see: Files saved.
    • Check: ls /etc/nginx/conf.d shows both.
    • Why: Nginx picks the block whose server_name matches the Host the browser sends.
  7. Test and reload
    • Command: sudo nginx -t && sudo systemctl reload nginx
    • You should see: syntax is ok, test is successful.
    • Check: No output after reload means success.
    • Why: Never reload an untested config on a live server.
  8. Test each name
    • Command:
      curl -H 'Host: music.example.com' http://localhost/
      curl -H 'Host: video.example.com' http://localhost/
    • You should see: <h1>Music</h1> and <h1>Video</h1>.
    • Check: Browser: http://music.example.com/ and http://video.example.com/ show their pages.
    • Why: The Host header test works even before DNS has spread.
  9. After stop/start: update the A record
    • Do: If you stop and start EC2, copy the new Public IPv4, then registrar DNS → Edit A @ → new IP → Save. Wait for the TTL.
    • You should see: nslookup example.com shows the new IP.
    • Check: Site opens again.
    • Why: Stop/start changes the public IP; Elastic IP (next chapter) prevents this.

18. Try at home

Try at home

Task 1: one domain

  1. Buy a cheap practice domain, or use one you already own.
  2. Add an A record @ to your EC2 public IP.
  3. Install and start Nginx, then open your domain and a hello.html test page.

Task 2: three subdomains

  1. Add three CNAME records pointing to your domain.
  2. Download three templates under /usr/share/nginx/websites/, with short folder names.
  3. Add three server blocks, test with sudo nginx -t, reload, and open all three.
  4. Open one with capital letters in the domain, then try a wrong capital letter in a file path and see the 404.

When you're done, terminate the instance, and delete the A record so your domain doesn't point at an IP you no longer own.

Common errors and fixes

Error / symptomFix
Name doesn't open, IP doesDNS not spread yet or wrong IP in A record; check nslookup and wait for TTL.
All subdomains show the same pageserver_name typo or file not in conf.d ending .conf; the default block answered.
NXDOMAIN in nslookupRecord name wrong (e.g. music.example.com typed in Name field). Use just music.
Site broke after server restartStop/start gave a new IP; edit the A record or use an Elastic IP.
https:// failsNo certificate yet; use http:// until you add one.

FAQ

Q. A vs CNAME?

A points a name to an IP. CNAME points a name to another name.

Q. How long does DNS take?

Usually minutes; registrars say up to 48 hours.

Q. Do capital letters matter?

Not in the domain. They can in the path, because Linux file names are case sensitive.

Q. Why many sites on one server?

Each server costs money; small sites share one with virtual hosting.

Recap

In short

  1. People remember names, not IPs. DNS turns a name into an IP: your computer asks a resolver, the resolver reads the domain's records.
  2. Registrars (GoDaddy, Hostinger, Amazon Route 53 and others) register domains for 1 to 10 years; check the term, add-ons and renewal price in the cart.
  3. Owner and admin details stay with the business owner; developers get limited access only.
  4. A record @ -> PUBLIC_IP points the domain to your server. sudo service nginx start prints a harmless Redirecting to /bin/systemctl line.
  5. A stop and start gives a new public IP, and DNS changes take time (TTL); an Elastic IP is the fix.
  6. Virtual hosting puts many sites on one server to save cost.
  7. .com is the TLD, example.com the domain, onepage.example.com a subdomain; CNAME records point subdomains at the domain.
  8. One Nginx server block per site: server_name picks the block, root gives the folder; the default block answers when nothing matches.
  9. The domain is not case-sensitive; the path can be.

Worked example: move one test subdomain without confusing DNS and Nginx

You moved class.example.com to a new lab server. Your laptop still opens the old page, while a classmate opens the new one. A resolver may still have the old record cached.

  1. Record the old answer and TTL with dig class.example.com A before changing anything. Find the domain's authoritative nameservers with dig example.com NS. Query one directly to check whether it already serves the new address.
  2. To test the web server independently, use curl --resolve class.example.com:443:203.0.113.10 https://class.example.com/ with your own hostname and candidate address. The request keeps the hostname for TLS and HTTP while using the supplied IP. Make sure the destination already has a certificate for the name.
  3. If the authoritative answer is new and a recursive resolver still returns the old value, wait for its cached TTL instead of changing Nginx. If both already return the new address and the page is wrong, diagnose the certificate, listener, server block or document root.
Interview question: will reducing the TTL after the switch clear old caches?

No. Resolvers that already cached the old answer may retain it until that answer's old TTL expires. Plan a lower TTL before a move when you need a shorter transition.

Reference 1 · Reference 2

Practise this chapter

Interview questions and answers

How can two hostnames reach the same instance but display different pages?

DNS resolves both names to the same address. The HTTP request preserves the hostname. Nginx selects a server block matching that host and serves files from its configured directory. Verify each name independently.

One resolver shows the old IP and another the new one. What should you check before editing DNS again?

Compare the authoritative answer with the cached resolver’s answer and remaining TTL. If the authoritative server already has the new value, allow caches to expire. Separately test that the new address serves the intended name.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. Which DNS record maps a name directly to an IPv4 address?

Answer and explanation

A. A

An A record stores an IPv4 address. A CNAME aliases one DNS name to another, whose address is resolved separately.

2. Two subdomains have the same A record but should show different sites. What can Nginx use to select a site?

Answer and explanation

D. The host name in the request and its server_name configuration

DNS gets both users to one address. Nginx then matches the HTTP Host to a server block and its document root.

3. A DNS lookup is correct, but HTTPS warns that the certificate names a different host. Which setup needs checking?

Answer and explanation

C. TLS certificate coverage for the requested host

Reaching the correct IP does not establish that the TLS certificate covers this name. Check the site's HTTPS listener and certificate.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

Seoul Beauty Lab is a cosmetics business in Seoul. Ji-woo Park looks after its IT and cloud work. They count money in KRW and run their AWS resources in the ap-northeast-2 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 12

Easy Restart a service after a change

Config changes only apply after the service restarts or reloads.

Restart the nginx service.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Check if a service is running

When a site is down, first check whether the web server process is running.

Show the status of the httpd service.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Install a package on Ubuntu

Ubuntu uses apt. Package names differ: on Ubuntu Apache is apache2.

Install the apache2 package on Ubuntu without being asked to confirm.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Install a package on Amazon Linux

dnf is the package manager on Amazon Linux 2023. -y answers yes for you.

Install the httpd package on Amazon Linux 2023 without being asked to confirm.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy List hosted zones

You need the zone ID to change records.

List all hosted zones in the account.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Port for MySQL

The DB security group should open only this port, only to the app.

Seoul Beauty Lab's app talks to RDS MySQL. Which port should the DB security group allow?

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Find the database endpoint

Your app connects using the endpoint name, not an IP.

Describe DB instance seoulbeauty-db.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Test the nginx config

A test catches typos before a restart takes your site down.

Check the nginx configuration files for errors.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Start a service now and at boot

enable makes it start after reboot; --now also starts it right away.

Enable the nginx service and start it immediately, in one command.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Open port 80 to the world

Visitors can reach your website only if the security group allows HTTP.

Allow inbound TCP port 80 from 0.0.0.0/0 on security group sg-01c51c3c10204c3b2.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Create a hosted zone

A hosted zone holds all DNS records for your domain.

Create a public hosted zone for seoulbeauty.kr, with caller reference seoulbeauty-2026-01.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard Create or update a DNS record

UPSERT creates the record or updates it if it already exists.

Apply the record changes in change.json to hosted zone Z0123456789ABCDEFGHIJ.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: How DNS works. People remember names, not IPs like 13.2.1.9. DNS is the internet's phone book: it turns a domain name into an IP address. Buy a domain at a registrar, then add records in its DNS settings. Check the answer:
Revision card: How DNS works · Download PNG
Revision card: Add an A record for EC2. Your domain must point to the server before the site opens by name. An A record maps a name to an IPv4 address. @ means the root domain. DNS settings › Add record › Type A › Host @ › Value = EC2 public IP. Record:
Revision card: Add an A record for EC2 · Download PNG
Revision card: Why DNS changes take time: TTL. After you change an IP, some users still reach the old server. TTL = seconds that resolvers may keep the old answer in cache. Lower the TTL before a planned change; use an Elastic IP so the IP never changes. TTL 3600 = up to 1 hour of old answers after a change.
Revision card: Why DNS changes take time: TTL · Download PNG
Revision card: Virtual hosting in Nginx. Paying for one server per small site wastes money. Virtual hosting serves many sites from one server, chosen by the name the browser asks for. One server block per site, each with its server_name and root. Block for a subdomain:
Revision card: Virtual hosting in Nginx · Download PNG
Comparison: A record vs CNAME record. A record: Maps a name to an IPv4 address. CNAME record: Maps a name to another name.
Comparison: A record vs CNAME record · Download PNG
Comparison: Domain vs Subdomain. Domain: The name you buy from a registrar, like example.com. Subdomain: A name in front of your domain, like blog.example.com.
Comparison: Domain vs Subdomain · Download PNG
Interview card: What happens when you type a domain name in the browser?. The browser asks DNS for the IP, then connects to that IP on port 80 or 443. Servers are found by IP; names are for humans. example.com › 13.2.1.9 › GET / on port 443.
Interview card: What happens when you type a domain name in the browser? · Download PNG
Interview card: A record vs CNAME: when do you use each?. A points a name to an IP. CNAME points a name to another name. CNAME follows the target if its IP changes. @ A 13.2.1.9; www CNAME example.com.
Interview card: A record vs CNAME: when do you use each? · Download PNG
Interview card: Your site stopped opening by name after a stop and start. Why?. The public IP changed, but the A record still has the old IP. Dynamic public IPs are released on stop. Use an Elastic IP and put it in the A record once.
Interview card: Your site stopped opening by name after a stop and start. Why? · Download PNG
Interview card: Does capitalisation matter in a URL?. Not in the domain; often yes in the path on Linux servers. DNS ignores case, but Linux file names are case-sensitive. EXAMPLE.com works; /About.html ≠ /about.html.
Interview card: Does capitalisation matter in a URL? · Download PNG

More cards: Ravi Sir's Cards.