Files
mintlify__docs/zh/deploy/reverse-proxy.mdx
locadex-agent[bot] 83476f17a8 docs(locadex): add translations (#2998)
Co-authored-by: locadex-agent[bot] <217277504+locadex-agent[bot]@users.noreply.github.com>
2026-01-30 10:39:47 -08:00

189 lines
6.9 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "反向代理"
description: "配置自定义反向代理以提供文档服务。"
keywords: ["反向代理配置", "nginx", "代理路由", "请求头转发"]
---
<Note>
反向代理配置仅适用于 [Enterprise 方案](https://mintlify.com/pricing?ref=reverse-proxy)。
</Note>
要通过自定义反向代理提供文档服务,你需要配置路由规则、缓存策略和请求头转发。
实施反向代理时,请留意可能出现的 domain 验证、SSL 证书签发、认证流程、性能以及 Analytics 跟踪等问题。
<div id="routing-configuration">
## 路由配置
</div>
按以下缓存策略将这些路径代理到你的 Mintlify 子域:
| Path | Destination | Caching |
| --------------------------------- | ------------------------------- | ------------- |
| `/.well-known/acme-challenge/*` | `<your-subdomain>.mintlify.app` | 不缓存 |
| `/.well-known/vercel/*` | `<your-subdomain>.mintlify.app` | 不缓存 |
| `/.well-known/skills/*` | `<your-subdomain>.mintlify.app` | 不缓存 |
| `/skill.md` | `<your-subdomain>.mintlify.app` | 不缓存 |
| `/mintlify-assets/_next/static/*` | `<your-subdomain>.mintlify.app` | 启用缓存 |
| `/_mintlify/*` | `<your-subdomain>.mintlify.app` | 不缓存 |
| `/*` | `<your-subdomain>.mintlify.app` | 不缓存 |
| `/` | `<your-subdomain>.mintlify.app` | 不缓存 |
<div id="required-header-configuration">
## 必需的请求头配置
</div>
按以下请求头要求配置你的反向代理:
- **Origin**:包含目标子域 `<your-subdomain>.mintlify.app`
- **X-Forwarded-For**:保留客户端 IP 信息
- **X-Forwarded-Proto**:保留原始协议(HTTP/HTTPS)
- **X-Real-IP**:转发真实的客户端 IP 地址
- **User-Agent**:转发用户代理
<Warning>
确保不要转发 `Host` 请求头
</Warning>
<div id="example-nginx-configuration">
## Nginx 配置示例
</div>
```nginx
server {
listen 80;
server_name <your-domain>.com;
# Let's Encrypt verification paths
location ~ ^/\.well-known/acme-challenge/ {
proxy_pass https://<your-subdomain>.mintlify.app;
proxy_set_header Origin <your-subdomain>.mintlify.app;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header User-Agent $http_user_agent;
# Disable caching for verification paths
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# Vercel verification paths
location ~ ^/\.well-known/vercel/ {
proxy_pass https://<your-subdomain>.mintlify.app;
proxy_set_header Origin <your-subdomain>.mintlify.app;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header User-Agent $http_user_agent;
# Disable caching for verification paths
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# AI skills paths
location ^~ /.well-known/skills/ {
proxy_pass https://<your-subdomain>.mintlify.app;
proxy_set_header Origin <your-subdomain>.mintlify.app;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header User-Agent $http_user_agent;
# Disable caching for verification paths
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# Skill manifest
location = /skill.md {
proxy_pass https://<your-subdomain>.mintlify.app;
proxy_set_header Origin <your-subdomain>.mintlify.app;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header User-Agent $http_user_agent;
# Disable caching for skill manifest
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# Static assets with caching
location ~ ^/mintlify-assets/_next/static/ {
proxy_pass https://<your-subdomain>.mintlify.app;
proxy_set_header Origin <your-subdomain>.mintlify.app;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header User-Agent $http_user_agent;
# Enable caching for static assets
add_header Cache-Control "public, max-age=86400";
}
# Mintlify-specific paths
location ~ ^/_mintlify/ {
proxy_pass https://<your-subdomain>.mintlify.app;
proxy_set_header Origin <your-subdomain>.mintlify.app;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header User-Agent $http_user_agent;
# 禁用 Mintlify 路径的缓存
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# Root path
location = / {
proxy_pass https://<your-subdomain>.mintlify.app;
proxy_set_header Origin <your-subdomain>.mintlify.app;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header User-Agent $http_user_agent;
# Disable caching for dynamic content
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# All other documentation paths
location / {
proxy_pass https://<your-subdomain>.mintlify.app;
proxy_set_header Origin <your-subdomain>.mintlify.app;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header User-Agent $http_user_agent;
# Disable caching for dynamic content
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
}
```
<div id="troubleshooting">
## 疑难解答
</div>
<div id="404-error">
### 404 错误
</div>
**现象**:文档可以加载,但部分功能不可用。API 调用失败。
**原因**:转发了 `Host` 头,或缺少 `Origin` 头。
**解决方案**:
- 停止转发 `Host` 头
- 将 `Origin` 头设置为 `<your-subdomain>.mintlify.app`
<div id="performance-issues">
### 性能问题
</div>
**表现**:页面加载缓慢,出现布局位移。
**原因**:缓存配置不正确。
**解决方案**:仅对 `/mintlify-assets/_next/static/*` 路径启用缓存。