Point Cloudflare Domain to VPS: Step-by-Step
This guide shows you how to connect a domain name managed by Cloudflare to your own virtual private server (VPS). You’ll add your server’s IP address as a DNS record in Cloudflare, so when someone visits your domain, they reach your VPS. You need a Cloudflare account with your domain added, and a VPS with a public IPv4 address.
What You’ll Need
- A domain name registered and added to Cloudflare (free plan works).
- A VPS with a static public IPv4 address (e.g., from DigitalOcean, Linode, AWS EC2, or any provider).
- Access to the Cloudflare dashboard (you must be logged in).
- Optional: your VPS’s hostname (like
hostnamein terminal) to set a subdomain likewwworapp.
Step-by-Step
- Find your VPS IP address. Log into your VPS provider’s control panel and note the public IPv4 address (e.g.,
203.0.113.10). You can also runcurl ifconfig.mefrom your VPS terminal to see it. - Log in to Cloudflare. Go to
dash.cloudflare.comand sign in with your account. - Select your domain. On the dashboard, click the domain name you want to use (e.g.,
example.com). If you have multiple domains, choose the correct one. - Open the DNS settings. In the left sidebar, click DNS → Records. This shows all existing DNS records for your domain.
- Add an A record. Click Add record. For Type, choose A (it’s the default).
- Set the name. In the Name field, enter
@to point the root domain (likeexample.com) to your VPS. To point a subdomain likewwworblog, enter that subdomain (e.g.,www). - Enter the IPv4 address. Paste your VPS’s public IP address into the IPv4 address field.
- Choose proxy status. Leave the orange cloud icon Proxied (default) to use Cloudflare’s CDN and protection. If you need your VPS’s real IP to be visible (e.g., for SSH or certain APIs), click the cloud to turn it grey (DNS only).
- Save the record. Click Save. The record appears in your DNS list.
- Add a www record (optional). If you want
www.example.comto work, add another A record with Namewwwand the same IP. Or create a CNAME record fromwwwto@if you prefer. - Wait for propagation. DNS changes can take a few minutes to a few hours to update globally. Cloudflare usually updates quickly, but internet providers may cache old records.
- Test your setup. Open a browser and visit
http://yourdomain.com(orhttps://if you have SSL). You should see your VPS’s web server (e.g., Apache, Nginx) or your app. If not, check the troubleshooting section below.
Common Mistakes
- Using the wrong IP address. Make sure you copy the IPv4 address, not the IPv6 (unless you add an AAAA record separately). Also, ensure it’s the public IP, not a private one like 10.x.x.x.
- Forgetting the
@for the root domain. Leaving the Name field empty or using@incorrectly can cause the root domain to not resolve. - Leaving proxy on when you need direct access. If you’re connecting via SSH or FTP, the orange cloud can block or slow those connections. Turn it off (grey) for those records.
- Not updating existing records. If you already have an A record pointing elsewhere, you must edit or delete it before adding a new one, else you’ll have conflicting records.
- Ignoring TTL. The default TTL (Auto) is fine, but if you’re testing, you might want to lower it to 5 minutes temporarily to speed up changes.
Tips
- Use a subdomain for testing. If you’re not sure, point
test.example.comto your VPS first. Once it works, add the root domain. - Set up SSL/TLS. In Cloudflare, go to SSL/TLS → Overview and choose “Full (strict)” if your VPS has a valid SSL certificate. For a self-signed cert, use “Full”.
- Keep your VPS secure. Before pointing a domain, make sure your VPS has a firewall (like UFW) and SSH key authentication. A public domain will attract scans.
- Use a CNAME for www. Instead of a second A record, create a CNAME from
wwwto@(or to your domain). This is cleaner and allows Cloudflare to handle it. - Check your web server config. Your VPS must be listening on port 80 (HTTP) and/or 443 (HTTPS). If you’re using Nginx or Apache, ensure the server block or virtual host is set to your domain.
Troubleshooting
- Domain doesn’t load. First, check if the DNS record is correct by running
dig yourdomain.comornslookup yourdomain.comfrom your local machine. If it returns your VPS IP, the DNS is fine; the issue is likely your web server or firewall. - “This site can’t be reached” after a long wait. Verify that your VPS is running and that a web server is installed. Try accessing the IP directly in a browser (e.g.,
http://203.0.113.10). If that works, the problem is DNS; if not, check your VPS’s firewall and web server status. - Cloudflare shows a 522 error. This means Cloudflare can’t reach your origin server. Check that your VPS is online, that the IP is correct, and that your firewall allows port 80/443 from Cloudflare’s IP ranges (or from anywhere if you’re not restricting).
- SSL certificate errors. If you’re using Cloudflare’s proxy, go to SSL/TLS settings and set the mode to “Full” or “Full (strict)”. If you have your own certificate, install it on your VPS.
- Changes not appearing. Clear your browser cache and flush your local DNS (e.g.,
ipconfig /flushdnson Windows,sudo systemd-resolve --flush-cacheson Linux). Also try a different network (like your phone’s hotspot). - Email stops working. If you have email on this domain, don’t point the MX records to your VPS unless you’re running a mail server. Keep MX records as they are, and only add the A record for web traffic.
Frequently Asked Questions
Q: How long does it take for the domain to point to my VPS?
A: With Cloudflare, changes usually take effect in under a minute for most users, but global propagation can take up to 24 hours. Check with dig after a few minutes.
Q: Do I need to buy a domain from Cloudflare?
A: No. Cloudflare works with any domain registrar. You just need to add your existing domain to your Cloudflare account and use their nameservers.
Q: Can I point multiple domains to the same VPS?
A: Yes. Add an A record for each domain (or subdomain) with the same IP address. Your web server must be configured to respond to each domain.
Q: What’s the difference between “Proxied” and “DNS only”?
A: Proxied (orange cloud) hides your VPS IP and enables Cloudflare’s CDN and security features. DNS only (grey cloud) just resolves the domain to your IP, with no Cloudflare protection.
Q: Should I use an A record or CNAME?
A: For the root domain, you must use an A record (or AAAA for IPv6). For subdomains, you can use a CNAME pointing to another hostname, but an A record with the IP also works.
Q: My domain works, but the padlock shows “Not secure”.
A: That means SSL isn’t set up. If you’re using Cloudflare’s proxy, enable “Flexible” or “Full” SSL in the SSL/TLS settings. For a permanent solution, install a free certificate from Let’s Encrypt on your VPS.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.