Cloudflare Setup for Amazon S3
This article assumes that you’ve already setup an Amazon S3 bucket and followed the steps within our Amazon S3 Quick Start Guide.
IMPORTANT: Cloudflare requires that the bucket name be the same as the CNAME you wish to use.
Once the above steps are taken care of, you will need to determine your bucket URL. To do this, prefix your region and bucket name to ‘.amazonaws.com’. For example:
Login to Cloudflare and head to the DNS tab. Add your CNAME and bucket URL.
The orange cloud icon next to the DNS entry indicates that traffic to the hostname will be proxied through the Cloudflare CDN. You do not need to enable Cloudflare on any other hostname for this to work.
Configure WP Offload Media
Login to your WordPress dashboard and navigate to Settings > Offload Media. Enable the Custom Domain (CNAME) option and enter your CDN URL.
Save the changes and clear your page cache if you have one enabled.
If your site has an active SSL certificate Cloudflare will automatically enable ‘Full SSL’, which will ensure that you do not receive mixed content warnings on the front-end.
If your site doesn’t have an SSL certificate, but you want your assets to be served over HTTPS you can enable ‘Flexible SSL’ in Cloudflare. You will also need to turn on ‘Force HTTPS’ in WP Offload Media.
Testing Everything Works
If you load your site’s front-end and open the developer tools (Cmd-Alt-i on macOS, Ctrl-Shift-i elsewhere) you should see that your assets are now being served from Cloudflare. You can confirm this by checking the response headers, which should contain a ‘CF-Cache-Status’ header.