12. Domains and DNS: GoDaddy, Elastic IP, A/CNAME and Subdomains
12.7 Subdomains
Subdomains free aani unlimited aahet – pratyek subdomain mhanje ek DNS record aani ek server block/virtual host.
example.com ─┐
www.example.com ─┼─► A 203.0.113.10 (web-1) ─► server_name decides the folder
blog.example.com ─┘ /var/www/example, /var/www/blog
api.example.com ───► A 203.0.113.20 (app server, Node on :3000 behind Nginx)
shop.example.com ───► CNAME my-alb-123.ap-south-1.elb.amazonaws.com
Step 1: DNS record (GoDaddy → DNS → Add New Record)
| Type | Name | Value | Use |
|---|---|---|---|
| A | blog |
203.0.113.10 |
Same server, different site |
| A | api |
203.0.113.20 |
Different EC2 instance (its own Elastic IP) |
| CNAME | shop |
my-alb-123.ap-south-1.elb.amazonaws.com |
AWS load balancer / other hostname |
| A | * |
203.0.113.10 |
Wildcard: any undefined subdomain |
In the Name field type only the subdomain part (blog), not blog.example.com. Otherwise you may create blog.example.com.example.com.
Step 2: a site for the subdomain on the server
sudo mkdir -p /var/www/blog
echo '<h1>Welcome to blog.example.com</h1>' | sudo tee /var/www/blog/index.html
# Nginx: blog.conf
server {
listen 80;
server_name blog.example.com;
root /var/www/blog;
index index.html;
}
# Apache: blog.conf
<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/blog
<Directory /var/www/blog>
Require all granted
</Directory>
</VirtualHost>
Test, reload, then verify with dig blog.example.com +short and curl http://blog.example.com.
Subdomain for a backend app (reverse proxy)
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://127.0.0.1:3000; # Express / Flask app (Chapter 9)
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
(On CentOS remember sudo setsebool -P httpd_can_network_connect 1.)
Why this matters for security
Forgotten subdomains (dev., test., old.) often run outdated software without monitoring – bug bounty hunters find many issues there. And if shop is a CNAME to a cloud resource that you delete, someone else may claim that resource name and serve content on your subdomain (subdomain takeover). Delete DNS records when you delete resources.
Ravindra Bagale's Tip
GoDaddy madhe Name field madhe khup students purna blog.yourdomain.com lihitat aani blog.yourdomain.com.yourdomain.com banto. Fakt blog lihaa. Aani wildcard * record soyiche aahe pan pratyek chukiche naav pan tumchya server var yete – garaj asel tarach vapra.
Lab
Create blog.yourdomain.com (A record to the same EIP) with its own folder and server block. Confirm with dig and curl that yourdomain.com and blog.yourdomain.com show different pages.
Thodkyaat sangaycha tar
- Registrar, DNS host and server are three separate things.
- A = name → IPv4, CNAME = alias → name (not at the apex), MX mail, TXT verification/SPF, NS delegation; TTL controls caching.
- Always point DNS to an Elastic IP, never to the auto-assigned public IP.
- GoDaddy: A
@→ EIP, CNAMEwww→@; delete parked records; UI may vary. - Web server must list the names in
server_name/ServerName+ServerAlias. - Verify with
dig,dig @8.8.8.8,curl -H "Host:". Subdomain = record + site block; delete dangling records.
Samjla ka? Tumchya website la aata naav aahe! Aata pudhe jaauya – ekach server var anek websites aani HTTPS.