Skip to content

Commit 4854f5b

Browse files
ethanpalmcdxker
andauthored
Cloudfront custom origin request (#1021)
* sentence case headings * copy edit * add Vercel behavior info * docs: updated screenshots with new Cloudfront webpages * spelling: correct Cloudfront -> CloudFront * copyedit --------- Co-authored-by: cdxker <[email protected]>
1 parent 60590ec commit 4854f5b

File tree

8 files changed

+104
-70
lines changed

8 files changed

+104
-70
lines changed
Lines changed: 104 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: "AWS Route 53 and Cloudfront"
2+
title: "AWS Route 53 and CloudFront"
33
sidebarTitle: "AWS"
44
description: "Host documentation at a /docs subdirectory using AWS services"
55
---
66

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

9-
To host your documentation at a `/docs` subpath using AWS Route 53 and Cloudfront, you need to configure your DNS provider to point to your Cloudfront distribution.
9+
To host your documentation at a `/docs` subpath using AWS Route 53 and CloudFront, you need to configure your DNS provider to point to your CloudFront distribution.
1010

1111
## Proxies with Vercel deployments
1212

@@ -25,153 +25,187 @@ These paths should be configured to bypass CloudFront caching and pass through d
2525

2626
### Header forwarding requirements
2727

28-
Ensure that CloudFront forwards the `HOST` header and client IP information correctly. This is critical for Vercel's verification processes.
28+
You must create a custom origin request policy that forwards the `HOST` header and client IP information correctly. This is critical for Vercel's verification processes.
2929

30-
When using CloudFront with Vercel deployments, CloudFront automatically adds the `CloudFront-Viewer-Address` header containing the original client's IP address.
30+
1. Create a custom origin request policy named `VercelCloudFrontProxy`.
31+
2. Include the `Origin` and `CloudFront-Viewer-Address` headers.
3132

32-
Make sure your CloudFront distribution is configured to forward this header to your origin by including it in your origin request policy or cache policy headers configuration.
33+
You must include the `CloudFront-Viewer-Address` header in your origin request policy or cache policy headers configuration to forward the header to your origin.
3334

34-
## Create Cloudfront Distribution
35+
## Create CloudFront distribution
3536

36-
Navigate to [Cloudfront](https://aws.amazon.com/cloudfront) inside the AWS console and click on `Create distribution`
37+
1. Navigate to [CloudFront](https://aws.amazon.com/cloudfront) inside the AWS console.
38+
2. Select **Create distribution**.
3739

38-
<Frame>
39-
![Cloudfront Create Distribution](/images/cloudfront/create-distribution.png)
40-
</Frame>
40+
<Frame>
41+
![CloudFront Distributions page with the "Create distribution" button emphasized.](/images/cloudfront/create-distribution.png)
42+
</Frame>
4143

42-
For the Origin domain, input `[SUBDOMAIN].mintlify.dev` where `[SUBDOMAIN]` is the project's unique subdomain. Click on `Use: [SUBDOMAIN].mintlify.dev`
44+
3. For the Origin domain, input `[SUBDOMAIN].mintlify.dev` where `[SUBDOMAIN]` is your project's unique subdomain.
4345

44-
<Frame>![Cloudfront Origin name](/images/cloudfront/origin-name.png)</Frame>
46+
<Frame>
47+
![CloudFront "Create distribution" page showing "acme.mintlify.dev" as the origin domain.](/images/cloudfront/origin-name.png)
48+
</Frame>
4549

46-
For **Cache key and origin requests**, select `Caching Optimized`.
50+
4. For "Web Application Firewall (WAF)," enable security protections.
4751

48-
<Frame>
49-
![Cloudfront Caching policy](/images/cloudfront/caching-policy.png)
50-
</Frame>
52+
<Frame>
53+
![Web Application Firewall (WAF) options with "Enable security protections" selected.](/images/cloudfront/enable-security-protections.png)
54+
</Frame>
5155

52-
And for **Web Application Firewall (WAF)**, enable security protections
56+
5. The remaining settings should be default.
57+
6. Select **Create distribution**.
5358

54-
<Frame>
55-
![Cloudfront Caching
56-
policy](/images/cloudfront/enable-security-protections.png)
57-
</Frame>
58-
59-
The remaining settings should be default. Click `Create distribution`.
59+
## Add default origin
6060

61-
## Add Default Origin
61+
1. After creating the distribution, navigate to the "Origins" tab.
6262

63-
After creating the distribution, navigate to the `Origins` tab.
63+
<Frame>
64+
![A CloudFront distribution with the "Origins" tab highlighted.](/images/cloudfront/origins.png)
65+
</Frame>
6466

65-
<Frame>![Cloudfront Origins](/images/cloudfront/origins.png)</Frame>
66-
67-
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.
67+
2. Find your staging URL that mirrors the main domain. This is highly variant depending on how your landing page is hosted. For example, the Mintlify staging URL is [mintlify-landing-page.vercel.app](https://mintlify-landing-page.vercel.app).
6868

6969
<Info>
70-
For instance, if your landing page is hosted on Webflow, you can use the
71-
Webflow's staging URL. It would look like `.webflow.io`.
72-
73-
If you use Vercel, you use the `.vercel.app` domain available for every project.
70+
If your landing page is hosted on Webflow, use Webflow's staging URL. It would look like `.webflow.io`.
7471

72+
If you use Vercel, use the `.vercel.app` domain available for every project.
7573
</Info>
76-
<Note>
7774

78-
If you're unsure on how to get a staging URL for your landing page, [contact
79-
support](/contact-support) and we'd be happy to help
75+
3. Create a new Origin and add your staging URL as the "Origin domain".
8076

81-
</Note>
77+
<Frame>
78+
![CloudFront "Create origin" page with a "Origin domain" input field highlighted.](/images/cloudfront/default-origin.png)
79+
</Frame>
8280

83-
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**.
81+
By this point, you should have two Origins: one with `[SUBDOMAIN].mintlify.app` and another with your staging URL.
8482

8583
<Frame>
86-
![Cloudfront Default Origins](/images/cloudfront/default-origin.png)
84+
![CloudFront "Origins" page with two origins: One for `mintlify` and another for `mintlify-landing-page`.](/images/cloudfront/final-origins.png)
8785
</Frame>
8886

89-
By this point, you should have two Origins - one with `[SUBDOMAIN].mintlify.app` and another with with staging URL.
87+
## Set behaviors
88+
89+
Behaviors in CloudFront enable control over the subpath logic. At a high level, we're looking to create the following logic.
9090

91-
## Set Behaviors
91+
- **If a user lands on /docs**, go to `[SUBDOMAIN].mintlify.dev`.
92+
- **If a user lands on any other page**, go the current landing page.
9293

93-
Behaviors in Cloudfront enables control over the subpath logic. At a high level, we're looking to create the following logic.
94+
1. Navigate to the "Behaviors" tab of your CloudFront distribution.
9495

95-
- **If a user lands on /docs**, go to `[SUBDOMAIN].mintlify.dev`
96-
- **If a user lands on any other page**, go the current landing page
96+
<Frame>
97+
![CloudFront "Behaviors" tab highlighted.](/images/cloudfront/behaviors.png)
98+
</Frame>
9799

98-
Select the **Create behavior** button and create the following behaviors.
100+
2. Select the **Create behavior** button and create the following behaviors.
99101

100102
### `/.well-known/*`
101103

102-
If you are deploying to Vercel, create a behavior for Vercel verification paths with a **Path pattern** of `/.well-known/*` and **Origin and origin groups** pointing to your main origin (the staging URL).
104+
Create behaviors for Vercel domain verification paths with a **Path pattern** of `/.well-known/*` and set **Origin and origin groups** to your docs URL.
103105

104-
For **Cache policy**, select `CachingDisabled` to ensure these verification requests pass through without caching.
106+
For "Cache policy", select **CachingDisabled** to ensure these verification requests pass through without caching.
105107

106-
### `/docs/*`
108+
<Frame>
109+
![CloudFront "Create behavior" page with a "Path pattern" of "/.well-known/*" and "Origin and origin groups" pointing to the staging URL.](/images/cloudfront/well-known-policy.png)
110+
</Frame>
111+
112+
<Info>
113+
If `.well-known/*` is too generic, it can be narrowed down to 2 behaviors at a minimum for Vercel:
114+
- `/.well-known/vercel/*` - Required for Vercel domain verification
115+
- `/.well-known/acme-challenge/*` - Required for Let's Encrypt certificate verification
116+
</Info>
107117

108-
Create a behavior with a **Path pattern** of `/docs/*` with **Origin and origin groups** pointing to the `.mintlify.dev` URL (in our case `acme.mintlify.dev`)
118+
### `/docs`
109119

110-
<Frame>![Cloudfront Behavior 1](/images/cloudfront/behavior-1.png)</Frame>
120+
Create a behavior with a **Path pattern** of `/docs` with **Origin and origin groups** pointing to the `.mintlify.dev` URL (in our case `acme.mintlify.dev`).
111121

112-
For **Cache policy**, select `CachingOptimized` and create behavior.
122+
- Set "Cache policy" to **CachingOptimized**.
123+
- In "Origin request policy", create an origin request policy named **VercelCloudFrontProxy**. That forwards the `Origin` and `CloudFront-Viewer-Address` headers.
113124

114-
### `/docs`
125+
<Frame>
126+
![CloudFront Create origin request policy page that forwards the `Origin` and `CloudFront-Viewer-Address` headers](/images/cloudfront/origin-request-policy.png)
127+
</Frame>
128+
129+
- Set Viewer Protocol Policy to **Redirect HTTP to HTTPS**
130+
131+
<Frame>
132+
![CloudFront "Create behavior" page with a "Path pattern" of "/docs/*" and "Origin and origin groups" pointing to the `acme.mintlify.dev` URL.](/images/cloudfront/behavior-1.png)
133+
</Frame>
134+
135+
### `/docs/*`
115136

116-
Create a behavior with a **Path pattern** of `/docs` and **Origin and origin groups** pointing to the same `.mintlify.dev` URL.
137+
Create a behavior with a **Path pattern** of `/docs/*` and **Origin and origin groups** pointing to the same `.mintlify.dev` URL.
117138

118-
<Frame>![Cloudfront Behavior 2](/images/cloudfront/behavior-2.png)</Frame>
139+
These settings should exactly match `/docs`. With the exception of the **Path pattern**.
140+
141+
- Set "Cache policy" to **CachingOptimized**.
142+
- Set "Origin request policy" to **VercelCloudFrontProxy**.
143+
- Set "Viewer protocol policy" to **Redirect HTTP to HTTPS**
119144

120145
### `Default (*)`
121146

122147
Lastly, we're going to edit the `Default (*)` behavior.
123148

124149
<Frame>
125-
![Cloudfront Behavior Default 1](/images/cloudfront/default-behavior-1.png)
150+
![A CloudFront distribution with the "Default (*)" behavior selected and the Edit button emphasized.](/images/cloudfront/default-behavior-1.png)
126151
</Frame>
127152

128-
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`).
153+
1. Change the default behavior's **Origin and origin groups** to the staging URL (in our case `mintlify-landing-page.vercel.app`).
129154

130155
<Frame>
131-
![Cloudfront Behavior Default 2](/images/cloudfront/default-behavior-2.png)
156+
![CloudFront "Edit behavior" page with the "Origin and origin groups" input field highlighted.](/images/cloudfront/default-behavior-2.png)
132157
</Frame>
133158

134-
Click on `Save changes`.
159+
2. Select **Save changes**.
160+
161+
### Check behaviors are set up correctly
162+
163+
If you follow the above steps, your behaviors should look like this:
164+
165+
<Frame>
166+
![CloudFront "Behaviors" page with 4 behaviors: `/docs/*`, `/docs`, `Default`, and `/.well-known/*`.](/images/cloudfront/all-behaviors.png)
167+
</Frame>
135168

136-
## Preview Distribution
169+
## Preview distribution
137170

138-
You can now test if your distribution is set up properly by going to the `General` tab and visiting the **Distribution domain name** URL.
171+
You can now test if your distribution is set up properly by going to the "General" tab and visiting the **Distribution domain name** URL.
139172

140173
<Frame>
141-
![Cloudfront Preview
142-
distribution](/images/cloudfront/preview-distribution.png)
174+
![CloudFront "General" tab with the "Distribution domain name" URL highlighted.](/images/cloudfront/preview-distribution.png)
143175
</Frame>
144176

145-
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.
177+
All pages should be directing to your main landing page, but if you append `/docs` to the URL, you should see it going to your Mintlify documentation instance.
146178

147-
## Connecting it with Route53
179+
## Connect with Route53
148180

149-
Now, we're going to bring the functionality of the Cloudfront distribution into your primary domain.
181+
Now, we're going to bring the functionality of the CloudFront distribution into your primary domain.
150182

151183
<Note>
152184
For this section, you can also refer to AWS's official guide on [Configuring
153185
Amazon Route 53 to route traffic to a CloudFront
154186
distribution](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-cloudfront-distribution.html#routing-to-cloudfront-distribution-config)
155187
</Note>
156188

157-
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`
189+
1. Navigate to [Route53](https://aws.amazon.com/route53) inside the AWS console.
190+
2. Navigate to the "Hosted zone" for your primary domain.
191+
3. Select **Create record**.
158192

159193
<Frame>
160-
![Route 53 create record](/images/cloudfront/route53-create-record.png)
194+
![Route 53 "Records" page with the "Create record" button emphasized.](/images/cloudfront/route53-create-record.png)
161195
</Frame>
162196

163-
Toggle `Alias` and then **Route traffic to** the `Alias to CloudFront distribution` option.
197+
4. Toggle `Alias` and then **Route traffic to** the `Alias to CloudFront distribution` option.
164198

165199
<Frame>
166-
![Route 53 create record alias](/images/cloudfront/create-record-alias.png)
200+
![Route 53 "Create record" page with the "Alias" toggle and the "Route traffic to" menu highlighted.](/images/cloudfront/create-record-alias.png)
167201
</Frame>
168202

169-
Click `Create records`.
203+
5. Select **Create records**.
170204

171205
<Note>
172206
You may need to remove the existing A record if one currently exists.
173207
</Note>
174208

175-
And voila! Your documentation will be served at `/docs` for your primary domain.
209+
Your documentation is now live at `/docs` for your primary domain.
176210

177211
<Propagating />

images/cloudfront/all-behaviors.png

56.8 KB
Loading

images/cloudfront/behavior-1.png

-79.3 KB
Loading
-169 KB
Loading

images/cloudfront/final-origins.png

69 KB
Loading

images/cloudfront/origin-name.png

-103 KB
Loading
69.2 KB
Loading
108 KB
Loading

0 commit comments

Comments
 (0)