Cloudflare explained: CDN, DNS and DDoS protection

What Cloudflare does in front of your site, which settings matter, and the gotchas that cause redirect loops and broken pages.

A cream cloud above a low wall of terracotta bricks

Cloudflare is a network that sits between your visitors and your server. Depending on your settings, it answers DNS queries for your domain, caches static files close to visitors, absorbs attack traffic and filters malicious requests.

This guide is for anyone adding a domain to Cloudflare who wants to understand what each setting changes. By the end you will know the orange and grey cloud, which SSL mode to pick and why, how caching works, and how to avoid redirect loops and exposing your server.

Cloudflare offers a free plan that covers DNS, the proxy and CDN, automatic edge certificates and DDoS mitigation, with a smaller set of firewall and rule features than its paid plans. Plans and limits change, so check Cloudflare's own plans page for current details.

What Cloudflare does

Cloudflare combines several services that are easy to confuse:

  • Authoritative DNS. When your domain's nameservers point to Cloudflare, it answers lookups for your records.
  • Reverse proxy and CDN. For records you proxy, visitors connect to Cloudflare's edge servers instead of your server. Cloudflare fetches content from your server (the origin) and can cache it.
  • DDoS mitigation. Because traffic passes through Cloudflare's network first, large floods of traffic can be absorbed there instead of overwhelming your origin.
  • Web application firewall (WAF). Rules inspect requests and block or challenge suspicious ones, such as known exploit attempts.
  • TLS at the edge. Cloudflare issues and serves the HTTPS certificate visitors see for proxied hostnames.
Visitor traffic passes through Cloudflare's edge cache, WAF and DDoS protection before reaching the origin server
With the proxy on, visitors talk to Cloudflare and Cloudflare talks to your origin

Orange cloud vs grey cloud

Every A, AAAA and CNAME record in Cloudflare has a proxy status:

StatusIconWhat happens
ProxiedOrange cloudDNS returns Cloudflare's IP addresses. Traffic goes through Cloudflare, so caching, WAF and DDoS protection apply.
DNS onlyGrey cloudDNS returns your real IP address. Visitors connect straight to your server, and Cloudflare is only the DNS provider.

Proxying only works for HTTP and HTTPS traffic on supported ports. Anything else, such as mail servers, SSH or database connections, must use DNS only. MX records themselves are never proxied, and the hostname they point to must be DNS only.

SSL modes: Flexible, Full and Full (strict)

The SSL/TLS encryption mode controls how Cloudflare connects to your origin. Visitors always see HTTPS from Cloudflare; the mode decides what happens on the second leg.

ModeVisitor to CloudflareCloudflare to originOrigin certificate checked
FlexibleHTTPSHTTP (unencrypted)No
FullHTTPSHTTPSNo, any certificate is accepted
Full (strict)HTTPSHTTPSYes, must be valid for the hostname

Use Full (strict) whenever your origin has a valid certificate. It is the only mode where traffic is encrypted end to end and Cloudflare verifies it is talking to your real server. A valid certificate can come from a public authority such as Let's Encrypt, from your host, or from Cloudflare's free Origin CA (which only Cloudflare trusts, so it suits proxied records only).

Avoid Flexible. It has two problems:

  • The connection between Cloudflare and your server is plain HTTP, so the padlock visitors see is misleading.
  • It causes redirect loops. If your app or server redirects HTTP to HTTPS (most do), Cloudflare requests the page over HTTP, gets told to use HTTPS, passes that redirect to the browser, which asks Cloudflare again over HTTPS, and Cloudflare again fetches over HTTP. The browser gives up with "too many redirects".

Full encrypts the connection but accepts a self-signed or expired certificate, so it doesn't protect against someone impersonating your origin. Treat it as a temporary step towards Full (strict).

Caching: static assets vs HTML

By default Cloudflare caches responses for common static file types such as images, CSS, JavaScript and fonts. It does not cache HTML by default, because pages often differ per visitor (logged-in users, shopping baskets, personalised content).

You can check what happened to a request with the cf-cache-status response header:

Terminal
curl -sI https://www.example.com/styles.css | grep -i -E "^(server|cf-cache-status|cache-control)"

HIT means it came from Cloudflare's cache, MISS means Cloudflare fetched it from the origin, and DYNAMIC means it was not eligible for caching.

Some rules of thumb:

  • Give static files long cache lifetimes and change their file names when they change (most build tools add a content hash, such as app.3f9a1c.js).
  • Cache HTML only for pages that are the same for everyone, and exclude admin, account, checkout and API paths.

Purging the cache

After a deploy that changes files without changing their names, visitors may still see the old version. In the Cloudflare dashboard, open your domain's Caching section and use Purge Cache: purge by URL for a few files, or Purge Everything as a last resort. Purging everything sends the next wave of requests to your origin at once, so avoid it at peak times.

Page Rules are now Rules

Older guides tell you to create Page Rules. Cloudflare is replacing them with more specific Rules: Cache Rules (what to cache and for how long), Redirect Rules, Configuration Rules (turn features on or off for certain paths), Origin Rules and Transform Rules (change headers or URLs). For new setups, use the newer Rules.

DDoS protection and "Under Attack" mode

Network-level and HTTP DDoS mitigation are on automatically for proxied traffic. For an application-layer attack that is still getting through, I'm Under Attack mode (in your domain's security settings) shows every visitor a short browser check before letting them in.

Use it as an emergency switch, not a permanent setting: it can block mobile apps, API clients and payment webhooks.

Origin IP exposure

The proxy only protects your server if attackers don't know its real IP address. Common leaks:

  • Old DNS records. Before you moved to Cloudflare, your IP was public. DNS history services keep it.
  • Grey-cloud records on the same server, such as direct.example.com, ftp.example.com or a staging subdomain.
  • Mail on the same IP. If your MX record points to mail.example.com and that resolves to the web server's IP, the address is visible to anyone.
  • Outgoing email headers sent directly from the web server.

To reduce the risk, host mail with a separate provider, remove or proxy records that point at the origin, and, if you control the server firewall, accept web traffic only from Cloudflare's published IP ranges. If the IP has already leaked and you are being attacked, changing it is often the only clean fix.

Step by step: putting a site behind Cloudflare

  1. Add your domain in Cloudflare. It scans and imports your existing DNS records.
  2. Compare the imported records with your current ones and add anything missing, especially MX, TXT (SPF, DKIM, DMARC) and verification records.
  3. Set each record's proxy status. Proxy the website hostnames; keep mail and non-web services DNS only.
  4. Change the nameservers at your registrar to the two Cloudflare gives you. For a domain registered with RemoteGeeks, see Manage a domain.
  5. Under SSL/TLS, choose Full (strict) and turn on Always Use HTTPS.
  6. Test the site, then check cf-cache-status on a static file and on a page.
  7. Add Cache Rules or Configuration Rules only once the basics work.
DNS
; Example records: web proxied, mail DNS only
example.com.        300  IN  A      203.0.113.10
www.example.com.    300  IN  CNAME  example.com.
mail.example.com.   300  IN  A      198.51.100.25
example.com.        300  IN  MX     10 mail.example.com.

In this example example.com and www would be proxied, and mail would stay DNS only on a different IP from the web server.

Using Cloudflare with RemoteGeeks

If your domain's DNS is on Cloudflare, you can connect your Cloudflare account to RemoteGeeks and edit the domain's A, AAAA, CNAME, MX and TXT records from the domain's page in the RemoteGeeks dashboard. The DNS records for Premium Email and Google Workspace are then added for you automatically.

Common mistakes

  • Choosing Flexible SSL. Fix: install a valid certificate on the origin and switch to Full (strict).
  • Proxying the mail hostname. Fix: set the record your MX points to as DNS only.
  • Leaving Under Attack mode on. Fix: turn it off once the attack ends, or exempt API and webhook paths.
  • Caching HTML that contains personal data. Fix: exclude logged-in, account and checkout paths, or bypass cache when a session cookie is present.
  • Forgetting Email Address Obfuscation. This feature rewrites email addresses in your HTML and adds a script to decode them. It can break JavaScript frameworks that hydrate server-rendered pages (React, Next.js, Vue), causing hydration errors or mangled text. Fix: turn it off under the Scrape Shield settings, or with a Configuration Rule for affected paths. Script-rewriting features such as Rocket Loader can cause similar problems.

Security notes

  • Use Full (strict) so traffic is encrypted and verified all the way to your origin.
  • Protect your Cloudflare account with two-factor authentication. Whoever controls it controls your DNS.
  • When creating API tokens for tools, scope them to the specific zone and permissions needed rather than using the global API key.
  • Cloudflare in front of your site does not patch your application. Keep doing the basics in Protect your website from malware and vulnerabilities.

Troubleshooting

SymptomCauseFix
"Too many redirects"Flexible SSL with an origin that redirects to HTTPSSwitch to Full (strict)
Error 526Full (strict) but the origin certificate is invalid or missingInstall a valid certificate, then retry
Error 521 or 522Cloudflare can't connect to the originCheck the origin is up and its firewall allows Cloudflare
Error 524Origin took too long to respond (100 seconds by default)Speed up the request or move slow work to a background job
Old content after deployCached copy at the edgePurge the changed URLs
Custom domain check fails on LaunchpadRecord is proxiedSet it to DNS only until HTTPS is active

Frequently asked questions

Do I need Cloudflare if my host already provides HTTPS?

No. It adds caching, a WAF and DDoS absorption, which matter most for busy or frequently targeted sites. Many small sites run well without it.

Can I use Cloudflare DNS without the proxy?

Yes. Set every record to DNS only and Cloudflare acts purely as your DNS provider.

Will Cloudflare make my dynamic app faster?

Static files load faster from nearby edge servers. Dynamic pages still come from your origin, so application speed still matters.

Does Cloudflare hide my server's IP completely?

Only for proxied records, and only if the IP hasn't leaked another way, such as through old DNS records or mail on the same server.

Next steps

Start simple: DNS on Cloudflare, website hostnames proxied, Full (strict) SSL and default caching. Add rules only when you have a specific reason.

Share this articleLinkedIn (opens in a new tab)X (opens in a new tab)Facebook (opens in a new tab)
Was this article helpful?

Get new guides in your inbox.

One email a month. Unsubscribe anytime.