How to Set Up Cloudflare With Your Hosting Without Breaking Your Site

To set up Cloudflare with your hosting, add your domain to a Cloudflare account, check that every DNS record was imported correctly, replace the nameservers at your domain registrar with the two Cloudflare gives you, then set SSL/TLS to Full (strict) and turn on Always Use HTTPS. Keep email records (MX targets, mail and webmail subdomains) as DNS only (grey cloud). The work takes about 30 minutes; the nameserver change usually completes within a few hours.
What the free plan does, and what it does not
Cloudflare sits between your visitors and your hosting server as a reverse proxy. On the free plan you get:
DNS hosting for your domain.
A CDN for static files: images, CSS, JavaScript and fonts are cached at locations near your visitors.
An edge SSL certificate for the connection between visitors and Cloudflare.
Network-level DDoS mitigation and basic security controls.
What it does not do:
It does not cache HTML by default. A slow, uncached WordPress page is still built by your server on every visit.
It does not proxy email. SMTP, IMAP and POP3 go straight to your mail server.
It does not replace backups, hosting resources or a fix for slow database queries.
It does not hide your server if the IP is still published elsewhere, for example in a mail record that points to the same server.
Before you start
Make sure you can log in to your domain registrar. You will change nameservers there.
Export or screenshot your current DNS records from cPanel Zone Editor or your current DNS provider, including TXT records for SPF, DKIM, DMARC and Google verification.
Confirm the site already works over HTTPS on your hosting. Free SSL included with your hosting is enough. You need a valid certificate on the server for Full (strict).
Turn off DNSSEC at the registrar if it is enabled. Changing nameservers while old DNSSEC records are still published can make the domain stop resolving. You can enable it again through Cloudflare afterwards.
Step by step: connect Cloudflare to your domain and hosting
1. Add the site
Create a Cloudflare account, choose to add a site, enter your root domain (without www) and pick the Free plan. Cloudflare scans your existing DNS and imports what it finds.
2. Review every DNS record
This is where most problems start. The scan often misses records, especially subdomains, DKIM keys and SRV records. Compare the imported list with your export and add anything missing. Then set the proxy status:
Proxied (orange cloud): the records that serve your website, usually the root (
@) andwww.DNS only (grey cloud):
mail,webmail,ftp,cpanel, anything used for SSH, and any hostname your MX records point to.
3. Change the nameservers at your registrar
Cloudflare shows two nameservers ending in ns.cloudflare.com. At your registrar, replace the current nameservers with exactly those two and remove any others. If your domain is registered with us, you can do this from the IM HOST domain management area. If you want to understand what changes when you switch nameservers versus editing A records, read our guide on connecting a domain to hosting with nameservers or an A record.
4. Wait for activation and verify
Cloudflare emails you when the zone is active. Nameserver changes often take effect within an hour, but as a rule of thumb allow up to 24 to 48 hours. Check from a terminal (replace example.com with your domain):
dig NS example.com +short
curl -sI https://example.com/ | grep -i -E "server|cf-cache-status|cf-ray"When the site is proxied, the response shows server: cloudflare and a cf-ray header.
5. Set SSL/TLS to Full (strict)
Cloudflare offers four modes. Only one is correct for a normal hosted site:
Off: no HTTPS. Never use it.
Flexible: visitors connect to Cloudflare over HTTPS, but Cloudflare talks to your server over plain HTTP. The browser shows a padlock while the second half of the trip is unencrypted. If your site also forces HTTPS (WordPress set to https, or an
.htaccessredirect), the result is an endless loop andERR_TOO_MANY_REDIRECTS.Full: encrypted to your server, but any certificate is accepted, even an expired or self-signed one.
Full (strict): encrypted and the server certificate must be valid. Use this.
Your hosting's free certificate works for Full (strict). You can also use a Cloudflare Origin Certificate, but browsers do not trust it directly, so if you ever turn the proxy off the site will show a security warning. For a company site where you want a certificate with organisation validation on the server itself, see our SSL certificate options.
6. Force HTTPS, carefully
Enable Always Use HTTPS and Automatic HTTPS Rewrites. Leave HSTS off until everything has worked for a few weeks. Browsers remember HSTS for the full max-age, so a mistake cannot be undone quickly.
Caching basics: what gets cached and how to check
By default Cloudflare caches static files by extension and passes HTML to your server. Check any response with curl -sI and look at cf-cache-status:
HIT: served from Cloudflare's cache.
MISS or EXPIRED: fetched from your server this time, cached for next time.
DYNAMIC: not eligible for caching, which is normal for HTML.
BYPASS: a rule or header told Cloudflare not to cache it.
Caching HTML at the edge can cut TTFB for distant visitors, but only do it if you can exclude wp-admin, cart, checkout, account pages and logged-in users. For most WordPress sites, the safer pattern is your host's page cache for HTML plus Cloudflare for static files. After a design change, purge the cache, or use Development Mode, which bypasses the cache for 3 hours. To measure the effect properly, follow our guide on how to test website speed with TTFB and PageSpeed, and for a wider view of edge caching for Arab audiences see CDN and edge caching for MENA audiences.
Getting the real visitor IP back
Once traffic is proxied, your server sees Cloudflare's IP addresses instead of visitors' IPs. That breaks rate limiting, security plugins, fail2ban and analytics based on server logs. Cloudflare sends the original address in the CF-Connecting-IP header.
On shared hosting, ask support whether real IP restoration is already configured on the server. On your own VPS with nginx, trust Cloudflare's published ranges and read that header. This builds the config from Cloudflare's official lists:
{ curl -s https://www.cloudflare.com/ips-v4; echo; curl -s https://www.cloudflare.com/ips-v6; echo; } \
| grep -v '^$' | sed 's/.*/set_real_ip_from &;/' \
| sudo tee /etc/nginx/conf.d/cloudflare-realip.conf
echo 'real_ip_header CF-Connecting-IP;' | sudo tee -a /etc/nginx/conf.d/cloudflare-realip.conf
sudo nginx -t && sudo systemctl reload nginxThe ranges change occasionally, so rerun it every few months. On Apache, the equivalent is mod_remoteip with RemoteIPHeader CF-Connecting-IP.
Email records must stay DNS only
Cloudflare does not proxy mail traffic. If the hostname your MX record points to (for example mail.example.com) is proxied, mail apps cannot connect and other servers may fail to deliver to you. Keep these grey: the MX target, mail, webmail, autodiscover and similar. Copy SPF, DKIM and DMARC TXT records character for character; one missing quote or a truncated DKIM key is enough to send your mail to spam.
Common breakages and how to fix them
ERR_TOO_MANY_REDIRECTS: SSL mode is Flexible while the server forces HTTPS. Switch to Full (strict).
Error 525 or 526: the SSL handshake with your server failed (525) or its certificate is invalid or expired (526). Fix or reissue the certificate on the hosting side.
Error 521 or 522: Cloudflare cannot reach your server. The server is down, or a firewall is blocking Cloudflare's IP ranges.
Error 524: your server took longer than 100 seconds to answer. Move long tasks out of web requests.
Email stopped after the switch: an MX target or mail subdomain is proxied, or a record was not imported.
A subdomain stopped working: its record was missed by the scan. Add it.
Changes to the site do not appear: purge the cache or enable Development Mode.
Menus, sliders or checkout scripts misbehave: turn off Rocket Loader and retest.
How to undo it
For a quick test, use Pause Cloudflare on Site in the dashboard, or set the web records to DNS only. Traffic then goes straight to your server while DNS stays at Cloudflare. To leave completely, recreate your DNS records at your previous DNS provider first, then change the nameservers back at the registrar. If you installed a Cloudflare Origin Certificate, put a publicly trusted certificate on the server before you turn the proxy off.
Frequently asked questions
Is the Cloudflare free plan enough for a small business website?
For most small business sites and blogs, yes. You get DNS, static file caching, an edge certificate and DDoS mitigation. Paid plans mainly add more advanced security rules, image optimisation and support.
Does Cloudflare make my website faster?
It speeds up static files for distant visitors and can reduce load on your server. It does not make uncached pages build faster. If your TTFB is slow because of the server or database, fix that first.
Do I still need an SSL certificate on my hosting?
Yes. Cloudflare's certificate covers the visitor-to-Cloudflare connection. For Full (strict), your server also needs a valid certificate. The free SSL included with your hosting is enough.
Can I use Cloudflare without changing my nameservers?
On the free plan, no. The full setup with Cloudflare nameservers is required. Setups that keep your existing DNS provider are limited to higher paid plans.
If you are setting up a new domain or want DNS and nameservers in one place, start with IM HOST domain names, which include free DNS management and domain lock. Our engineers can check your records with you 24/7 before you switch.
More from our blog
Discover more practical guides and product insights from the IM Host team.
View all articles