🟫 ClodHost beta
Sign In
🎉 All services free during beta! 🎉 All services free during beta!

Setting Up Custom Domains

Use your own domain name like myapp.com instead of a ClodHost subdomain. Includes DNS setup and free SSL.

Reading time: 10 min Difficulty: Beginner
View examples as:
Ask Claude Manual Code

Table of Contents

How Custom Domains Work

When someone types your domain in their browser, here's what happens:

  1. Browser asks DNS "What's the IP address for myapp.com?"
  2. DNS responds with your server's IP address
  3. Browser connects to that IP address
  4. Your server sees the domain name and serves the right site

So you need to tell DNS to point your domain to your ClodHost server's IP address.

Buying a Domain

If you don't have a domain yet, here are some popular registrars:

Registrar Price (.com/year) Notes
Namecheap $10-13 Free privacy protection, good interface
Cloudflare $9-10 At-cost pricing, includes CDN
Google Domains $12 Simple, integrates with Google
Porkbun $9-10 Cheap, free WHOIS privacy
Recommendation

Cloudflare Registrar is great if you want CDN/caching features. Namecheap or Porkbun are good budget options.

Configuring DNS

Point your domain to your ClodHost server.

Find Your Server IP

Example prompt:

"What is the IP address of my server? I need it to configure my domain's DNS records."
# Find your server's public IP
curl ifconfig.me

# Or check ClodHost dashboard for your server's IP

Add DNS Records

Go to your domain registrar's DNS settings and add these records:

Type Name Value TTL
A @ 123.45.67.89 (your server IP) 3600
A www 123.45.67.89 (your server IP) 3600
DNS Propagation

DNS changes can take anywhere from a few minutes to 48 hours to propagate worldwide. If it doesn't work immediately, wait a few hours and try again.

Verify DNS

Example prompt:

"Check if my DNS is configured correctly for myapp.com. It should point to my server's IP address."
# Check A record
dig myapp.com +short

# Should return your server's IP address
# 123.45.67.89

# Check www subdomain
dig www.myapp.com +short

Setting Up SSL

HTTPS is essential for security and SEO. Let's get a free SSL certificate from Let's Encrypt.

Install SSL Certificate

Example prompt:

"Set up a free SSL certificate for myapp.com and www.myapp.com using Let's Encrypt and Certbot. Configure Nginx to use HTTPS and redirect all HTTP traffic to HTTPS."
# Install Certbot
sudo apt install certbot python3-certbot-nginx -y

# Get certificate (Certbot will auto-configure Nginx)
sudo certbot --nginx -d myapp.com -d www.myapp.com

# Follow the prompts:
# - Enter email for renewal notifications
# - Agree to terms
# - Choose to redirect HTTP to HTTPS (recommended)

# Test auto-renewal
sudo certbot renew --dry-run
Auto-Renewal

Certbot automatically sets up a cron job to renew certificates before they expire. You don't need to do anything!

www and non-www Redirects

Choose one canonical version (with or without www) and redirect the other.

Redirect www to non-www

Example prompt:

"Configure Nginx to redirect www.myapp.com to myapp.com (without www). Use a 301 permanent redirect so search engines update their index."
# /etc/nginx/sites-available/myapp

# Redirect www to non-www
server {
    listen 80;
    listen 443 ssl;
    server_name www.myapp.com;

    ssl_certificate /etc/letsencrypt/live/myapp.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/myapp.com/privkey.pem;

    return 301 https://myapp.com$request_uri;
}

# Main server block
server {
    listen 443 ssl;
    server_name myapp.com;

    ssl_certificate /etc/letsencrypt/live/myapp.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/myapp.com/privkey.pem;

    root /var/www/myapp;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

Adding Subdomains

Create subdomains like api.myapp.com or blog.myapp.com.

Subdomain Setup

Example prompt:

"Set up api.myapp.com as a subdomain that proxies to my Node.js API running on port 3001. Add SSL for the subdomain too."
# 1. Add DNS record
# Type: A, Name: api, Value: your-server-ip

# 2. Get SSL for subdomain
sudo certbot --nginx -d api.myapp.com

# 3. Configure Nginx
server {
    listen 443 ssl;
    server_name api.myapp.com;

    ssl_certificate /etc/letsencrypt/live/api.myapp.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.myapp.com/privkey.pem;

    location / {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Troubleshooting

Common Issues

Debugging Commands

Example prompt:

"My domain myapp.com isn't working. Help me debug the issue. Check DNS, Nginx configuration, and SSL certificate status."
# Check DNS
dig myapp.com +short
nslookup myapp.com

# Test Nginx config
sudo nginx -t

# Check Nginx is running
sudo systemctl status nginx

# View Nginx error log
sudo tail -f /var/log/nginx/error.log

# Check SSL certificate
sudo certbot certificates

# Test SSL connection
openssl s_client -connect myapp.com:443 -servername myapp.com