I was doing a project for an organization that had a WordPress Multisite network of International websites. The problem we encountered was that WordPress sites in other countries would run more slowly because our web host was in the United States. I needed to move into the Cloud. I liked the “pay for what you use” model of Amazon CloudFront. Now the challenge was to get WordPress to interface with CloudFront. I found an easy way to do this using the WP Super Cache plugin. Here is the process that I took:
1. Create CloudFront Distributions
First of all, I logged into my Amazon CloudFront account and created a new download distribution. On the “Choose An Origin” page, I typed in the URL of one of the sites in my Multisite network that I wanted to use with Amazon CloudFront:
I left all the default settings in place on the “Create Default Behavior” page.
On the “Distribution Details” page, I typed in a more friendly “cdn.mysite.com” subdomain CNAME that I would set up on my DNS server in Step 2. I also made sure to leave a helpful comment in the “Comments” box.
After finishing the wizard, the distribution took a little while to activate.
I created a unique distribution for as many of the sites on my WordPress multisite network that I wanted to run through CloudFront.
2. Set up a CNAME for each CloudFront Distribution
Each new CloudFront distribution is assigned a unique domain name such as “d1zfxpnm794u7b.cloudfront.net”. My next step was to create new CNAME records in the DNS that would point each “cdn.mysite.com” subdomain to its “d1zfxpnm794u7b.cloudfront.net” CloudFront distribution.
3. Install and Configure WP Super Cache
Then I had to install WP Super Cache on my WordPress Multisite network. This was easy to do. However, I discovered one important “gotcha” with the current version of WP Super Cache (1.1). It is an “all or nothing” plugin. Once it is enabled on one site on my network, it starts caching the pages on every site. To help me remember that this was happening, I chose to network activate the plugin. However, I had to keep in mind that if I went to the WP Super Cache Settings page on any individual blog and turned the caching on or off, it would turn the caching on or off globally for every site.
On the WP Super Cache Settings pages, I globally enabled caching on the “Easy” tab. Because I was using a Multisite install with the Domain Mapping WordPress plugin, I also had to enable the WP Super Cache Domain Mapping plugin on the WP Super Cache Settings “Plugins” tab.
Then I globally enabled CDN Support on the “CDN” tab. It is not a problem to globally enable CDN Support on a Multisite network even if there are sites on your network that are not using a CDN.
I found out that there is one exception to the rule of every setting applying globally. On the WP Super Cache Settings “CDN” tab, even though “Enable CDN Support” is a global setting, the URL settings below it are unique to each individual site. This is important because each site in a Multisite Network with Domain Mapping enabled will need to have it’s own unique CloudFront distribution.
There are two local settings that needed modified on each individual site for which I had set up a CloudFront distribution:
- Under Off-site URL I entered the CNAME URL for my CloudFront distribution.
- I made sure to add “,files” to the Include directories list so that all of the uploaded files would also use CloudFront.
And it worked!
Loved your post, and everything works great with the exception of the /files/ directory.
If you spare a few minutes of your time I ‘d love to speak to you via email.
Thanks
Is it possible to automatically set the CDN URL for all subsites as they will be serving content from the same directory?
https://wordpress.org/plugins/aws-cdn-by-wpadmin/ simplifies the task of creating Amazon AWS CDN and its free