
Cloudflare sits between your visitors and your hosting server as a reverse proxy. Its free plan gives you a global CDN, free SSL, basic DDoS protection and firewall, and fast DNS. To set it up, add your site to Cloudflare, check that it imported every DNS record, change your domain's nameservers at the registrar, then configure SSL to Full (strict), turn on Always Use HTTPS, and set sensible caching and security rules. This guide walks through each step and the settings that most often break sites when they are wrong. This guide explains cloudflare setup step by step.
- Before switching nameservers, confirm every record, especially MX, SPF, DKIM and DMARC for email.
- Use SSL/TLS mode Full (strict). Flexible causes redirect loops and is not truly secure.
- Proxy (orange cloud) only web records; keep mail and verification records DNS-only (grey cloud).
- Do not cache admin, cart, checkout or account pages.
Cloudflare setup: how Cloudflare works
When you move your nameservers to Cloudflare, it answers DNS for your domain. For proxied records, it returns Cloudflare's IP addresses instead of your server's. Visitors connect to the nearest Cloudflare data centre, which serves cached files directly and forwards other requests to your server. Your origin IP stays hidden, which also helps against direct attacks.
Step 1: Add your site
- Create a free account at Cloudflare using a business email, with two-factor authentication on.
- Click Add a site, enter your root domain (for example
example.com) and choose the Free plan. - Cloudflare scans your existing DNS records.
Step 2: Check every DNS record
The scan often misses records. Compare carefully with your current DNS (screenshot it at your registrar or host first):
| Record | Proxy status |
|---|---|
A @ and CNAME www (website) | Proxied (orange) |
| MX records | DNS only (MX cannot be proxied) |
A/CNAME for mail, webmail, ftp, cpanel | DNS only (grey) |
| TXT: SPF, DKIM, DMARC, verification | Not proxied (TXT is never proxied) |
| Subdomains for third-party services (Shopify, email marketing) | Usually DNS only; follow the service's instructions |
Our DNS records guide explains each type.
Step 3: Change nameservers at your registrar
Cloudflare gives you two nameservers such as ava.ns.cloudflare.com and tom.ns.cloudflare.com. Replace the existing nameservers with these at your domain registrar (for .pk domains, through your PKNIC registrar or reseller). Turn off DNSSEC at the registrar first if it is enabled; you can enable it again from Cloudflare later. Activation usually completes within a few hours.
Step 4: Set SSL/TLS correctly
| Mode | Visitor → Cloudflare | Cloudflare → server | Use? |
|---|---|---|---|
| Flexible | HTTPS | HTTP (unencrypted) | Avoid |
| Full | HTTPS | HTTPS, any certificate | Temporary only |
| Full (strict) | HTTPS | HTTPS, valid certificate | Recommended |
Your server needs a valid certificate for Full (strict): use your host's free Let's Encrypt SSL, or create a free Origin Certificate in Cloudflare and install it on the server. Then enable:
- Always Use HTTPS (SSL/TLS → Edge Certificates)
- Automatic HTTPS Rewrites, which fixes some mixed-content links
- Minimum TLS version 1.2
- HSTS only after everything works on HTTPS, including subdomains
Wrong SSL settings are the top cause of redirect loops after moving to Cloudflare.
Step 5: Speed settings
- Brotli compression is applied automatically on the edge. See our compression guide.
- Caching → Configuration: standard caching level; set Browser Cache TTL to "Respect existing headers" if your server sends good cache headers.
- Cache rules: by default Cloudflare caches static files (images, CSS, JS) but not HTML. To cache HTML for a mostly static site, add a cache rule, and exclude
/wp-admin/*,/wp-login.php,/cart*,/checkout*,/my-account*and any URL with a logged-in cookie. - Automatic Platform Optimization (APO) for WordPress is a paid add-on that caches HTML safely.
- Avoid Rocket Loader unless you have tested it; it can break scripts.
Step 6: Security settings
- Leave Bot Fight Mode off at first if you use payment gateway callbacks or APIs; it can block legitimate server-to-server requests.
- Add a WAF custom rule to challenge requests to
/wp-login.phpand/xmlrpc.phpfrom outside your country if your admins are only in Pakistan. - Use Security → Events to see what is blocked and why.
- Use Under Attack Mode only during an actual attack.
After setup: check these
- Website loads on HTTPS with www and non-www redirecting correctly.
- Send and receive a test email.
- Submit a contact form and, for stores, place a test order through the payment gateway.
- Purge the Cloudflare cache after site updates (Caching → Purge Everything, or by URL).
- If your server logs or security plugin show only Cloudflare IPs, enable real visitor IP restoration (mod_remoteip or the host's Cloudflare setting).
Cloudflare setup: frequently asked questions
Cloudflare setup: is the Cloudflare free plan enough?
For most small business sites, yes: CDN, SSL, DNS and basic protection are included.
Cloudflare setup: will Cloudflare make my site faster in Pakistan?
Usually, for images, CSS and JS, because they are served from nearby edge locations. HTML still comes from your server unless you cache it, so server speed still matters.
Cloudflare setup: can I use Cloudflare with Hostinger or cPanel hosting?
Yes. Some hosts also offer their own CDN; use one or the other for the same domain, not both stacked, unless you know how they interact.
Related guides: How to Set Up Google Analytics 4 (GA4), 404 Error and 403 Forbidden Error.
For official guidance, see Cloudflare developer documentation.
Want Cloudflare set up for you?
We configure Cloudflare DNS, SSL, caching and firewall rules without breaking email or checkout, as part of our hosting and speed optimization services. Contact us.
Written by the ItsWebExpert team, a web design and development company in Karachi building websites, online stores and apps for businesses across Pakistan.
Ask a Question on WhatsApp