How to Set Up Cloudflare Free CDN in Front of Your VPS (2026)
A cloudflare free cdn vps setup puts Cloudflare servers between your visitors and your VPS. Visitors connect to a nearby Cloudflare edge server, and that server fetches content from your VPS when it needs to. Static files get served from the edge, while dynamic pages still come from your origin, so a small VPS carries less load and distant visitors get faster responses.
What a Cloudflare Free CDN VPS Setup Actually Does
Cloudflare acts as a reverse proxy for your domain. A visitor request goes to Cloudflare first, which can serve cached files directly, filter out some junk traffic, and pass the rest to your VPS. Your VPS still runs the site, the database, and the application.
The free plan covers what most small sites need: CDN caching, a shared SSL certificate, basic DDoS protection, and a few firewall rules. Advanced firewall rules, image resizing, and detailed analytics sit on paid plans, and the free plan caps how many rules you can create.
Before You Start: What You Need on the VPS
Make sure the site already works when you reach the VPS directly. If the site returns errors on the origin, Cloudflare will only pass those errors along. You also need access to your domain registrar, because you will change the domain nameservers to Cloudflare.
Note your current DNS records first. If your domain uses email, write down the existing MX, TXT, and SPF records before you change anything, because a missed mail record is the most common way this migration breaks email. Your web server should already serve the site over HTTPS. A free Let’s Encrypt certificate on Nginx works fine as the origin certificate.
Step 1: Add Your Site and Point DNS to Cloudflare
Create a free Cloudflare account, click Add site, and enter your domain. Cloudflare scans your current DNS records and shows what it found. Check the Cloudflare DNS records against the list you wrote down earlier and add any missing ones now, especially mail records.
For each record that should go through the CDN, keep the orange cloud icon switched on, which means proxied. The A record for your root domain should point to your VPS public IP, and the A record for www should point to the same IP. Records that must stay direct, such as mail server hostnames, stay grey, meaning DNS only. Proxying a mail hostname breaks mail delivery. Cloudflare then gives you two nameservers to set at your registrar. DNS changes take minutes to a few hours to spread. Check progress by running dig NS yourdomain.com from your VPS.
Step 2: Set the SSL Mode to Full (Strict)
Once DNS points to Cloudflare, open SSL/TLS in the Cloudflare dashboard and set the encryption mode to Full (Strict). This mode encrypts the connection from the visitor to Cloudflare and from Cloudflare to your VPS, and it checks that your origin certificate is valid.
Do not leave the mode on Flexible. Flexible encrypts only the visitor-to-Cloudflare leg and talks plain HTTP to your VPS, which leaves the second half of the trip unprotected. It also causes redirect loops on sites that force HTTPS, because the origin sees plain HTTP and keeps redirecting. If you see a “too many redirects” error after switching to Cloudflare, check the SSL mode first. The Nginx redirect setup on your VPS should match this mode, with HTTPS enforced at the origin as well. Turn on Always Use HTTPS in the Edge Certificates section so HTTP requests get redirected to HTTPS at the edge.
Step 3: Set Cache Rules That Help Instead of Breaking Things
By default, Cloudflare caches static files such as images, CSS, and JavaScript, and it passes dynamic pages through to your origin. You can shape it with cache rules, which replace the older page rules on the free plan. On the free plan you get a limited number of cache rules, so keep them few and simple.
A useful first rule is to cache static assets longer. Create a cache rule that matches file extensions such as jpg, png, webp, css, js, woff2 and sets the edge cache TTL to a month. A second rule can bypass the cache for the admin area and login pages, for example by matching a URI path that contains /wp-admin/ or /wp-login.php and setting the cache to bypass. Never cache a logged-in dashboard or a checkout page, because one visitor could end up seeing another visitor’s page.
If you run WordPress, remember that Cloudflare caching and server-side caching are separate layers. A FastCGI cache in Nginx speeds up the origin, while Cloudflare caches at the edge. Purge both when you change content. For WordPress-specific Cloudflare settings, the guide to speeding up WordPress with Cloudflare covers the plugin and caching choices in more detail.
Step 4: Lock Down the Origin So Traffic Only Comes Through Cloudflare
Once the proxy works, anyone who knows your VPS IP can still reach the origin directly and skip Cloudflare entirely. The fix is to allow only Cloudflare IP ranges through your server firewall and block direct web traffic from everything else. Add those ranges to your firewall allow list for ports 80 and 443, then drop other traffic to those ports.
A second layer is Authenticated Origin Pulls, which makes your origin accept connections only from Cloudflare servers that present a client certificate. Turn it on in the Cloudflare dashboard under SSL/TLS, then configure Nginx or Apache to verify that certificate. This closes the gap that firewall rules leave when an attacker finds your origin IP through an old DNS record. If that setup feels like too much for now, the firewall allow list alone is a solid first step. Keep SSH open for your own IP or key-based access only while you edit firewall rules, or you can lock yourself out.
How to Verify the CDN Is Working
Start with a header check from your terminal:
curl -sI https://yourdomain.com | grep -i -E "cf-cache-status|server|cache-control"
Look for the cf-cache-status header. HIT means Cloudflare served the file from its edge cache. MISS means it fetched the file from your origin this time. DYNAMIC means Cloudflare passed the request through without caching. If the header is missing entirely, traffic is not going through the proxy, so check that the DNS record is still orange-clouded.
Next, run dig +short yourdomain.com and check that the returned IP belongs to Cloudflare, not your VPS. Then load the site in a browser and check that pages, images, and styles all load over HTTPS with no mixed-content warnings. Finally, visit your VPS IP directly in a browser. With the firewall rules in place, that direct visit should fail or time out, while the domain continues to work.
Free Plan Limits Worth Knowing Before You Rely on It
The free plan is generous, but it has edges. Cache rules, firewall rules, and page rules each have small limits, so a setup that needs dozens of rules will not fit. The free Web Application Firewall covers managed rulesets in a limited form, and custom firewall rules are capped at a small number. Bot Fight Mode is available on the free plan, but it can also challenge real visitors, so watch your logs after turning it on.
Large file uploads through the proxy have a size cap on the free plan, so if your site accepts big uploads, those requests may fail at the edge while direct uploads work. A CDN also hides your origin IP from casual visitors, but it does not make your server invisible. The origin IP can leak through old DNS history, outgoing mail headers, or a subdomain you forgot to proxy. Treat the CDN as a performance and filtering layer, not as a guarantee that nobody can find your server. The Cloudflare security settings guide explains the WAF, Bot Fight Mode, and SSL modes in more depth.
When the Free Plan Is Enough, and When It Is Not
For a personal blog, a small business site, or a side project on a single VPS, the free plan usually covers what matters: faster static delivery, a valid SSL certificate, and a layer of protection against casual abuse. Most small WordPress sites never outgrow it.
Consider a paid plan when you need more control, such as more firewall and cache rules, image optimization, longer analytics retention, or support that answers quickly when something breaks. A store that takes payments or a site that gets targeted attacks regularly will also benefit from the stronger WAF and rate limiting on paid plans. Check the official pricing page before you decide, because plan features and limits change over time. Set up the free plan the way this guide describes, with Full (Strict) SSL, a few clear cache rules, and an origin that only trusts Cloudflare, and you have a setup that is fast, encrypted end to end, and easy to reason about.