Skip to content

CloudFront

Melvyn Harbour edited this page Aug 29, 2019 · 2 revisions

CloudFront, an Amazon Web Services tool provides us with a layer of caching that protects the website from high load. We can take particular advantage of this as our website doesn't change very often.

There is a single CloudFront Distribution to provide the cache. We mostly just needs default settings, but there are a couple of things that need to be set up correctly for WordPress to function as you would expect.

Origin

There is a single Origin defined, pointing at web.wehorr.org. This represents the address that CloudFront will look at in order to fetch the website content. Note that this cannot be www.wehorr.org as it would form a circular reference, looking up from itself.

Behaviors

We need four Behaviors defined, with preference in order:

  1. wp-admin/* defined with Query String Forwarding all and and Caching based on all. It should allow all HTTP methods and forward all Cookies.
  2. wp.login.php as for the previous entry.
  3. /wp-json/* defined as above, but with Whitelisted Headers for Host, Options and Referer.
  4. Default (*) with only GET, HEAD and OPTIONS allowed, Query String Forwarding all and some whitelisted cookies:
PHPSESSID
wordpress_logged_in_*
wordpress_test_cookie
wp-settings-*

Invalidations

This section is used when you change something on a page. When you do, create an invalidation that refers to the URL(s) of the pages you have changed in order to flush the cache. Note that there is a (fairly large) limit on the number of free invalidations per month, so if you're planning a lot of updates, batch them up and then use a wildcard invalidation.

Clone this wiki locally