Complete CDN Acceleration Configuration Guide
Detailed guide on configuring CDN acceleration, including setup steps for Alibaba Cloud CDN, Tencent Cloud CDN, and Cloudflare.
What is CDN
CDN (Content Delivery Network) is an intelligent virtual network built on existing network infrastructure. It uses edge servers deployed globally, with load balancing, content distribution, and scheduling modules to allow users to get content from nearby locations.
Why You Need CDN
Main Advantages
- Faster access - Users access from nearby, reducing latency
- Lower load - Reduce origin server pressure
- Better experience - Faster loading speeds, better user experience
- Cost savings - Reduce bandwidth costs
- Higher reliability - Distributed architecture improves availability
Suitable Scenarios
- Website acceleration
- Download distribution
- Video on demand
- Live streaming
- API acceleration
Mainstream CDN Service Comparison
| Feature | Alibaba Cloud CDN | Tencent Cloud CDN | Cloudflare |
|---|---|---|---|
| Node Count | 2800+ | 2800+ | 300+ |
| China Nodes | ✅ | ✅ | ❌ |
| Free Tier | ❌ | ❌ | ✅ |
| HTTPS | ✅ | ✅ | ✅ |
Alibaba Cloud CDN Configuration
1. Add Domain
- Click “Add Domain”
- Enter acceleration domain (e.g., cdn.example.com)
- Select business type
- Enter origin information
2. Configure Origin
Origin Types:
- IP origin - Direct IP address
- Domain origin - Origin domain name
- OSS origin - Select OSS bucket
3. Configure Cache Policy
// Cache configuration
{
"directory": "/",
"ttl": 3600, // 1 hour
"weight": 1
}
// Different cache times for different paths
{
"directory": "/static/images/",
"ttl": 86400, // 24 hours
}
4. Configure HTTPS
- Upload certificate or use free certificate
- Enable HTTP/2
- Configure forced HTTPS redirect
Tencent Cloud CDN Configuration
Basic Configuration
Similar to Alibaba Cloud CDN:
- Add acceleration domain
- Configure origin information
- Configure cache rules
- Enable HTTPS
Advanced Configuration
Access Control:
// Referer anti-hotlinking
{
"referer": {
"enabled": true,
"type": "white_list",
"list": ["example.com", "*.example.com"]
}
}
Cloudflare Configuration
1. Add Site
- Register Cloudflare account
- Add your website
- Select free plan
2. Modify DNS
Change domain DNS servers to Cloudflare’s DNS servers.
3. Configure Cache
Page Rules:
*example.com/images/*
- Cache level: Standard
- Edge cache expire time: 1 day
*example.com/api/*
- Cache level: Bypass
- Disable cache
4. Optimization Settings
Speed Optimization:
- Auto Minify - Auto compress CSS/JS
- Brotli compression
- HTTP/2
- HTTP/3 (QUIC)
Performance Optimization Recommendations
1. Cache Strategy
Static resources:
- Images, CSS, JS: Long cache (1 year)
- HTML files: Short cache or no cache
- API responses: No cache
Cache configuration example:
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
2. File Optimization
Image optimization:
- Use WebP format
- Responsive images
- Lazy loading
- Image compression
CSS/JS optimization:
- Minify code
- Combine files
- Lazy loading
- Async loading
Best Practices Summary
- Configure cache reasonably - Long cache for static resources, no cache for dynamic content
- Enable HTTPS - Improve security, enable HTTP/2
- Monitor performance - Regularly review monitoring data, optimize configuration
- Control costs - Choose appropriate billing method, optimize traffic usage
- Multi-level cache - Browser cache + CDN cache + origin cache
Related Reading: