Skip to content

How to Connect a CDN to Your Site

Key idea:

CDN (Content Delivery Network) — geographically distributed servers serving static content from the node closest to the user. For a standard site setup takes 30 min: register at Cloudflare (free), switch DNS, enable proxy, set cache rules. For RU — Yandex Cloud CDN (DC in Moscow).

Below: step-by-step, working examples, common pitfalls, FAQ.

Step-by-Step Setup

  1. Register at CDN (Cloudflare free)
  2. In dashboard add the domain → import existing DNS records
  3. At the registrar switch nameservers to Cloudflare (craig.ns.cloudflare.com, etc.)
  4. Wait for propagation (1-24 h). Enterno DNS checker shows when done
  5. In Cloudflare enable: "Proxy" (orange cloud) on A records for edge caching
  6. SSL/TLS mode: Full (strict) — if origin has cert. Full (not strict) — if self-signed.
  7. Cache rules: Static Files → Cache Everything, TTL 1 year
  8. Verify: curl -I https://example.com | grep -i "cf-cache-status" → "HIT"

Working Examples

ScenarioConfig
Cloudflare Page Rule for cacheURL: example.com/static/* → Cache Everything + Edge Cache TTL: 1 year + Browser Cache TTL: 1 year
AWS CloudFront distributionOrigin: your-bucket.s3.amazonaws.com Alternate Domain Names (CNAMEs): cdn.example.com Default Cache Behavior: Redirect HTTP to HTTPS + Cache based on Host header
Yandex Cloud CDNCreate CDN resource → Primary origin: origin.example.com Edge locations: Moscow + Saint-Petersburg SSL: Let's Encrypt or custom cert
nginx origin behind CDNreal_ip_header CF-Connecting-IP; set_real_ip_from 173.245.48.0/20; # Cloudflare IP ranges
Cache bust via query paramhttps://example.com/style.css?v=1776446434 # filemtime hash auto-bust

Common Pitfalls

  • Cloudflare SSL "Flexible" + HTTPS redirect in PHP = redirect loop
  • Cache rules on dynamic endpoints (/api/*, /admin/*) — serves stale data to everyone
  • Origin sees client IP as Cloudflare → all logs = 173.245.x.x. Fix: real_ip_header CF-Connecting-IP.
  • CDN caches Set-Cookie headers — users see each other's sessions. Bypass cache for /api.
  • Redirect chain longer (www → non-www → HTTPS → CDN) — LCP degrades. Consolidate.

Learn more

Frequently Asked Questions

Cloudflare or Yandex Cloud CDN?

Cloudflare: global coverage, free, but not every Russian ISP routes optimally. Yandex: tier-1 RU coverage + compliance, paid from 0.5₽/GB.

How much does CDN speed up the site?

International client TTFB: 300-800ms → 50-150ms. LCP: 10-40% improvement depending on content.

How to purge CDN cache?

Cloudflare: Dashboard → Caching → Purge Cache (all or by URL). AWS: Invalidation in CloudFront console. Yandex: Prefetch/Purge API.

Does a CDN help SEO?

Yes. Google uses TTFB + Core Web Vitals. Fast CDN → better CWV → +10-20% visibility.