Deploy at a subpath with AWS Route 53 and CloudFront
Deploy your Mintlify documentation at a subpath on AWS by combining Route 53 DNS routing, a CloudFront distribution, and cache behaviors.
To host your documentation at a subpath such as yoursite.com/docs using AWS Route 53 and CloudFront, configure your DNS provider to point to your CloudFront distribution.
Before configuring AWS, set your base path in your dashboard:
- Navigate to the Custom domain setup page in your dashboard.
- Enable the Host at toggle.
- Enter your domain.
- Enter your base path. For example,
/docsor/help. - Click Add domain.
Overview
Section titled “Overview”Route traffic to these paths with a Cache Policy of CachingDisabled:
/.well-known/acme-challenge/*- Required for Let's Encrypt certificate verification/.well-known/vercel/*- Required for domain verification/docs/*- Required for subpath routing/docs- Required for subpath routing/_mintlify/*- Required for API playground requests
Route traffic to these paths with a Cache Policy of CachingOptimized:
/mintlify-assets/*- Required for CSS, JavaScript, and faviconsDefault (*)- Your website's landing page
All Behaviors must have an origin request policy of AllViewerExceptHostHeader.
The behaviors for your subpath must allow all HTTP methods. CloudFront only allows GET and HEAD requests by default. This blocks the POST requests that Mintlify uses for analytics and other interactive features.
Create CloudFront distribution
Section titled “Create CloudFront distribution”- Navigate to CloudFront inside the AWS console.
- Click Create distribution.
- For the Origin domain, input
[SUBDOMAIN].mintlify.sitewhere[SUBDOMAIN]is your project's unique subdomain. - For "Web Application Firewall (WAF)," enable security protections.
- The remaining settings should be default.
- Click Create distribution.
Add default origin
Section titled “Add default origin”- After creating the distribution, navigate to the "Origins" tab.
- Find your staging URL that mirrors the main domain. This varies depending on your landing page host. For example, the Mintlify staging URL is mintlify-landing-page.vercel.app.
- Create a new Origin and add your staging URL as the "Origin domain."
You should now have two Origins: one with [SUBDOMAIN].mintlify.site and another with your staging URL.
Set behaviors
Section titled “Set behaviors”Behaviors in CloudFront enable control over the subpath logic. At a high level, you create the following logic:
- If a user lands on your custom subpath, go to
[SUBDOMAIN].mintlify.site. - If a user lands on any other page, go to the current landing page.
- Navigate to the "Behaviors" tab of your CloudFront distribution.
- Click the Create behavior button and create the following behaviors.
/.well-known/*
Section titled “/.well-known/*”Create behaviors for Vercel domain verification paths with a Path pattern of /.well-known/* and set Origin and origin groups to your docs URL.
For "Cache policy," select CachingDisabled to ensure these verification requests pass through without caching.
Your subpath
Section titled “Your subpath”Create a behavior with a Path pattern of your chosen subpath, for example /docs. Set Origin and origin groups to the .mintlify.site URL (for example, acme.mintlify.site).
- Set "Cache policy" to CachingDisabled.
- Set "Origin request policy" to AllViewerExceptHostHeader.
- Set "Viewer protocol policy" to Redirect HTTP to HTTPS.
- Set "Allowed HTTP methods" to GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE.
Your subpath with wildcard
Section titled “Your subpath with wildcard”Create a behavior with a Path pattern of your chosen subpath followed by /*, for example /docs/*, and Origin and origin groups pointing to the same .mintlify.site URL.
These settings should exactly match your base subpath behavior, with the exception of the Path pattern.
- Set "Cache policy" to CachingDisabled.
- Set "Origin request policy" to AllViewerExceptHostHeader.
- Set "Viewer protocol policy" to Redirect HTTP to HTTPS.
- Set "Allowed HTTP methods" to GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE.
/mintlify-assets/*
Section titled “/mintlify-assets/*”Create a behavior with a Path pattern of /mintlify-assets/* and set Origin and origin groups to the .mintlify.site URL. This path serves the CSS, JavaScript, and favicons for your documentation from the root of your domain.
- Set "Cache policy" to CachingOptimized.
- Set "Origin request policy" to AllViewerExceptHostHeader.
- Set "Viewer protocol policy" to Redirect HTTP to HTTPS.
/_mintlify/*
Section titled “/_mintlify/*”Create a behavior with a Path pattern of /_mintlify/* and set Origin and origin groups to the .mintlify.site URL. This path handles API playground requests from the root of your domain.
- Set "Cache policy" to CachingDisabled.
- Set "Origin request policy" to AllViewerExceptHostHeader.
- Set "Viewer protocol policy" to Redirect HTTP to HTTPS.
- Set "Allowed HTTP methods" to GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE.
Default (*)
Section titled “Default (*)”Edit the Default (*) behavior.
- Change the default behavior's Origin and origin groups to the staging URL (for example,
mintlify-landing-page.vercel.app). - Click Save changes.
Check that you set up behaviors correctly
Section titled “Check that you set up behaviors correctly”If you follow the preceding steps, your distribution has six behaviors:
/docs/*/docs/mintlify-assets/*/_mintlify/*/.well-known/*Default (*)
Confirm that each behavior points to the correct origin: the .mintlify.site URL for the docs, asset, API, and /.well-known/* paths, and your staging URL for Default (*).
Preview distribution
Section titled “Preview distribution”To test your distribution, go to the "General" tab and visit the Distribution domain name URL.
All pages should route to your main landing page. When you append your chosen subpath, for example /docs, the URL should serve your Mintlify documentation.
Connect with Route 53
Section titled “Connect with Route 53”Next, connect the CloudFront distribution to your primary domain.
Add your domain to the distribution
Section titled “Add your domain to the distribution”First, add your domain to the CloudFront distribution. Without an alternate domain name, CloudFront rejects requests that arrive through your domain.
- Open your distribution's "General" tab, then click Edit in the "Settings" section.
- Add your domain (for example,
yoursite.com) as an Alternate domain name (CNAME). - For "Custom SSL certificate," attach an AWS Certificate Manager (ACM) certificate that covers your domain.
Create the Route 53 record
Section titled “Create the Route 53 record”- Navigate to Route53 inside the AWS console.
- Navigate to the "Hosted zone" for your primary domain.
- Click Create record.
- Toggle
Aliasand then Route traffic to theAlias to CloudFront distributionoption. - Click Create records.
Your documentation is now live at your chosen subpath for your primary domain.