Documentation

Integrating with AWS CloudFront

AWS CloudFront is a reverse proxy tool offering similar features to Servd's own ingress platform. If you use AWS for your wider infrastructure or for managing DNS, you might want to add it in front of your Servd project in order to consolidate your platform configurations. Here are a few steps to help you integrate it with your Servd project:

  1. Create the Distribution(s) - CloudFront distributions are the wrappers around everything else. Each distribution can be set up to handle multiple domains, but we normally recommend creating one distribution per domain. Some general settings such as domains and SSL certificate management are defined on the distribution directly.

  2. Set up the Origin(s) - Each distribution can have multiple origins. An Origin is a back-end server that CloudFront will proxy traffic through to. The settings for these are things like the domain for the origin, whether to connect via HTTP/HTTPS, timeouts, etc.

  3. Set up the Behaviour(s) - these map incoming requests to Origins, following specific rules. All distributions have a default behaviour which acts as a catch-all, but you can also create other behaviours which only apply to specific paths. This can be useful if you only want to capture traffic hitting a specific subpath for a domain.

Origin Domains and URLs #

When creating an Origin which points to Servd, Cloudfront will require a domain name, as it doesn't allow IP addresses. So you'll need to create a domain within Servd (e.g origin.mysite.com) and hook up the DNS for it in your DNS provider. You can then use origin.mysite.com as the origin domain in your Cloudfront settings.

By default AWS will then send origin.mysite.com over to Servd as the Host header. With its default setup, Craft will think that this is the domain being used to access the site by the end user, so it'll start outputting things like control panel links with this domain. To get Craft to stop doing that, we have to force it to ignore the Host header and explicitly define a domain to use. The method of doing this depends on your Craft version, but in general:

  1. Set an explicit Site URL on your default and any secondary 'Site's defined in Craft
  2. Set an explicit domain for the Craft control panel using the baseCpUrl config setting
  3. In some versions of Craft you also need to explicitly set the domain for cpresources and action urls, however newer Craft versions will do this for you automatically.

Once Cloudfront is forwarding requests to Servd using your origin domain name, and Craft has been forced to use the 'real' domain in all of the URLs that it outputs, you should be up and running with Cloudfront proxying requests through to Servd.