Domains & Websites
How to Point a Domain to Your VPS: DNS Records, nginx and Free SSL
By NileVPS Team · Published · 6 min read
اقرأ المقال بالعربيYou've bought a domain and set up a VPS, and now you want your site to load when visitors type the domain name instead of an IP address. This happens in two stages. The first takes place at your domain registrar or DNS provider, where you tell the world that this name points to your server's address. The second happens on the server itself, where you configure the web server to accept requests for that name and serve them over HTTPS. In this guide we cover both stages in detail on Ubuntu 24.04 or Debian 12, including the Cloudflare option.
What You Need
- A domain registered with any registrar, with access to edit its DNS records.
- A VPS with a static IPv4 address, plus an IPv6 address if available. If you don't have a server yet, take a look at our VPS plans.
- An SSH connection with a
sudouser, as described in connecting to a Linux VPS over SSH.
The examples use the domain example.com and the address 203.0.113.10, so replace them with your own details.
Stage One: DNS Records
The Records You'll Need
| Record | Name (Host) | Value | Purpose |
|---|---|---|---|
| A | @ | 203.0.113.10 | Points the root domain to the IPv4 address |
| AAAA | @ | Your server's IPv6 address | Points the root domain to the IPv6 address |
| CNAME | www | example.com | Makes www follow the root domain |
The @ symbol means the domain itself, with no prefix. Log in to your provider's DNS management panel, delete any old A records for @ or www that point to the registrar's default parking pages, then add the records above.
Important notes:
- Only add an AAAA record if IPv6 actually works on your server. Otherwise the site will fail for visitors whose connection prefers IPv6.
- Instead of a CNAME, you can add a second A record for
wwwwith the same address; the result is practically identical. However, you cannot put a CNAME on@itself. - Don't delete MX records if you use email on this domain.
TTL and Propagation
TTL is the time, in seconds, that DNS servers around the world cache an answer before asking again. If the old record had a TTL of 86400 (a full day), some visitors may keep seeing the old address for up to a day. So:
- If you are moving an existing site, lower the TTL to 300 seconds a day before the move, then change the address, and once everything is stable raise it again to something like 3600.
- If the domain is new, records usually appear within minutes.
- If you change the nameservers themselves, propagation can take several hours, and occasionally up to 48 hours.
Verifying the Records
On Linux or macOS, use dig. On Ubuntu and Debian you may need to install it first via the dnsutils package:
sudo apt install -y dnsutils
dig +short example.com A
dig +short example.com AAAA
dig +short www.example.comTo query a specific public DNS server and bypass your local cache:
dig @1.1.1.1 +short example.com A
dig @8.8.8.8 +short example.com AOn Windows, use nslookup in PowerShell:
nslookup example.com 1.1.1.1Once you see 203.0.113.10 in the output, move on to the next stage.
Stage Two: Configuring the Server
Install nginx and Open the Ports
sudo apt update
sudo apt install -y nginx
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enableNginx Full opens ports 80 and 443. If you use the cloud firewall in the NileVPS panel, make sure both ports are allowed there too.
Create the Site Folder and Configuration File
sudo mkdir -p /var/www/example.com
echo '<h1>example.com is working</h1>' | sudo tee /var/www/example.com/index.html
sudo chown -R www-data:www-data /var/www/example.comNext, create the site's configuration file (server block):
sudo nano /etc/nginx/sites-available/example.comWith the following content:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}Enable the site, test the configuration, then reload:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxOpen http://example.com in your browser and your page should appear. If you see the default nginx page instead, double-check that server_name is spelled correctly.
Free SSL Certificate with Certbot
Let's Encrypt issues free certificates trusted by every browser, and Certbot issues and renews them automatically:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.comYou will be asked for an email address for expiry notices and to accept the terms. Certbot verifies that you control the domain over port 80, then automatically updates the nginx configuration to add HTTPS and redirect HTTP to it.
The certificate is valid for 90 days, and the package installs a systemd timer that renews it automatically. Check the timer and test renewal:
systemctl list-timers | grep certbot
sudo certbot renew --dry-runIf issuance fails, the cause is usually that the DNS records haven't propagated yet, or that port 80 is closed in one of the two firewalls.
The Cloudflare Option
You can move DNS management to Cloudflare for free by changing the nameservers at your registrar. When adding an A record, you'll see two options:
- DNS only (grey cloud): Cloudflare acts purely as a DNS provider, and visitors connect to your server directly.
- Proxied (orange cloud): visitors pass through Cloudflare's network, your server's real IP is hidden, and you get caching and DDoS protection.
The order we recommend to avoid problems:
- Add the records in DNS only mode first, and issue the Let's Encrypt certificate on the server as in the previous step.
- Switch the records to Proxied.
- In Cloudflare's SSL/TLS settings, choose Full (strict) mode. Avoid Flexible mode, because it leaves the connection between Cloudflare and your server unencrypted and can cause an infinite redirect loop with the Certbot configuration.
In Proxied mode, your nginx logs will show Cloudflare's addresses instead of your visitors' IPs. You can fix this with nginx's real_ip module, using Cloudflare's published IP ranges and the CF-Connecting-IP header. For stronger protection, restrict ports 80 and 443 in your firewall to Cloudflare's ranges only, so nobody can reach the server directly.
FAQ
How long does it take to point a domain to a server?
Changes to the records themselves usually show up within minutes, depending on the TTL. Changing nameservers can take several hours and, in rare cases, up to 48 hours. Use dig against different public DNS servers to track progress.
Should I use a CNAME or an A record for www?
Both work. A CNAME is easier to maintain, because if you change the server's address you only update the root A record and www follows automatically. Just never put a CNAME on the root domain @.
Can I point more than one domain to the same server?
Yes. Create DNS records for each domain pointing to the same address, give each one its own nginx server block and site folder, then issue a certificate for it with Certbot. A single VPS can host dozens of small sites, depending on its resources.
Why does Certbot fail even though the site loads?
Common causes include an AAAA record pointing to the wrong IPv6 address so Let's Encrypt tries to connect there, Cloudflare in Proxied mode with redirect settings that block validation, or port 80 being closed. Fix the records, or temporarily switch to DNS only, then try again.