mirror of
https://github.com/mintlify/docs.git
synced 2026-09-14 13:35:46 +08:00
086a2640e8
Co-authored-by: locadex-agent[bot] <217277504+locadex-agent[bot]@users.noreply.github.com>
71 lines
3.3 KiB
Plaintext
71 lines
3.3 KiB
Plaintext
---
|
||
title: "Vercel"
|
||
description: "在 Vercel 的子路径下部署文档。"
|
||
keywords: ["vercel.json", "Vercel 部署", "重写规则配置", "子路径路由"]
|
||
---
|
||
|
||
import { VercelJsonGenerator } from "/snippets/zh/vercel-json-generator.mdx";
|
||
|
||
配置你的 `vercel.json` 文件,将主域名的请求代理到文档所在的子路径。
|
||
|
||
|
||
<div id="verceljson-file">
|
||
## vercel.json 文件
|
||
</div>
|
||
|
||
`vercel.json` 文件用于配置项目的构建和部署方式。它位于项目的根目录,用来控制部署的各个方面,包括路由、重定向、请求头以及构建设置。
|
||
|
||
我们会在你的 `vercel.json` 文件中使用 `rewrites` 配置,将来自主域名的请求代理到你的文档站点。
|
||
|
||
Rewrites 会在不更改浏览器中 URL 的情况下,将传入请求映射到不同的目标。当有人访问 `yoursite.com/docs` 时,Vercel 会在内部从 `your-subdomain.mintlify.dev/docs` 获取内容,但用户在浏览器中仍然看到的是 `yoursite.com/docs`。这与重定向不同,后者会将用户直接带到另一个完全不同的 URL。
|
||
|
||
<div id="configuration">
|
||
## 配置
|
||
</div>
|
||
|
||
<div id="host-at-docs-subpath">
|
||
### 在 `/docs` 子路径下托管
|
||
</div>
|
||
|
||
1. 在控制台中前往 [Custom domain setup](https://dashboard.mintlify.com/settings/deployment/custom-domain)。
|
||
2. 将 **Host at `/docs`** 开关切换到开启状态。
|
||
<Frame>
|
||
<img alt="Custom domain setup 页面截图。Host at `/docs` 开关已打开,并用橙色矩形高亮显示。" src="/images/subpath/toggle-light.png" className="block dark:hidden" />
|
||
<img alt="Custom domain setup 页面截图。Host at `/docs` 开关已打开,并用橙色矩形高亮显示。" src="/images/subpath/toggle-dark.png" className="hidden dark:block" />
|
||
</Frame>
|
||
3. 输入你的域名。
|
||
4. 选择 **Add domain**。
|
||
5. 在你的 `vercel.json` 文件中添加以下重写规则。将 `[subdomain]` 替换为你的子域,可以在控制台 URL 的末尾找到。例如,`dashboard.mintlify.com/your-organization/your-subdomain` 的子域标识符是 `your-subdomain`。
|
||
|
||
```json
|
||
{
|
||
"rewrites": [
|
||
{
|
||
"source": "/docs",
|
||
"destination": "https://[subdomain].mintlify.dev/docs"
|
||
},
|
||
{
|
||
"source": "/docs/:match*",
|
||
"destination": "https://[subdomain].mintlify.dev/docs/:match*"
|
||
}
|
||
]
|
||
}
|
||
```
|
||
|
||
`rewrites` 配置会将你域名上的 `/docs` 子路径映射到你的文档站点上的 `/docs` 子路径。
|
||
|
||
- **`source`**:你域名上触发重写的路径模式。
|
||
- **`destination`**:请求应被代理到的位置。
|
||
- **`:match*`**:用于捕获子路径之后任意路径片段的通配符。
|
||
|
||
如需了解更多信息,请参阅 Vercel 文档中的 [Configuring projects with vercel.json: Rewrites](https://vercel.com/docs/projects/project-configuration#rewrites)。
|
||
|
||
<div id="host-at-custom-subpath">
|
||
### 在自定义子路径下托管
|
||
</div>
|
||
|
||
要使用自定义子路径(任何非 `/docs` 的路径),你必须在存储库中组织文档文件,使其与子路径结构相匹配。比如,如果你的文档托管在 `yoursite.com/help`,那么文档文件必须位于 `help/` 目录中。
|
||
|
||
使用下面的生成器来创建你的 rewrites(重写规则)配置。将这些重写规则添加到你的 `vercel.json` 文件中。
|
||
|
||
<VercelJsonGenerator /> |