Connecting a custom domain to your VPS makes everything feel more professional โ and for NAT VPS users, there's one extra step most guides skip. Here's the full picture.
The challenge with NAT VPS and domains
On a dedicated IP VPS, you point your domain's A record to your IP and traffic arrives on port 80/443. On a NAT VPS, your IP is shared โ ports 80 and 443 are likely already taken by the host. Your traffic comes in on one of your assigned ports instead (say, port 10080 for HTTP).
The cleanest solution: use Cloudflare as a proxy. Cloudflare accepts traffic on standard ports 80/443, then forwards it to your server on any port you specify.
Option 1 โ Cloudflare (recommended)
Step 1: Add your domain to Cloudflare (free plan). Update your domain's nameservers at your registrar to point to Cloudflare.
Step 2: In Cloudflare DNS, add an A record:
Type: A
Name: @ (or www)
Value: 147.135.215.238 (your host IP)
Proxy: ON (orange cloud)
Step 3: In Cloudflare, go to Rules โ Origin Rules. Create a rule that rewrites the destination port to your assigned HTTP port:
Hostname equals yourdomain.com
โ Rewrite destination port to: YOUR_HTTP_PORT
Now visitors hit yourdomain.com on port 80/443. Cloudflare proxies it to your server on your assigned port. SSL is handled by Cloudflare automatically.
Option 2 โ Direct DNS (non-standard port)
If you don't want to use Cloudflare, point an A record to the host IP and have users connect on your assigned port:
yourdomain.com:10080
This works fine for internal tools, dashboards, and services where you control who accesses them. For public websites, the non-standard port looks unprofessional.
Nginx configuration with a domain
server {
listen YOUR_HTTP_PORT;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yoursite;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
SSL without Cloudflare
Let's Encrypt works if you have port 80 available for the ACME challenge. On a NAT VPS, you may need to use the DNS challenge instead of the HTTP challenge:
apt install -y certbot python3-certbot-dns-cloudflare
certbot certonly --dns-cloudflare --dns-cloudflare-credentials ~/.secrets/cloudflare.ini -d yourdomain.com
Subdomain setup
Each subdomain just needs its own A record pointing to the same host IP, and its own Nginx server { } block on a different port. With Cloudflare port rewriting, each subdomain can map to a different port on your server โ letting you host multiple services under one domain.