In this CloudFront Distribution how-to-do we will cover following tasks :
- Create a Cloudfront distribution for the images that are uploaded on a WordPress blog.
- Automatically sync wordpress uploads to s3 bucket.
- Compare the image load time across different countries with and without cloudfront.
Step 1 : Create a Bucket
Step 2 : Create the CloudFront Distribution
Step 3 : Create the new Cronjob
Note: In order to perform further steps its recommended to configure AWS CLI on EC2 instance before moving on further.
*/2 * * * * root aws s3 sync /var/www/html/wp-content/uploads s3://wp-cdn1
Step 4 : Add new post to WordPress with Image
Step 5 : Redirect uploads folder to our CloudFront Distribution
rewriterule ^wp-content/uploads/(.*)$ http://dsnbd65zem3ul.cloudfront.net/$1 [r=301, nc]
Step 6 : Restart crond and httpd service
Step 7 : Testing our Cloudfront Distribution
Step 8 : Latency Test (without Cloudfront)
Here you can see the result without cloudfront
Step 9 : Latency Test (with Cloudfront)
With CDN implemented you can see it has decreased latency of website, thus this proves the advantage of having a CDN configured for all the static content on a wesbite.
Feel free to ask any queries in comments below.
Thanks for reading, hope it helped!
-bhargav
Social Profiles