Here is a tutorial which will help you setup and serve your content from a CDN service. So check this, if you are planning to enable the CDN services for your blog.
CDN services have become one of the essential parts of blog setup these days. As blog loading speed has become one of the crucial factors for search engine rankings, people want to make sure they utilize the resources properly.
CDN can help you serve the files from the closest location of your readers. They cache these files around the world in different locations and serve them from the server which is close to the readers.
This way it does not impact the page loading time and increase the bandwidth availability of your server.
When You Should Enable CDN
One of the questions which I get very frequently is when you should enable CDN support for your blogs?
Many people want to know if they need to wait for the traffic before enabling CDN or should they need to go ahead and invest without any income?
This is a catch 22 situation, you won’t start generating enough income in a short time without CDN support and most of the CDN services usually start with a fixed basic cost.
I have started this blog keeping the cost in mind and I am tracking each and every penny spends on this. So I myself have gone through this situation and looked at the costs very closely, this is what I suggest.
You should enable the CDN on your blog from Day One
Yes, there is no excuse for not providing faster experience to your users and that is particularly true if you are targeting multiple geo-locations. You should enable it on day 1 and make sure your blog has a reduced loading time for your readers.
How To Manage Cost?
Now the next thing to talk about is cost, how should we manage it? So let’s check what I have done with this blog to manage my cost effectively.
Usually, when you start your blog, you would not want higher fixed costs as you would be looking to build your income. So at this time, I prefer solutions which are charged pay per use basis. Once you generate enough traffic that the pay per use cost starts increasing, you can look to move.
There are few CDN providers which runs with a free plan but most of them have some restrictions. I was looking for an option which can provide complete flexibility and faster turnaround. Amazon Web Services is one such provider.
I have already talked about how I have finalized and installed this blog on Amazon LightSail. So it makes sense to integrate another service of AWS with this blog.
Now even if you are running on any other WordPress Shared Hosting, you should still be able to use AWS CloudFront CDN without any issue.
Why AWS CloudFront CDN For WordPress
There are many reasons why I have chosen AWS CloudFront as my CDN provider. If you are new to AWS you get limited usage free for the first full year.
In the free tier, you will get 50GB free data out and up to 2,000,000 http / https request. This should be good enough for most of the starter blogs.
Once you cross the limit, you will be charged for what you use. So there is no fixed monthly cost and you can still provide a better experience to your readers.
What Will You Get?
AWS currently has 19 region and 57 availability zones for its users. What are region and zones?
Region– It is like a geo-location with a collection of multiple zones mapped with a physical data center. Every Region is physically isolated and independent from every other Region in terms of location, power, water supply, etc.
Zones– It’s a logical data center in a Region available for use by any AWS customer. They have all the contingency build so two zones will not fail together.
Rackspace blog has a good article to describe region and zones of AWS. For the people from technical background – each region is completely independent. Each Availability Zone is isolated, but the Availability Zones in a region are connected through low-latency links.
These 19 Regions cover geo-locations all over the world and 5 more are planned by end of this year. So your content will always have a closer location to your users and will be served fast.
Other CDN Options
If you are not so inclined to use Amazon CloudFront, here are some other choices which you can use.
This is another CDN service which charge based on usage only. There is no fixed monthly commitment upfront. You will also get 25GB free for the first month as a new customer.
Keycdn prices are one of the most competitive. They charge almost half the price of AWS CloudFront. The more you use their CDN service, the cheaper it becomes.
The only drawback for their service is minimum payment to buy Keycdn credits. Currently, the minimum payment is set to $49 which will give you Keycdn credit of the same account. These credits will expire in one year or you have to make a $49 payment again to carry them forward.
For a new blog $49 may be little expensive, so let me make it easy for you. You can use the below link and signup for Keycdn, this will give you $10 credit which will help you go for some months without any issue. You can reload the amount once these credit are expired.
I also like StackPath (Formally MaxCDN) plans as they provide a good balance between cost and usage. The only issue is their basic plan starts with $10 per month.
You can use the promo code ‘TECHKLE25’ to get 25% off on your pricing but it will still cost around $7.50.
StackPath gives 1 TB global bandwidth in its starter plan, if you compare it with AWS CloudFront, they will charge you around $60 – $80 for that kind of bandwidth. So price wise its much different but on AWS, you will only pay for what you have used.
Most of the started blog needs very little bandwidth so StackPath will be costly at the start but becomes a good alternative once your AWS CloudFront expense starts to reach around $10.
My suggestion would be to use AWS CloudFront till your monthly expense becomes around $5. Once you reach to that limit than move to Keycdn and wait till you reach to $10 monthly expense before moving to StackPath.
Suggested Posts: How To Set Up Email Services On AWS LightSail WordPress Install
AWS CloudFront Setup
This is very good for the starter blogs as they always have constrained budget. So you will only spend money on the bandwidth which you use. If it’s a new AWS account, you can use it for free up to one year.
Do I need S3 Bucket?
If you start looking for information about AWS CloudFront, you would see many pages talking about including AWS S3 Bucket and CloudFront to WordPress. So many people get confused that they need to create an S3 bucket and then use it as an origin for CloudFront.
No, You don’t need S3 Bucket for using AWS CloudFront with WordPress
Also remember that S3 bucket gets charged separately, so until you have a business need to use it, I would not recommend it.
How to Enable AWS CloudFront CDN Service
There are two steps which you need to complete to enable AWS CloudFront for WordPress.
- Enable pull service in AWS CloudFront to fetch your files. AWS doesn’t charge for incoming data so this data transfer will be free of cost.
- Point your files to AWS CloudFront in your WordPress install so it can be picked up from there.
Don’t worry both the steps are very easy to accomplish.
Enable a Pull Service
You can go to your AWS Console and look for CloudFront service. Now you need to create a new distribution, which will be used to supply your files.
Once you click on create distribution, it will ask what kind of delivery method you want – Web or RTMP.
Web– To distribute static files from your blog
RTMP – To distribute media files like audio and video
For our usage, we can select Web as we will be serving files from our WordPress installation. You need to enter origin details in the next screen.
Specify the origin domain name, protocol policy, and other general settings. There are few important settings which are mentioned below:
Origin Domain Name– Domain name for your blog which needs to be integrated with AWS CloudFront
Price Class– AWS is charged differently based on the region, so if you want to avoid pricier location and want to serve content from certain regions, you can select here.
Alternate Domain Names– If you want to use your own CNAME rather than the AWS provided name, you can set it here. Alternatively it will create a domain name for you, which might not be easily readable. So if you want to change it, you can do it here.
Geo Restrictions– If you want to restrict your content at some geo location, you can do it here.
You can also set your http vs https settings also here, decide how you want to serve your content. If you have enabled https and want all http request to redirect to https, you can set it up here.
Enable AWS CloudFront In WordPress
Once you have created a distribution, it will pull all the files from your sites and will cache it in AWS. Now you need to point your WordPress to AWS distribution for your static files.
You can do that with W3 Total Cache plugin, it provides support for AWS CloudFront. Before you make that connection, you need to create an access id and security key for your AWS account.
You can just enable it and set it as a mirror also but that doesn’t give fine grain controls. So I prefer the access id and security key method.
Create an access ID and security Key
You can go to AWS Console and look for IAM. Create a new user and give it any name you like. Select the Programmatic access method under access type, we do not want that user id to login to AWS console.
Now you need to provide authority for CloudFront to this user. Attach pre-made policy CloudFrontFullAccess and CloudFrontReadOnlyAccess to the user. Once you are done, it will generate an access id and secret key, make a note of it.
Update W3 Total Cache
Now go to General Setting in W3 Total Cache and enable CDN with Amazon CloudFront. After enabling it, you need to create a connection to AWS.
Go to CDN page and it will ask for access id, secret key and domain name. You can enter the details and it will create a connection to AWS.
Domain name will be what you have given in CNAME section of CloudFront or will be assigned for you. You can get it from AWS CloudFront dashboard.
You can update what kind of files you want to serve from your CDN and W3 Total Cache will update the links to point to CDN. Now if you open your blog, your static files will be served from AWS CloudFront.
One thing which you need to note is CloudFront charges for file invalidations. So if you want to clear your cache and manually invalidate the cache, there will be a charge. First, 1000 Files / Path are free, after that you need to pay. So be careful while invalidating the cached files.
You can also skip using CDN for logged in users or administers, if you want to save some cost. But I would recommend to periodically check your blog as a normal user. You may want to keep it as close as other user of your blog so all gets a single consistent view.
You can also set it up with WP Super Cache with ease, just provide the alternate URL and enable the CDN support, it will start serving the file from AWS CloudFront.
That’s how you can enable the CDN service for your WordPress blog with AWS CloudFront. Which CDN service are you using for your blog and when did you enable it? Did you wait for some before using the CDN service with your blog?