CloudCover

Cloudfront, A Pain with Wordpress, or Is it?

by Tunoor Rao, Saturday, 08 October 2016

We’ve all been there, struggling with the Apache Configurations, Tune-ups and WP configurations to handle the spikes on our Wordpress WebSite(s). On top of that, CPU and Memory spikes add to our pain. But there’s good news, coz Cloudfront is going to be there for you.

There are a lot of plugins that talk about Static Caching, but that is not what this post is about. We will cover the setup of Cloudfront over an existing Wordpress Website in reference to the concept shared in this blog post.

How To Set it Up

Step 1 is easy as pie. Create a Cloudfront Distribution that points to your Wordpress Website and assign the relevant CNAMES and SSL Certificate(s) to it.

OriginSettings

CNAMESettings

Step 2 is configuring the default cache settings, aka default behaviour, that will control how Cloudfront responds to majority of the incoming requests. We can choose the headers and cookies we want to Whitelist (Selective Caching of Objects), No Forwarding (Cache all requests) or Forward All (No Caching, Fetch Directly from origin).

Make sure that query strings are forwarded so that any searches or DB queries are easily handled.

CacheBehaviour

Pay close attention to the following, as these values control the duration for which Cloudfront will cache your objects -

Minimum TTL

Default Value - 0

Definition - The minimum amount of time, in seconds, that you want objects to stay in CloudFront caches before CloudFront forwards another request to your origin to determine whether the object has been updated. Minimum TTL interacts with HTTP headers such as Cache-Control max-age, Cache-Control s-maxage, and Expires and with Default TTL and Maximum TTL.

Maximum TTL

Default Value - 31536000

Definition - The maximum amount of time, in seconds, that you want objects to stay in CloudFront caches before CloudFront forwards another request to your origin to determine whether the object has been updated. The value that you specify applies only when your origin adds HTTP headers such as Cache-Control max-age, Cache-Control s-maxage, and Expires to objects.

Default TTL

Default Value - 86400

Definition - The default amount of time, in seconds, that you want objects to stay in CloudFront caches before CloudFront forwards another request to your origin to determine whether the object has been updated. The value that you specify applies only when your origin does not add HTTP headers such as Cache-Control max-age, Cache-Control s-maxage, and Expires to objects.

Step 3 is adding more behaviours to access our wp-admin pages and to fetch directly from origin for dynamic requests e.g. wp-login.php

DynamicDelivery1

DynamicDelivery2

Any other custom pages can be served with behaviours configured to fetch content from origin or a cached copy from Cloudfront.

Save your distribution and wait a good 15-20 minutes until your Cloudfront Distribution shows the status “Deployed”

If you use Route 53 for DNS Management, you can create an ALIAS record set for the CNAMES mapped to Cloudfront and you’re set.

If you desire, there are a few other settings that were recently introduced e.g. HTTP Version selection (HTTP/2, HTTP/1.1 etc) or enabling IPv6.

NewSettings


All done! Now you can serve your Wordpress site without the use of additional plugins/configuration. All you need is Cloudfront.

Author

Tunoor Rao

Tunoor Rao

Tunoor is "Lead Sysops Engineer" at CloudCover. She loves multi cloud strategies and is our In-House VPN Specialist.