What Cloudflare does and why you'd add it to a VPS

Cloudflare sits between your visitors and your VPS. When someone visits your website, their request goes to Cloudflare first, not directly to your server. Cloudflare caches your pages, blocks some attacks, and hides your VPS's real IP address. You point your domain's nameservers to Cloudflare instead of your hosting provider, and Cloudflare routes traffic back to your VPS.

Most people add Cloudflare because it reduces the load on their VPS, speeds up pages for visitors far away, and provides free DDoS protection. You keep your VPS exactly as it is — Cloudflare works in front of it, not inside it.

The setup takes about 15 minutes if your domain registrar cooperates. The hardest part is usually waiting for nameserver changes to propagate, which can take a few hours to a full day.

Key Takeaways

  • Create a free Cloudflare account, add your domain, and Cloudflare will scan for your existing DNS records automatically.
  • Change your domain's nameservers at your registrar to point to Cloudflare's nameservers — this is the step that takes longest to take effect.
  • Once nameservers propagate, create an A record in Cloudflare pointing to your VPS's IP address.
  • Test that traffic reaches your VPS by visiting your domain and checking that pages load correctly.
  • You can enable Cloudflare's caching and security features after confirming the basic setup works.

Create a Cloudflare account and add your domain

Go to cloudflare.com and click Sign Up. Enter your email and create a password. Cloudflare will send you a confirmation email — click the link to verify your account.

After you log in, click Add a Site or Add Domain. Type your domain name (for example, example.com, not www.example.com). Cloudflare will ask you to choose a plan — the free plan works for most small sites and includes basic caching and DDoS protection. Click Continue.

Cloudflare will scan your domain's current DNS records and show you what it found. This usually takes a minute or two. You'll see records like MX records (for email) and any A records pointing to your old host. Review them to make sure they look right, then click Continue.

Change your nameservers at your domain registrar

Cloudflare will show you two nameservers to use. They look like this: ns1.cloudflare.com and ns2.cloudflare.com (the exact numbers and names vary). Write these down or keep the Cloudflare tab open.

Log into your domain registrar — the company where you bought your domain. This might be GoDaddy, Namecheap, Google Domains, your VPS provider, or another registrar. Find the section called Nameservers, DNS, or Domain Settings. Delete the old nameservers and enter Cloudflare's two nameservers exactly as shown.

Save the change. The registrar will confirm the update, but it won't take effect when ready. Nameserver changes propagate across the internet over the next few hours to 24 hours. You can check progress by going back to Cloudflare and clicking Check Nameservers — it will tell you when propagation is complete.

While you wait, do not make other DNS changes. If you need to add email or other services, do it in Cloudflare after nameservers propagate, not at your registrar.

Create or update your A record in Cloudflare

Once nameservers have propagated (Cloudflare will notify you), log back into Cloudflare and go to your domain's dashboard. Click the DNS tab on the left.

You should see the DNS records Cloudflare scanned earlier. Look for an A record with your domain name. If one exists and points to your VPS's IP address, you're done with this step. If it points to an old IP address, click the record, change the IP to your VPS's IP address, and save.

If there's no A record at all, click Add Record. Choose A from the dropdown. In the Name field, type @ (which means the root domain). In the IPv4 Address field, paste your VPS's IP address. Leave the TTL (time to live) at Auto. Click Save.

If you use www.example.com, create a second A record with the name www pointing to the same IP address, or create a CNAME record pointing www to your root domain.

Test that your domain reaches your VPS

Open a new browser tab and visit your domain (example.com or www.example.com). Your website should load. If it doesn't, wait another 15 minutes — DNS changes sometimes take longer to reach your location.

If your site still doesn't load, check two things. First, make sure your VPS's web server is running. Log into your VPS and restart Apache, Nginx, or whatever server you use. Second, check that the A record in Cloudflare matches your VPS's actual IP address — a typo here is the most common cause of failure.

You can also verify the setup by opening your browser's developer tools (F12 or right-click and choose Inspect), going to the Network tab, and reloading the page. Look at the response headers for any request — you should see a header that says cf-ray or mentions Cloudflare. This confirms traffic is flowing through Cloudflare.

Configure caching and security settings (optional but recommended)

Now that your domain works, you can turn on Cloudflare's features. In your Cloudflare dashboard, click the Caching tab. Set Cache Level to Cache Everything if you want Cloudflare to cache all your pages, or Standard if you want it to cache only static files like images and CSS. Most small sites benefit from Cache Everything.

Click the Security tab. Set Security Level to Medium or High — this blocks some suspicious traffic before it reaches your VPS. If you later notice legitimate visitors getting blocked, lower it back to Medium.

You can also enable Bot Fight Mode (free plan) to block automated attacks. These settings reduce the work your VPS has to do and protect against common attacks.

Troubleshooting common problems

Your site shows a Cloudflare error page instead of your website. This usually means Cloudflare can't reach your VPS. Check that your A record points to the correct IP address and that your VPS's web server is running. Restart the web server and wait a few minutes.

Email stops working after you switch to Cloudflare. Cloudflare scanned your MX records when you added your domain, so they should still be there. Check the DNS tab and confirm your MX records are present and unchanged. If they're missing, add them back manually.

Your site loads but very slowly. This usually means Cloudflare's cache isn't working. Go to the Caching tab and check that Cache Level is not set to Bypass. Also check that your VPS isn't sending cache-control headers that tell Cloudflare not to cache. If you're not sure, set Cache Level to Cache Everything and wait 10 minutes for pages to cache.

Nameservers still haven't propagated after 24 hours. This is rare. Check that you entered Cloudflare's nameservers exactly as shown — even a small typo will prevent propagation. If they're correct, contact your registrar's support to confirm the change went through.

Frequently Asked Questions

Do I have to use Cloudflare's nameservers, or can I use CNAME records instead?

You can use a CNAME record if your registrar supports it, but nameservers are simpler and more reliable. Some registrars don't allow CNAME records at the root domain, so nameservers are usually the better choice. If your registrar blocks nameserver changes, ask their support about CNAME setup.

Will Cloudflare slow down my site?

No — Cloudflare usually speeds up your site by caching pages and serving them from servers closer to your visitors. The only time it might add delay is if your VPS is very slow to respond, because Cloudflare has to wait for your server before it can cache the page. If that's the case, the problem is your VPS, not Cloudflare.

What if my VPS provider also offers DNS?

You can use either. If you switch to Cloudflare, you'll stop using your VPS provider's DNS. Your VPS itself still works the same way — only the DNS routing changes. Some people keep both for redundancy, but that's advanced and not necessary for most sites.

Can I use Cloudflare with a subdomain instead of my main domain?

Yes, but you'll need to use a CNAME record instead of changing nameservers. This is more complex and only necessary if you want to keep your main domain on a different DNS provider. For most setups, switching the whole domain to Cloudflare is simpler.

How do I remove Cloudflare if I change my mind?

Change your nameservers back to your registrar's or VPS provider's nameservers. Write down your DNS records from Cloudflare first so you can recreate them at your old DNS provider. Once nameservers propagate, you can delete your Cloudflare account.