cdn.yourdomain.com
)Hosting static assets like CSS, JavaScript, and images from a CDN improves your website speed and user experience. In this guide, we’ll show you how to upload your files to Cloudflare R2 (S3-compatible storage), and serve them through Amazon CloudFront using your own subdomain like cdn.callcenterjob.co.in
.
Low-cost object storage with Cloudflare R2
Global CDN with AWS CloudFront
Use your own domain (cdn.example.com
)
Improve SEO, loading speed, and performance scores
Use rclone to upload files automatically:
Make sure your rclone.conf
is configured like this:
Go to AWS CloudFront console → Create Distribution
For Origin Domain, use your bucket endpoint:
Set Viewer Protocol Policy: Redirect HTTP to HTTPS
Enable compression for better speed
Under Alternate Domain (CNAME):
Choose or request an SSL certificate for your subdomain via ACM
In your DNS (Cloudflare or other provider), add a CNAME:
Type | Name | Target | TTL |
---|---|---|---|
CNAME | cdn | dxxxxxxxxxxx.cloudfront.net |
Auto |
Proxy status: DNS only (gray cloud)
CloudFront domain will look like: d123abc4.cloudfront.net
To allow the public (and CloudFront) to access your files, add this policy to your S3-compatible bucket:
Without this, users will get a 403 Forbidden error.
To keep your bucket updated, create a cron job:
Add:
Try accessing a static file:
If it loads without 403 error, you're all set!
You can restrict your R2 bucket so only CloudFront can access it, by using Origin Access Control (OAC). This avoids exposing your R2 endpoint directly.
Comments