
August 22, 2026
13 min read
By Kokil Thapa | Last reviewed: September 2026
A correct Cloudflare CDN setup turns a slow VPS into a fast global site. A sloppy one breaks logins, caches private data, or traps users in redirect loops. I have configured Cloudflare on production Laravel, WordPress, and custom PHP apps for clients in Nepal and abroad. Bandwidth is expensive here. Latency to overseas origins hurts conversion. This guide walks through the exact SSL, DNS, cache, and security settings that survive real traffic—not demo configs that fail on day one.
Before you proxy traffic, confirm your app understands reverse proxies. Laravel must trust forwarded headers. WordPress may need real IP plugins. My guide on Laravel API best practices covers backend trust configuration behind a CDN. Without it, rate limiting, geolocation, and audit logs see Cloudflare IPs—not your visitors.
How do you configure Cloudflare CDN setup and best practices for SSL and DNS?
Most Cloudflare migration outages I diagnose trace back to SSL mode or DNS proxy mistakes. Fix those first. Everything else builds on a clean foundation.
Selecting the correct SSL/TLS encryption mode
Cloudflare offers four encryption modes between the browser and your origin. Only one belongs on production in 2026.
- Off: Never use in production. Traffic between Cloudflare and origin travels in plain text.
- Flexible: Avoid. Cloudflare speaks HTTPS to users but HTTP to origin. Laravel, WordPress, and most frameworks force HTTPS and loop forever.
- Full: Encrypts end-to-end but skips certificate validation. Acceptable only with self-signed origin certs during temporary migration.
- Full (Strict): The production default. Requires a valid origin certificate matching your hostname. Use Let's Encrypt or a free Cloudflare Origin CA certificate.
On every Laravel and WordPress project I manage, I set Full (Strict) immediately after adding the zone. Pair it with a valid origin cert from Let's Encrypt and Certbot setup. That combination stops redirect loops and closes the gap between edge and origin.
DNS record configuration and proxy status
The orange cloud means proxied. The grey cloud means DNS only. Only HTTP and HTTPS belong behind the orange cloud.
FTP, SSH, SMTP, and database ports must stay grey. Cloudflare's proxy drops non-HTTP traffic. Mail delivery fails silently when MX or mail A records get proxied by mistake.
Type Name Content Proxy Status TTL
A @ 203.0.113.50 Proxied Auto
A www 203.0.113.50 Proxied Auto
A mail 203.0.113.50 DNS Only Auto
A ftp 203.0.113.50 DNS Only Auto
TXT @ v=spf1 include:_spf.google.com ~all Nepali businesses on shared VPS or local hosting gain two wins from proxying the main domain. DDoS absorption happens at the edge. Your origin IP stays hidden. When evaluating providers alongside CDN work, read cloud hosting services in Nepal and pricing to see which stacks integrate cleanly with Cloudflare. Our domain registration and hosting service often pairs Cloudflare with origin hardening from day one.
What cache rules prevent stale content in dynamic applications?
Caching is where Cloudflare setups fail for dynamic apps. Static assets cache fine. HTML with session cookies does not. One wrong rule serves guest pages to logged-in users or leaks CSRF tokens across sessions.
Configuring Cache Rules for Laravel and PHP applications
Cloudflare Cache Rules replaced legacy Page Rules for new zones in 2026. Build rules in priority order. Higher rules win.
- Bypass cache for authenticated users: Match cookies like
laravel_session,XSRF-TOKEN, orwordpress_logged_in_*. Set cache level to Bypass. - Bypass admin and API routes: Match URI paths
/admin/*,/api/*,/dashboard/*,/wp-admin/*. Set cache level to Bypass. - Cache static assets aggressively: Match extensions
.css,.js,.png,.jpg,.webp,.woff2,.svg. Set edge TTL to one month. - Cache public HTML cautiously: For marketing pages and blog posts on legal portals I maintain, set TTL to one hour. Enable Respect Origin Headers.
# Cache Rule 1: Bypass authenticated sessions
(http.cookie contains "laravel_session") or
(http.cookie contains "wordpress_logged_in") or
(http.cookie contains "XSRF-TOKEN")
# Action: Cache Level = Bypass
# Cache Rule 2: Aggressive static asset caching
(http.request.uri.path.extension in {"css" "js" "png" "jpg" "webp" "woff2" "svg"})
# Action: Edge Cache TTL = 1 month Test with two browser profiles before go-live. One logged in. One guest. Submit a form on each. Cached HTML with stale CSRF tokens is a common production bug I see on client projects.
Understanding Cache-Control header interactions
Cloudflare respects Cache-Control: private, no-store, and no-cache by default. Laravel sends no-cache, private on web routes by default. Edge rules cannot override that for HTML unless origin headers change.
// Laravel: opt-in caching for public blog post
return response($view)
->header('Cache-Control', 'public, max-age=3600')
->header('Vary', 'Accept-Encoding'); WordPress sites often use WP Rocket or Cloudflare's official plugin for header management. Custom Laravel builds need explicit middleware. On legal-tech portals with document uploads, I default every sensitive route to private, no-cache. Public pages opt in individually. See caching strategies for web performance for the broader picture beyond Cloudflare alone.
| Content Type | Recommended Edge TTL | Browser TTL | Purge Strategy |
|---|---|---|---|
| Static assets (CSS/JS/images) | 1 month | 1 month | Versioned filenames or purge on deploy |
| Public HTML (blog, landing pages) | 1 hour – 24 hours | 10 minutes | Purge via API or plugin on publish |
| Authenticated/user-specific pages | Bypass | Bypass | Not applicable |
| API JSON responses | Bypass or 1 minute | 0 seconds | Event-driven invalidation |
| Admin/dashboard routes | Bypass | Bypass | Not applicable |
After deploy, purge cached assets or use fingerprinted filenames from Vite 8.x builds. On a WooCommerce florist project like Petals Qatar flowers shop, product image cache invalidation must follow catalog updates. Otherwise shoppers see old prices.
How do you secure applications with Cloudflare WAF and bot management?
Performance gets attention. Security pays for itself faster on Nepali sites facing credential stuffing and scraper traffic. WAF rules block attacks before they hit your PHP-FPM pool.
Enabling and tuning Managed WAF rulesets
Enable Cloudflare Managed Rulesets on every production zone. Start in Log mode for two weeks. Review false positives. Then switch matched rules to Block or Challenge.
Common false positives on my client deployments include:
- Payment gateway callbacks from eSewa, Khalti, and ConnectIPS flagged as suspicious POST bodies
- Legal document upload endpoints triggering multipart inspection rules
- Third-party webhook receivers blocked by rate-limiting rules
Create WAF exceptions for known callback IP ranges. Do not disable OWASP rules globally. One exception on /payment/callback beats turning off SQL injection protection site-wide. Read fail2ban versus Cloudflare for DDoS protection to understand how edge and server layers complement each other.
Bot Fight Mode and rate limiting
Enable Bot Fight Mode on the free tier. It challenges low JavaScript-score requests. Scrapers and credential stuffers drop before reaching origin. For eCommerce checkout flows, Super Bot Fight Mode on Pro plans distinguishes verified bots from hostile automation.
On legal service portals I maintain, bot challenges cut spam form submissions noticeably. Watch the Managed Challenge pass rate in analytics. If more than two percent of legitimate users fail, widen your exception list.
Pair Cloudflare rate limiting with application-level throttling in Laravel. Edge limits protect origin CPU. App limits protect business logic. See how to secure your website and server in Nepal for the full stack beyond CDN settings alone.
Which performance optimizations deliver measurable speed improvements?
Cloudflare caching helps TTFB. Compression and protocol tuning help LCP. Both feed directly into Core Web Vitals optimization and search rankings.
Compression and protocol optimization
Enable Brotli compression under Speed → Optimization. Brotli beats gzip by 15–25% on text assets. Keep gzip as fallback for older clients.
Enable HTTP/3 (QUIC) and Early Hints (103). QUIC cuts connection setup time on mobile networks in Nepal where packet loss is common. Early Hints send preload Link headers while PHP still renders the page.
Image optimization and Polish
Product-heavy sites benefit from Cloudflare Polish on Pro plans. It converts JPEG and PNG to WebP or AVIF at the edge. Pair it with responsive <picture> tags in Blade or WordPress themes.
On budget builds, optimize images at build time with Vite 8.x or Sharp in Laravel. Let Cloudflare cache the pre-compressed output. You keep most of the gain without a Pro subscription. Our speed optimization service often combines origin image pipelines with edge caching for eCommerce clients.
Argo Smart Routing for international audiences
Nepali businesses serving diaspora customers in Australia, the US, or the Gulf benefit from Argo Smart Routing. Traffic rides Cloudflare's private backbone instead of congested public peering. Cost runs roughly $5/month plus per-GB usage—often Rs 700/month base, ~USD 5.
On international eCommerce like Nepal Gift Card, cross-border latency directly affects checkout completion. Argo is worth testing when analytics show high overseas bounce on slow LCP.
How do you troubleshoot common Cloudflare integration failures?
Even correct configs break under edge cases. These four problems account for most tickets I handle after a Cloudflare go-live.
Infinite redirect loops after enabling Cloudflare
SSL mode mismatch causes nearly every redirect loop. Laravel forces HTTPS via middleware. Cloudflare in Flexible mode connects to origin over HTTP. The app redirects to HTTPS. Cloudflare connects over HTTP again. The loop never ends.
Fix: Set SSL to Full (Strict). Install a valid origin certificate. Configure TrustProxies in Laravel:
// app/Http/Middleware/TrustProxies.php
protected $proxies = '*';
protected $headers = \Illuminate\Http\Request::HEADER_X_FORWARDED_FOR |
\Illuminate\Http\Request::HEADER_X_FORWARDED_HOST |
\Illuminate\Http\Request::HEADER_X_FORWARDED_PORT |
\Illuminate\Http\Request::HEADER_X_FORWARDED_PROTO |
\Illuminate\Http\Request::HEADER_X_FORWARDED_AWS_ELB; WordPress users should follow WordPress Cloudflare integration for speed. The same SSL and cookie rules apply.
Stale content served to authenticated users
Logged-in users seeing guest pages means cache bypass rules miss their cookies. Cloudflare string matching is case-sensitive. Verify exact cookie names in DevTools.
Disable any legacy "Cache Everything" Page Rule during testing. That rule ignores cookies unless you add explicit bypass conditions. Official Cloudflare cache documentation explains how edge TTL interacts with origin headers.
Origin server IP exposure despite proxying
Attackers who find your real IP bypass Cloudflare entirely. Lock ports 80 and 443 to Cloudflare published IP ranges only. Reject all other inbound HTTP traffic with UFW. See UFW firewall rules for web servers for the exact allowlist commands.
Real client IP not reaching the application
Cloudflare sends the visitor IP in CF-Connecting-IP and X-Forwarded-For. Your web server must pass those headers to PHP-FPM. On Nginx, add the real IP module config documented in Laravel deployment on Ubuntu with Nginx. Apache needs RemoteIP module configuration.
Validate header parsing with a quick JSON payload test in our JSON formatter tool after logging a test request. Confirm the IP field matches your actual address—not a Cloudflare range.
For broader context on why CDN investment matters locally, read why every Nepali business should use CDN for speed. Align technical choices with market realities before you cut over DNS.
Key Takeaways
- Set SSL to Full (Strict) with a valid origin certificate before proxying any production traffic.
- Build Cache Rules that bypass sessions, admin paths, and API routes—then cache static assets for one month.
- Enable WAF managed rules in Log mode first; whitelist payment callbacks and webhooks before blocking.
- Turn on Brotli, HTTP/3, and Early Hints; optimize images at origin if Pro Polish is not in budget.
- Restrict origin ports 80/443 to Cloudflare IP ranges so attackers cannot bypass the edge.
- Purge cache or version assets on every deploy; test with logged-in and guest browser profiles.
People Also Ask
Is Cloudflare CDN free enough for a small business website?
Yes. The free plan includes CDN caching, Universal SSL, basic DDoS protection, and Bot Fight Mode. That covers most brochure sites and small WordPress shops. Upgrade when you need Polish image optimization, advanced WAF tuning, or SLA-backed support.
How long does Cloudflare CDN setup take?
DNS propagation takes up to 48 hours globally. Actual configuration—SSL, cache rules, WAF—takes one to three hours for a standard Laravel or WordPress site. Complex multi-domain setups with staging environments need a full day including testing.
Does Cloudflare work with shared hosting in Nepal?
Yes, as long as your host allows custom DNS and origin HTTPS. Point nameservers or individual A records to Cloudflare. Set SSL to Full (Strict). Some budget hosts block outbound ports or use shared IPs—verify compatibility before migrating production traffic.
Should I use Cloudflare or AWS CloudFront for a Laravel app?
Cloudflare suits most Laravel VPS deployments: simpler DNS, built-in WAF, and no S3 requirement. CloudFront pairs better with S3-hosted assets on AWS-native stacks. Compare approaches in AWS CloudFront CDN setup for Laravel assets if your infrastructure is already on AWS.
Ship Cloudflare CDN Setup That Survives Production Traffic
Effective Cloudflare CDN setup rests on three habits. Encrypt with Full (Strict). Cache selectively by authentication state and content type. Layer security from bot challenges through WAF to origin firewall rules. Treat Cloudflare as application architecture—not a checkbox after launch.
Test every change in staging first. Monitor analytics for WAF false positives. Document cache rules alongside your codebase. If you want an audit of an existing zone—or hands-on setup for Laravel, WordPress, or custom PHP—contact us for a production review. I also take direct enquiries via my contact page. For ongoing tuning, our SEO service and page speed optimization checklist cover the metrics side after CDN work is done.
Frequently Asked Questions
0 Comments
Leave a comment
Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

