Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 63 additions & 66 deletions advanced/subpath/route53-cloudfront.mdx
Original file line number Diff line number Diff line change
@@ -1,146 +1,143 @@
---
title: "AWS Route 53 and Cloudfront"
title: "AWS Route 53 and CloudFront"
sidebarTitle: "AWS"
description: "Host documentation at a /docs subdirectory using AWS services"
---

import Propagating from "/snippets/custom-subpath-propagating.mdx";

## Create Cloudfront Distribution
This guide walks you through configuring AWS CloudFront and Route 53 to serve your documentation at `/docs` while keeping your main site intact. You'll create a CloudFront distribution that routes `/docs` traffic to your Mintlify documentation and all other traffic to your primary site.

Navigate to [Cloudfront](https://aws.amazon.com/cloudfront) inside the AWS console and click on `Create distribution`
<Info>
Before starting, ensure you have AWS console access with permissions for CloudFront and Route 53. You'll also need your Mintlify subdomain (found in your dashboard) and a staging URL for your main site.
</Info>

## Set up CloudFront distribution

Navigate to [CloudFront](https://aws.amazon.com/cloudfront) in the AWS console and select **Create distribution**.

<Frame>
![Cloudfront Create Distribution](/images/cloudfront/create-distribution.png)
![CloudFront Create Distribution](/images/cloudfront/create-distribution.png)
</Frame>

For the Origin domain, input `[SUBDOMAIN].mintlify.dev` where `[SUBDOMAIN]` is the project's unique subdomain. Click on `Use: [SUBDOMAIN].mintlify.dev`
For the origin domain, enter `[SUBDOMAIN].mintlify.dev` where `[SUBDOMAIN]` is your project's unique subdomain from the dashboard. Select **Use: [SUBDOMAIN].mintlify.dev** from the dropdown.

<Frame>![Cloudfront Origin name](/images/cloudfront/origin-name.png)</Frame>
<Frame>![CloudFront Origin name](/images/cloudfront/origin-name.png)</Frame>

For **Cache key and origin requests**, select `Caching Optimized`.
Under **Cache key and origin requests**, select **Caching Optimized**.

<Frame>
![Cloudfront Caching policy](/images/cloudfront/caching-policy.png)
![CloudFront Caching policy](/images/cloudfront/caching-policy.png)
</Frame>

And for **Web Application Firewall (WAF)**, enable security protections
For **Web Application Firewall (WAF)**, enable security protections.

<Frame>
![Cloudfront Caching
policy](/images/cloudfront/enable-security-protections.png)
![CloudFront Security protections](/images/cloudfront/enable-security-protections.png)
</Frame>

The remaining settings should be default. Click `Create distribution`.
Leave other settings as defaults and select **Create distribution**.

## Add Default Origin
## Add your main site origin

After creating the distribution, navigate to the `Origins` tab.
After creating the distribution, go to the **Origins** tab.

<Frame>![Cloudfront Origins](/images/cloudfront/origins.png)</Frame>
<Frame>![CloudFront Origins](/images/cloudfront/origins.png)</Frame>

We want to find a staging URL that mirrors where the main domain (example.com). This is highly variant depending on how your landing page is hosted.
You need a staging URL that mirrors your main domain. This varies based on your hosting provider:

<Info>
For instance, if your landing page is hosted on Webflow, you can use the
Webflow's staging URL. It would look like `.webflow.io`.

If you use Vercel, you use the `.vercel.app` domain available for every project.
<Tip>
Common staging URL patterns:
- Webflow: `yoursite.webflow.io`

Check warning on line 51 in advanced/subpath/route53-cloudfront.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

advanced/subpath/route53-cloudfront.mdx#L51

Did you really mean 'Webflow'?
- Vercel: `yourproject.vercel.app`

Check warning on line 52 in advanced/subpath/route53-cloudfront.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

advanced/subpath/route53-cloudfront.mdx#L52

Did you really mean 'Vercel'?
- Netlify: `yourproject.netlify.app`

Check warning on line 53 in advanced/subpath/route53-cloudfront.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

advanced/subpath/route53-cloudfront.mdx#L53

Did you really mean 'Netlify'?
- GitHub Pages: `username.github.io/repository`
</Tip>

</Info>
<Note>

If you're unsure on how to get a staging URL for your landing page, [contact
support](/contact-support) and we'd be happy to help

Can't find your staging URL? Check your hosting provider's dashboard or contact support for help identifying the correct URL.
</Note>

Once you have the staging URL, ours for instance is [mintlify-landing-page.vercel.app](https://mintlify-landing-page.vercel.app), create a new Origin and add it as the **Origin domain**.
Create a new origin using your staging URL as the **Origin domain**.

<Frame>
![Cloudfront Default Origins](/images/cloudfront/default-origin.png)
![CloudFront Default Origins](/images/cloudfront/default-origin.png)
</Frame>

By this point, you should have two Origins - one with `[SUBDOMAIN].mintlify.app` and another with with staging URL.

## Set Behaviors
You should now have two origins: your Mintlify subdomain and your main site's staging URL.

Behaviors in Cloudfront enables control over the subpath logic. At a high level, we're looking to create the following logic.
## Configure routing behaviors

- **If a user lands on /docs**, go to `[SUBDOMAIN].mintlify.dev`
- **If a user lands on any other page**, go the current landing page
Behaviors control how CloudFront routes requests. You'll create rules that send `/docs` traffic to your documentation and everything else to your main site.

We're going to create three behaviors by clicking on the `Create behavior` button.
Create three behaviors by selecting **Create behavior**:

### `/docs/*`
### `/docs/*` behavior

The first behavior should have a **Path pattern** of `/docs/*` with **Origin and origin groups** pointing to the `.mintlify.dev` URL (in our case `acme.mintlify.dev`)
Set **Path pattern** to `/docs/*` and **Origin and origin groups** to your `.mintlify.dev` URL.

<Frame>![Cloudfront Behavior 1](/images/cloudfront/behavior-1.png)</Frame>
<Frame>![CloudFront Behavior 1](/images/cloudfront/behavior-1.png)</Frame>

For **Cache policy**, select `CachingOptimized` and create behavior.
Set **Cache policy** to **CachingOptimized** and create the behavior.

### `/docs`
### `/docs` behavior

The second behavior should be the same as the first one but with a **Path pattern** of `/docs` and **Origin and origin groups** pointing to the same `.mintlify.dev` URL.
Create another behavior with **Path pattern** `/docs` pointing to the same `.mintlify.dev` origin.

<Frame>![Cloudfront Behavior 2](/images/cloudfront/behavior-2.png)</Frame>
<Frame>![CloudFront Behavior 2](/images/cloudfront/behavior-2.png)</Frame>

### `Default (*)`
### Update default behavior

Lastly, we're going to edit the `Default (*)` behavior.
Edit the **Default (*)** behavior to point to your main site's staging URL.

<Frame>
![Cloudfront Behavior Default 1](/images/cloudfront/default-behavior-1.png)
![CloudFront Behavior Default 1](/images/cloudfront/default-behavior-1.png)
</Frame>

We're going to change the default behavior's **Origin and origin groups** to the staging URL (in our case `mintlify-landing-page.vercel.app`).
Change **Origin and origin groups** to your staging URL and save changes.

<Frame>
![Cloudfront Behavior Default 2](/images/cloudfront/default-behavior-2.png)
![CloudFront Behavior Default 2](/images/cloudfront/default-behavior-2.png)
</Frame>

Click on `Save changes`.
## Test your distribution

## Preview Distribution

You can now test if your distribution is set up properly by going to the `General` tab and visiting the **Distribution domain name** URL.
Go to the **General** tab and visit your **Distribution domain name** URL to test the setup.

<Frame>
![Cloudfront Preview
distribution](/images/cloudfront/preview-distribution.png)
![CloudFront Preview distribution](/images/cloudfront/preview-distribution.png)
</Frame>

All pages should be directing to your main landing page, but if you append `/docs` to the URL, you should see it going to the Mintlify documentation instance.
Verify that:
- The root URL shows your main site
- Adding `/docs` to the URL displays your documentation

## Connecting it with Route53
## Connect with Route 53

Now, we're going to bring the functionality of the Cloudfront distribution into your primary domain.
Now you'll route your primary domain through the CloudFront distribution.

<Note>
For this section, you can also refer to AWS's official guide on [Configuring
Amazon Route 53 to route traffic to a CloudFront
distribution](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-cloudfront-distribution.html#routing-to-cloudfront-distribution-config)
This follows AWS's guide on [routing traffic to a CloudFront distribution](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-cloudfront-distribution.html#routing-to-cloudfront-distribution-config). You'll need Route 53 managing your domain's DNS.
</Note>

Navigate to [Route53](https://aws.amazon.com/route53) inside the AWS console, and click into the `Hosted zone` for your primary domain. Click on `Create record`
In [Route 53](https://aws.amazon.com/route53), open your domain's **Hosted zone** and select **Create record**.

<Frame>
![Route 53 create record](/images/cloudfront/route53-create-record.png)
</Frame>

Toggle `Alias` and then **Route traffic to** the `Alias to CloudFront distribution` option.
Enable **Alias** and set **Route traffic to** as **Alias to CloudFront distribution**. Select your distribution from the dropdown.

<Frame>
![Route 53 create record alias](/images/cloudfront/create-record-alias.png)
</Frame>

Click `Create records`.
Select **Create records**.

<Note>
You may need to remove the existing A record if one currently exists.
</Note>
<Warning>
You may need to delete existing A records for your domain before creating the alias record.
</Warning>

And voila! Your documentation will be served at `/docs` for your primary domain.
Your documentation will now be available at `yourdomain.com/docs`.

<Propagating />
Loading