DEV Community

Md Asaduzzaman
Md Asaduzzaman

Posted on

Deep learning about DNS records!

🌍 DNS & VPS Setup Guide (Example: plabonasad.xyz)

When you purchase a domain and a VPS hosting, you need to connect them.

This is done using DNS records and configuring your VPS (like Nginx/Apache).

This guide is brief, step-by-step, and developer-friendly.


πŸ“– Quick Overview: DNS Records

DNS is like the phonebook of the internet.

It tells the browser or mail server where to go when someone uses your domain.

Common DNS Records

Record Purpose Example
A Points domain β†’ IPv4 address plabonasad.xyz β†’ 123.45.67.89
AAAA Points domain β†’ IPv6 address plabonasad.xyz β†’ 2606:4700:4700::1111
MX Directs emails β†’ mail server @ MX 10 mail.google.com
CNAME Points domain β†’ another domain www β†’ plabonasad.xyz
TXT Stores text (for verification & security) "v=spf1 include:_spf.google.com ~all"

πŸ‘‰ For website setup, the A record is the most important (connects your domain β†’ VPS IP).


πŸš€ Step 1: Get Your VPS Public IP

Login to your VPS provider dashboard and copy your IPv4 address.

Example: 123.45.67.89


πŸš€ Step 2: Set DNS Records

Go to your domain registrar DNS settings (where you bought plabonasad.xyz).

Add the following records:

Type Name Value Purpose
A @ 123.45.67.89 Root domain β†’ VPS
A www 123.45.67.89 www β†’ VPS

πŸ‘‰ This means:

  • plabonasad.xyz β†’ goes to your VPS
  • www.plabonasad.xyz β†’ goes to your VPS

🌍 Overview Flow (Diagram)

User Browser (plabonasad.xyz)
          |
          v
   DNS Lookup (A Record β†’ 123.45.67.89)
          |
          v
       VPS Server
          |
          v
      Nginx/Apache
          |
          v
     Your Website

Enter fullscreen mode Exit fullscreen mode

πŸš€ Step 3: Configure Nginx on VPS

SSH into your VPS:

ssh username@123.45.67.89
Enter fullscreen mode Exit fullscreen mode

Create a config for your domain:

sudo nano /etc/nginx/sites-available/plabonasad.xyz
Enter fullscreen mode Exit fullscreen mode

Copy nginx config code:

# Redirect everything to https://plabonasad.xyz
server {
    listen 80;
    server_name www.plabonasad.xyz;
    return 301 https://plabonasad.xyz$request_uri;
}

# Main site (canonical domain)
server {
    listen 80;
    server_name plabonasad.xyz;

    root /var/www/app1/public;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

Enter fullscreen mode Exit fullscreen mode

Enable the site by symlink:

sudo ln -s /etc/nginx/sites-available/plabonasad.xyz /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

Step 4: Test DNS

Check if your domain points to the VPS:

dig plabonasad.xyz
Enter fullscreen mode Exit fullscreen mode

Or use dnschecker.org

Step 5: Secure with SSL (Optional but Recommended)

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y
Enter fullscreen mode Exit fullscreen mode

Run:

sudo certbot --nginx -d plabonasad.xyz -d www.plabonasad.xyz
Enter fullscreen mode Exit fullscreen mode

Now your site will load with HTTPS πŸ”’.

Final Notes

  • A record connects domain β†’ server IP
  • Nginx/Apache serves the website from VPS
  • SSL (Certbot) secures with HTTPS
  • Other records (MX, CNAME, TXT) are useful for email & verification

Now when someone types plabonasad.xyz, they’ll reach your VPS-hosted site πŸŽ‰.

Top comments (0)