What a CDN Does and Why It Matters for Business Websites
A content delivery network caches your site assets on servers distributed across multiple geographic locations. When a visitor loads your website, the CDN serves content from the nearest edge location rather than routing every request back to your origin server. This reduces latency, decreases time to first byte, and can improve Core Web Vitals scores in Google Search Console.
For business websites with an international audience, the performance improvement is often significant. Visitors in Australia fetching assets from a server in London experience noticeable delay. A CDN removes that bottleneck by serving cached copies from a location closer to them. For sites with a predominantly UK or European audience, the benefit is more modest because most visitors are already geographically close to the origin server.
Beyond performance, CDNs offer practical security and operational benefits. Most providers include DDoS mitigation, which can absorb malicious traffic before it reaches your server. They reduce origin server load during traffic spikes, which means your site stays online during unexpected surges. Some providers add automatic image optimisation, converting images to modern formats and resizing them based on the visitor's device.
When a CDN Is Worth the Cost for a Business Website
Most small business websites in the United Kingdom with primarily local or regional traffic do not need a CDN. The performance gain from adding a CDN in this scenario is typically under 100 milliseconds. That difference is imperceptible to most visitors and unlikely to move the needle on search rankings or conversion rates.
A CDN becomes genuinely worthwhile in specific situations:
- International audience: If more than 20-30% of your visitors come from outside Europe, a CDN meaningfully reduces load times for those users.
- Large files: Video content, software downloads, PDF libraries, or image-heavy portfolios benefit substantially from edge caching.
- Underpowered origin servers: If your current server maxes out on bandwidth during traffic spikes, offloading static asset delivery to a CDN reduces the load on your origin.
- Security requirements: DDoS protection built into most CDN services provides a first line of defence without additional configuration.
Before paying for a CDN plan, it is worth checking whether your hosting provider already includes CDN functionality. Some managed WordPress hosts, cloud hosting platforms, and enterprise-level providers bundle CDN access with their standard plans.
DNS Configuration for CDN Integration
Setting up a CDN requires changes at the DNS level. The exact process varies by provider, but the general principle is the same: point your public DNS records to the CDN provider's infrastructure instead of directly to your server.
For most business websites, you will update your DNS A record or CNAME record to point to the CDN provider's anycast address. The CDN then routes requests through its edge nodes. Your web server configuration stays largely unchanged because the CDN acts as a reverse proxy in front of your origin.
One common point of confusion is handling the root domain. Many DNS providers do not allow a CNAME record on the root domain (example.com) due to how DNS resolution works. Several approaches handle this:
- ALIAS or ANAME records: Some DNS providers offer these record types that function like CNAMEs for root domains.
- Cloudflare's proxy: Cloudflare accepts a direct A record that it then proxies, avoiding the root domain CNAME limitation.
- Redirect approach: Point the root domain to an IP address and configure a redirect from www to root at the CDN or server level.
For business websites using Cloudflare, the provider's dashboard guides you through this process. You add your domain, update your nameservers, and Cloudflare handles the DNS configuration from its interface.
Configuring Nginx to Work Behind a CDN
When a CDN sits in front of your Nginx server, it forwards requests to your origin on behalf of visitors. Your Nginx configuration needs to handle this correctly to preserve important information and manage caching behaviour properly.
Forwarding Visitor IP Addresses
By default, Nginx sees the CDN's IP address as the client IP. If your application, firewall rules, or security tools depend on knowing the visitor's real IP address, you need to configure Nginx to read the headers the CDN sends.
Most CDNs pass the real client IP in either the X-Forwarded-For header or the X-Real-IP header. Your Nginx configuration should trust these headers from the CDN's IP range only. Here is a basic example:
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2a06:98f0::/32;
set_real_ip_from 2c0f:f248::/32;
real_ip_header X-Forwarded-For;
real_ip_header X-Real-IP;
These IP ranges are Cloudflare's. Other CDN providers publish their IP ranges in their documentation. Using a tool like fail2ban or a web application firewall with the wrong IP configuration can result in legitimate visitors being blocked because the system sees the CDN's IP instead of the visitor's real address.
Passing Cache-Control Headers
Your application likely sets Cache-Control headers on responses. The CDN reads these headers to determine what to cache and for how long. If your Nginx configuration strips or modifies these headers, the CDN may cache content incorrectly.
Check that your Nginx configuration includes the fastcgi_hide_header or proxy_hide_header directives appropriately if you are using Nginx as a reverse proxy or handling PHP through FastCGI. For static files served directly by Nginx, ensure headers set by your application are passed through.
Configuring Cache Policies
Set appropriate cache lifetimes for different content types. Static assets like CSS, JavaScript, images, and fonts should have long cache lifetimes, typically one week or more. HTML pages should have shorter cache lifetimes, often a few minutes to an hour, depending on how frequently your content changes.
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 7d;
add_header Cache-Control "public, no-transform";
}
The no-transform directive tells the CDN not to modify the response body. This matters if your application serves already-optimised images that would be degraded by recompression.
Caching Strategies and Cache Invalidation
Static assets change infrequently compared to HTML pages, but they do change. When you deploy a new version of a stylesheet or JavaScript file, you need the CDN to serve the updated version rather than a stale cached copy.
Content-Addressed Filenames
The standard approach is to version your asset URLs. When a file changes, the URL changes. Instead of /style.css, you serve /style.v2.css or /style-a1b2c3.css. Most build tools and frameworks support this automatically through fingerprinting.
This approach means you can set very long cache lifetimes on static assets without worrying about stale content. When you deploy a new version, you deploy a new URL. The old cached version becomes irrelevant because no pages link to it anymore.
Immediate Cache Invalidation
Sometimes you need to purge cached content immediately. You might discover a JavaScript vulnerability, publish a breaking change, or need to update emergency content. All major CDN providers offer cache purge APIs for this purpose.
For Cloudflare, the API call looks like this:
curl -X POST "https://api.cloudflare.com/client/v4/zones/ZONE_ID/purge_cache" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{"files":["https://example.com/style.css"]}'
Automate cache purging as part of your deployment process. When you push a new version of a file to production, your deployment script should trigger a cache purge for that specific file. This keeps your deployment pipeline smooth and ensures visitors see updated content within seconds rather than waiting for the cache TTL to expire.
Common CDN Configuration Mistakes
Several configuration errors appear repeatedly when setting up CDNs for business websites. Avoiding these saves time and prevents frustrating user experience problems.
Setting Long Cache TTLs on Dynamic Pages
The most frequent mistake is applying aggressive caching to HTML pages that change frequently. A visitor sees outdated content, your support team receives confused emails, and you spend time debugging a problem that did not exist before the CDN setup. Separate your caching rules for static assets and dynamic pages. Use short TTLs or bypass the cache entirely for personalised or frequently updated content.
Missing IP Address Headers
Forgetting to configure X-Forwarded-For or X-Real-IP headers breaks IP-based access control, geo-restriction, rate limiting, and security logging. Test your application with the CDN active and verify that visitor IP addresses appear correctly in your logs and application code.
Not Testing Before Full Deployment
Switching DNS records propagates globally over minutes to hours. During this period, some visitors go through the CDN while others hit your origin directly. Test thoroughly in a staging environment and consider using a temporary subdomain to validate your CDN configuration before pointing your main domain.
HTTPS Certificate Configuration
Most CDNs provide free HTTPS certificates through automated providers like Let's Encrypt. If you are bringing your own certificate, ensure it covers both the root domain and any subdomains you plan to use with the CDN. Misconfigured certificates result in browser warnings that drive visitors away.
Validating Your CDN Is Working Correctly
After configuring your CDN, verify that it is actually serving cached content from edge locations rather than proxying every request to your origin server.
Checking Response Headers
Each CDN provider adds identifying headers to responses. These headers confirm that the CDN is handling the request:
- Cloudflare: Adds
cf-rayto every response. - Fastly: Adds
fastly-debug-ttlandvia: 1.1 varnish. - AWS CloudFront: Adds
x-cache: Hit from cloudfrontfor cached responses.
Use curl -I to inspect response headers from different geographic locations:
curl -I https://example.com/asset.js
curl -I https://example.com/index.html
Look for the CDN-specific headers in the response. If you see your origin server's headers instead, the CDN is not caching or not in the request path.
Measuring Performance Improvement
Run performance tests before and after CDN activation to measure the actual improvement. Use WebPageTest or Google PageSpeed Insights, selecting a test server location that matches your audience. For a UK business with mostly UK visitors, test from a UK location. For international audiences, test from multiple geographic regions.
Key metrics to compare:
- Time to First Byte (TTFB): A properly configured CDN should reduce TTFB by 50-80% for geographically distant visitors.
- Fully loaded time: Measures the total page load time including all assets.
- Largest Contentful Paint (LCP): A Core Web Vitals metric that CDNs often improve substantially.
Keep baseline measurements before activation so you have accurate before-and-after data rather than estimates.
Choosing a CDN Provider for Your Business Website
For most small business websites in the United Kingdom, three providers cover the main use cases effectively. The right choice depends on your technical comfort level, existing infrastructure, and specific requirements.
Cloudflare
Cloudflare is the easiest option for business owners who want minimal configuration. Its free tier includes DNS management, global CDN, DDoS protection, and automatic HTTPS. The setup process involves changing your domain nameservers, and most sites are fully operational within an hour. Cloudflare's CDN setup with Cloudflare guide covers the initial configuration steps in detail.
The free tier supports approximately 100,000 monthly page views, which covers the majority of small business websites. Paid plans add features like image optimisation, faster DDoS response, and priority support.
Fastly
Fastly targets developers and technical teams who need fine-grained control over caching behaviour. Its VCL (Varnish Configuration Language) and more recently WAF (Web Application Firewall) rules allow customisation that enterprise teams require. The free tier is limited and primarily intended for evaluation rather than production use.
If your team has the technical expertise and needs real-time log analysis, custom cache invalidation strategies, or programmable edge computing, Fastly provides capabilities that simpler CDNs do not.
AWS CloudFront
AWS CloudFront integrates tightly with other AWS services. If you run your infrastructure on AWS EC2, S3, or Elastic Beanstalk, CloudFront integrates naturally with those services. It provides granular control over edge computing functions and detailed logging through CloudWatch.
CloudFront charges for data transfer out and requests. The free tier covers 10TB per month for the first 12 months of a new AWS account, which is generous for most small business websites. Beyond the free tier, costs scale with usage.
Making the Decision for Your Business Website
A CDN is a powerful tool when your audience, content type, or infrastructure genuinely benefits from edge caching. For small business websites with a local UK audience and modest traffic levels, the performance improvement is often marginal, and the added configuration complexity may not justify the switch.
If you serve international visitors, host large files, run resource-constrained servers, or need DDoS protection, a CDN is worth the investment. The free tiers from Cloudflare and similar providers are generous enough for most business websites to start without any cost.
If you are unsure whether your site would benefit, run a baseline performance test first. Measure your current TTFB, page load time, and Core Web Vitals scores. Then evaluate whether the CDN's benefits align with the gaps you identify. If you need help reviewing your current setup or planning a CDN integration, prepare details of your hosting environment, audience geography, and current performance metrics before getting in touch.