Setting Up Your First CDN: A Hands-On Tutorial

· Mei-Lin Wu · 9 min read

Setting up a CDN involves pointing your domain to a distributed network of edge servers that cache and deliver your content from locations close to your visitors. This tutorial walks through the complete process using Cloudflare as the primary example, then provides parallel instructions for AWS CloudFront and Bunny CDN. If you are new to CDN technology, start with our guide on how CDNs work before diving into configuration.

What Do You Need Before Setting Up a CDN?

Before starting, gather these prerequisites: For foundational context, read What Is a CDN? The Complete Beginner's Guide — FlyFish NWA.

How Do You Set Up Cloudflare CDN Step by Step?

Cloudflare is the most popular CDN for first-time users because it offers a generous free tier, a straightforward setup wizard, and built-in DDoS protection. The entire process takes 15-30 minutes plus DNS propagation time.

Performance Comparison: Edge vs Origin Processing
Metric Edge Processing Origin Processing Improvement
Latency (p50)8–15 ms120–300 ms15–20x faster
Cache Hit Ratio85–95%N/AReduces origin load
TLS Handshake1–5 ms (nearby PoP)50–150 ms10–30x faster
Bandwidth Cost$0.01–0.04/GB$0.05–0.12/GB3–5x cheaper
Availability99.99% (multi-PoP)99.9% (single DC)10x fewer outages
CDN Network Overview — Understanding the delivery architectureCDN Network Overview — Understanding the delivery architecture CDN Network Topology — Content Delivery Flow U User A Tokyo U User B London U User C New York Edge Server Tokyo PoP Edge Server London PoP Edge Server New York PoP Mid-Tier Cache Origin Shield Origin Server Your Server Request Cache Miss Fetch Cache Hit → Instant Response
Figure 1: CDN Network Overview — Understanding the delivery architecture

Step 1: Create an Account and Add Your Domain

Sign up at cloudflare.com and click "Add a Site." Enter your domain name (example.com, not www.example.com). Cloudflare automatically scans your existing DNS records and imports them. Select the Free plan to start. Verify the imported DNS records match your current configuration, paying special attention to MX records for email delivery.

Step 2: Change Your Nameservers

Cloudflare assigns two nameservers (e.g., ada.ns.cloudflare.com and bob.ns.cloudflare.com). Log in to your domain registrar and replace the existing nameservers with the Cloudflare pair. This step is critical because it routes all DNS resolution through Cloudflare, enabling the CDN proxy layer. Propagation typically takes 1-4 hours but can take up to 48 hours.

Step 3: Configure SSL/TLS

Navigate to SSL/TLS settings and choose the appropriate encryption mode:

ModeOrigin SSL RequiredSecurity LevelBest For
FlexibleNoBasicSites without origin SSL (temporary only)
FullSelf-signed OKGoodDevelopment environments
Full (Strict)Valid certificateBestProduction websites (recommended)

Always aim for Full (Strict) mode in production. Enable "Always Use HTTPS" and "Automatic HTTPS Rewrites" to eliminate mixed content issues.

Step 4: Set Up Cache Rules

The default Cloudflare configuration caches static assets (images, CSS, JS, fonts) but passes HTML through to the origin. For most websites, this default is a solid starting point. Customize caching behavior using cache-control headers from your origin server or Cloudflare Cache Rules:

Step 5: Enable Performance Settings

Under the Speed section, enable these features: Auto Minify for CSS, JavaScript, and HTML; Brotli compression; Early Hints (103 status code); and HTTP/2 prioritization. These settings improve delivery speed beyond basic caching. Refer to the Cloudflare architecture deep dive for advanced tuning options.

How Do You Set Up AWS CloudFront as an Alternative?

AWS CloudFront is the CDN of choice for applications already running on AWS infrastructure. The setup is more involved than Cloudflare but integrates deeply with S3, EC2, and Lambda@Edge.

Distribution Configuration

  1. Open the CloudFront console and click "Create Distribution."
  2. Set the origin domain to your server hostname or S3 bucket endpoint.
  3. Configure the origin protocol policy to "HTTPS Only" if your origin supports SSL.
  4. Set the viewer protocol policy to "Redirect HTTP to HTTPS."
  5. Add your custom domain as an alternate domain name (CNAME).
  6. Request or import an SSL certificate through AWS Certificate Manager (ACM). The certificate must be in the us-east-1 region.
  7. Configure the default cache behavior with TTL values matching your content update frequency.

DNS Configuration

Unlike Cloudflare, CloudFront uses a CNAME approach. Create a CNAME record at your DNS provider pointing your domain to the CloudFront distribution domain (e.g., d1234abcdef.cloudfront.net). If using Route 53, create an alias record instead, which supports the zone apex (example.com without www).

How Do You Set Up Bunny CDN as a Budget-Friendly Option?

Bunny CDN offers the simplest setup with transparent per-GB pricing and no bandwidth commitments:

Request Lifecycle — How content moves through the CDNRequest Lifecycle — How content moves through the CDN CDN Request Flow — From Browser to Edge CDN Request Lifecycle Step 1 DNS Lookup Step 2 TCP Connect Step 3 TLS Handshake Step 4 Edge Server Step 5 Cache Check Step 6 Response Cache HIT → 5ms response Cache MISS → Fetch origin 0ms ~50ms (cache hit) ~200ms (cache miss)
Figure 2: Request Lifecycle — How content moves through the CDN
  1. Create a Pull Zone with your origin URL (e.g., https://origin.example.com).
  2. Test the default CDN URL (yourzone.b-cdn.net) to verify content delivery.
  3. Add a custom hostname under the Pull Zone settings.
  4. Create a CNAME record at your DNS provider pointing to yourzone.b-cdn.net.
  5. Enable the free SSL certificate for your custom hostname.
  6. Configure cache expiration and Vary headers for proper content negotiation.

Bunny CDN starts at approximately 0.01 per GB for North American and European traffic, making it cost-effective for bandwidth-heavy sites delivering images, video, or software downloads.

How Do You Verify Your CDN Is Working?

After DNS propagation completes, verify CDN functionality through three methods:

Method 1: Response Header Inspection

Open your browser developer tools (F12), navigate to your site, and inspect the response headers of a static asset. Look for these CDN-specific headers:

CDN ProviderCache Status HeaderHIT ValueMISS Value
CloudflareCF-Cache-StatusHITMISS (first request)
CloudFrontX-CacheHit from cloudfrontMiss from cloudfront
Bunny CDNCDN-CacheHITMISS

Request the same asset twice. The first request should show MISS (fetched from origin), and the second should show HIT (served from edge cache).

Method 2: Multi-Location Performance Testing

Use tools like KeyCDN Performance Test, Dotcom-Tools, or Pingdom to measure TTFB from servers worldwide. Before CDN activation, distant locations might show 300-800ms TTFB. After CDN activation, all locations should show under 100ms for cached content.

Method 3: Google PageSpeed Comparison

Run Google PageSpeed Insights before and after CDN setup. Compare Largest Contentful Paint (LCP), First Contentful Paint (FCP), and Time to First Byte (TTFB) metrics. Expect measurable improvements in all three, directly impacting your Core Web Vitals scores.

What Are the Most Common CDN Setup Mistakes?

After helping hundreds of teams configure their first CDN, these mistakes appear repeatedly:

What Should You Do After Your CDN Is Running?

Once the basic setup is verified, take these next steps to maximize CDN value:

  1. Monitor cache hit ratio — Aim for 85%+ for static-heavy sites. Check your CDN analytics dashboard weekly during the first month.
  2. Enable WAF rules — Activate the web application firewall to block common attack patterns (SQL injection, XSS, directory traversal).
  3. Configure page-specific rules — Create rules that bypass cache for admin pages, API endpoints, and checkout flows.
  4. Set up monitoring alerts — Configure alerts for cache hit ratio drops, origin error spikes, and certificate expiration warnings.
  5. Document your configuration — Record all custom rules, DNS changes, and SSL settings for your team. CDN configurations are notoriously difficult to audit months later.

With a properly configured CDN in place, you can explore advanced optimization techniques including image optimization, HTTP/3 and QUIC protocols, and edge computing capabilities that transform your CDN from a simple cache into a powerful application delivery platform.

External References

References & Standards: RFC 7234 · HTTP/2 specification