This article sets out to show how to host a static websitewether built from a generator like Jekyll, Pelican or Hyde, or “by hand” on Amazon Web Services, especially Amazon S3 in order to store the website files, and CloudFront in order to deliver them. The main purpose is to be able to get a website fast from anywhere, reliable, secure, highly scalable and inexpensive
Many websites and places that talk about integrating Amazon Cloudfront with WordPress are simply talking about static assets. Using some caching plugin that rewrites the URLs in the page’s source to point at your Cloudfront distribution, and that’s about it. They don’t talk about how your server can be (as WP SuperCache puts it) Stephen Fry-proof. No one actually says anything about how to put YOUR ENTIRE WEBSITE behind Amazon Cloudfront (and by this, I mean pointing your www.* domain at Cloudfront and letting it take care of everything).
- Go to CloudFront settings
- Edit Distributions settings for a distribution
- Go to the Behaviors tab and edit or create a behavior
- Set Forward Headers to Whitelist
- Add Referer as a whitelisted header
- Save the settings in the bottom right corner
Make sure to also handle the Referer header on your origin.
There are well documented requirements to the resources Amazon CloudFront will cache. For our use-case most interesting HTTP headers would be the Cache-Control, Date, Last-Modified and ETag.
Amazon CloudFront uses Cache-Control header to control how long it should cache given resource. There is another Expires header available in the HTTP spec, however Cache-Control is preferred by CloudFront.
Apart from that we need to serve Date and Last-Modified headers that are required to compute expire value from Cache-Control header.