Cloudflare is one of the most popular ways to put a CDN and a security layer in front of a website, and its free plan is generous enough for most small sites. Setup only takes a few minutes. Getting it set up correctly, so you don't break your email, your SSL or your admin area, takes a little more care.
This step-by-step guide walks you through setting up Cloudflare for a small website, along with the settings that matter and the mistakes to avoid.
What Cloudflare does for a small site
When you put Cloudflare in front of your site, visitors connect to Cloudflare first, and Cloudflare connects to your hosting server (the "origin"). That lets it:
- Cache static files at locations around the world, so they load faster for distant visitors. See what a CDN is for the basics.
- Hide your server's IP address from casual lookups for proxied records.
- Absorb attacks and junk traffic before it reaches your server. Our guide on DDoS attacks explains why that matters.
- Provide HTTPS at the edge, along with modern protocols like HTTP/3 and Brotli compression.
- Run your DNS on a fast, reliable network.
Before you start
Have these ready:
- Access to your domain registrar, where you will change nameservers.
- A list of your current DNS records, especially email records (MX, SPF, DKIM, DMARC). Take a screenshot or export them from your hosting control panel.
- A working SSL certificate on your hosting, such as a free AutoSSL or Let's Encrypt certificate. This is important for the SSL step later.
- A recent backup, just in case.
If DNS terms are fuzzy, our explainers on DNS records and nameservers vs DNS records will help.
Step 1: Create an account and add your site
Sign up at cloudflare.com, choose to add a site (sometimes labeled "add a domain"), and enter your root domain, for example example.com, not www.example.com. Choose the Free plan.
Step 2: Review the imported DNS records carefully
Cloudflare scans your existing DNS and imports what it finds. Don't just click Continue. Scans can miss records, especially email-related TXT records and subdomains you set up long ago.
Compare the list with the records you saved earlier and add anything missing. Pay particular attention to:
- A / AAAA records for the root domain and
www - MX records for email
- TXT records for SPF, DKIM, DMARC and domain verifications
- CNAME records for subdomains and third-party services
Step 3: Decide which records are proxied
Each record has a cloud icon:
- Orange cloud (Proxied): traffic goes through Cloudflare. Use this for your website records (root domain and
www). - Grey cloud (DNS only): Cloudflare just answers the DNS lookup; traffic goes straight to the server.
Set these to DNS only:
- Mail-related hostnames such as
mail.example.com, and anything your MX records point to. Cloudflare's standard proxy handles web traffic, not email. - Hostnames used for FTP, SSH or other non-web services.
- Control panel hostnames such as
cpanel.example.comif you connect to them on non-standard ports. Cloudflare only proxies a specific list of ports.
Getting this step right is what keeps your email working.
Step 4: Change your nameservers
Cloudflare gives you two nameservers, with names like something.ns.cloudflare.com. Log in to your domain registrar, find the nameserver settings for your domain, and replace the existing nameservers with Cloudflare's.
Changes usually take effect within a few hours but can take longer. Our guide to DNS propagation explains why. Cloudflare will email you when the site is active.
Step 5: Set the right SSL/TLS mode
This is the setting that causes the most trouble. Under SSL/TLS, Cloudflare offers several modes:
- Off: no HTTPS. Don't use this.
- Flexible: HTTPS between visitor and Cloudflare, but plain HTTP between Cloudflare and your server. This often causes "too many redirects" loops when your site also forces HTTPS, and it leaves part of the journey unencrypted.
- Full: HTTPS all the way, but Cloudflare doesn't validate your server's certificate.
- Full (strict): HTTPS all the way, with a valid certificate on your server. This is the one you want.
If your hosting already has a valid certificate, choose Full (strict). If you can't get a publicly trusted certificate on your server, Cloudflare offers free "Origin Certificates" you can install there, which work with Full (strict).
Also turn on Always Use HTTPS so visitors are redirected to the secure version.
Step 6: Speed settings worth checking
The defaults are reasonable, but take a look at:
- Caching level and browser cache TTL: the standard settings cache static files like images, CSS and JavaScript. Leave HTML uncached unless you know what you're doing.
- Brotli compression: applied automatically to compatible responses.
- HTTP/3: enable it under Network if it isn't on already. See HTTP/2 vs HTTP/3 for why it helps.
Avoid stacking features that do the same job. If your WordPress cache plugin already minifies CSS and JavaScript, you don't need another layer doing it too.
Step 7: Protect WordPress admin pages from caching
If you later add cache rules that cache HTML, always exclude:
/wp-admin/*and/wp-login.php- Cart, checkout and account pages for WooCommerce
- Any page that shows logged-in or personalized content
Caching these can show one user's content to another or break logins. With default settings, Cloudflare doesn't cache HTML, so this mainly matters once you start customizing.
Step 8: Test everything
Once the site is active:
- Load your site on HTTPS and check for the padlock.
- Log in to the WordPress admin and make a test edit.
- Send and receive a test email to and from your domain.
- Submit your contact form.
- Check response headers for
cf-cache-statusto confirm Cloudflare is serving static files (HIT means served from cache).
Common problems and fixes
"Too many redirects": almost always Flexible SSL mode plus a server-side HTTPS redirect. Switch to Full (strict).
Email stopped working: an MX target or mail hostname is proxied (orange) or a record was missed during import. Set mail records to DNS only and compare with your old records.
Changes don't show: purge the Cloudflare cache under Caching > Configuration, and clear your site's own cache plugin.
Error 521 or 522: Cloudflare can't reach your server. The server may be down, or a firewall may be blocking Cloudflare's IP ranges.
Visitor IPs all look like Cloudflare: your server needs to read the real visitor IP from Cloudflare's headers. Many hosts and server modules handle this automatically; on your own server you'll need to configure it.
Wrapping up
Cloudflare can make a small website faster and more resilient for free, as long as you set it up thoughtfully. Check every imported DNS record, keep mail records grey-clouded, use Full (strict) SSL, and test email and logins after the switch. Do that, and you get a global CDN and a security layer without breaking anything along the way.