What are Subdomains?
Subdomains are prefixes added to your main domain (e.g., blog.example.com, api.example.com). Each can point to a different server or service.
Creating Subdomain Records
# Point to same server as main domain
blog.example.com. IN A 198.51.100.10
api.example.com. IN A 198.51.100.10
# Point to different server
staging.example.com. IN A 198.51.100.20
# Use CNAME for third-party services
mail.example.com. IN CNAME ghs.googlehosted.com.
shop.example.com. IN CNAME shops.myshopify.com.Wildcard Subdomains
# Match all subdomains not explicitly defined
*.example.com. IN A 198.51.100.10Useful for SaaS platforms where each customer gets a subdomain (e.g., customer1.myapp.com).
Web Server Configuration
# Nginx — serve different content per subdomain
server {
listen 80;
server_name blog.example.com;
root /var/www/blog;
}
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
}
}SSL for Subdomains
# Individual certs
sudo certbot --nginx -d blog.example.com
# Wildcard cert (covers all subdomains)
sudo certbot certonly --manual --preferred-challenges dns -d "*.example.com"