Skip to main content

Host at a subpath

AWS Route 53 + CloudFront

Host your NookDocs site at yourdomain.com/docs with a CloudFront behavior + function.

On AWS, a CloudFront distribution for acme.com routes the /docs* path to a NookDocs origin, and a CloudFront Function tags requests with the headers we need. See Host at a subpath for the overall model.

Subpath hosting lives in the customer's CloudFront config — there is no NookDocs API. Add the project origin (<slug>.nookdocs.site, HTTPS only, empty origin path so /docs is kept), a behavior on path pattern /docs*, and a viewer-request CloudFront Function that sets two request headers: x-nookdocs-host (the public host) and x-nookdocs-base-path (e.g. /docs). NookDocs then prefixes every link, asset, and canonical with that base path. Use an Origin request policy that forwards host + headers (AllViewer) and CachingDisabled or a low TTL so edits appear quickly.

1. Add the NookDocs origin

In your CloudFront distribution → Origins → Create origin:

FieldValue
Origin domainacme.nookdocs.site (your project subdomain)
ProtocolHTTPS only
Origin path(leave empty — the /docs path is kept)

2. Add a behavior for /docs*

Behaviors → Create behavior:

FieldValue
Path pattern/docs*
Originthe NookDocs origin above
Viewer protocol policyRedirect HTTP to HTTPS
Allowed methodsGET, HEAD (+ OPTIONS)
Cache policyCachingDisabled (or a short TTL)
Origin request policyAllViewer (forward host + headers)

This makes CloudFront send acme.com/docs/* to NookDocs while everything else keeps hitting your default origin.

3. Tag requests with a CloudFront Function

Functions → Create function (viewer request), attach it to the /docs* behavior:

function handler(event) {
  var request = event.request;
  request.headers["x-nookdocs-host"] = { value: "acme.com" };
  request.headers["x-nookdocs-base-path"] = { value: "/docs" };
  return request;
}

The dashboard shows this function pre-filled — Settings → Domains → Show proxy setup.

4. Route 53

Point acme.com (A/AAAA alias) at the CloudFront distribution as usual. No record points at NookDocs directly — CloudFront fronts everything.

Verify

curl -sI https://acme.com/docs | grep -i content-type
curl -s  https://acme.com/docs/llms.txt | head -1

Notes

  • Use CachingDisabled (or low TTL) on the /docs* behavior so doc edits appear quickly; NookDocs already sends sensible cache headers.

  • Sending a CSP via CloudFront response headers? See CSP.

Was this page helpful?

Last updated August 11, 2026