> For the complete documentation index, see [llms.txt](https://www.axisnow.io/zh/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.axisnow.io/zh/docs/edge/policies/upstream-control.md).

# 回源控制

按规则改写回源地址与请求并控制连接缓冲和重试

回源控制插件决定边缘怎样把请求发往源站：发往哪个地址、用什么协议和 Host、URL 和请求头改成什么样，以及连接复用、缓冲和失败重试。域侧的回源配置是基线，本插件按规则对部分请求做改写和调优。

## 六个动作 <a href="#actions" id="actions"></a>

<table data-search="false"><thead><tr><th width="190">动作</th><th>作用</th><th width="150">默认规则</th></tr></thead><tbody><tr><td><a href="/zh/docs/edge/policies/upstream-control/configuration.md#origin-rewrite">回源配置改写</a></td><td>改写源地址、协议、端口、Host 与 SNI</td><td>未配置</td></tr><tr><td><a href="/zh/docs/edge/policies/upstream-control/configuration.md#url-rewrite">URL 改写</a></td><td>改写回源的路径和查询串，客户端地址和缓存 Key 不变</td><td>未配置</td></tr><tr><td><a href="/zh/docs/edge/policies/upstream-control/configuration.md#header-rewrite">回源请求 Header 改写</a></td><td>添加、设置或删除回源请求头</td><td>未配置</td></tr><tr><td><a href="/zh/docs/edge/policies/upstream-control/configuration.md#buffer">缓冲区设置</a></td><td>请求体是否收完再回源，源响应是否在边缘缓冲</td><td>都开启</td></tr><tr><td><a href="/zh/docs/edge/policies/upstream-control/configuration.md#retry">回源重试</a></td><td>回源失败时重试的触发条件和次数</td><td>网络错误和 502 Bad Gateway、503 Service Unavailable、504 Gateway Timeout，最多 10 次</td></tr><tr><td><a href="/zh/docs/edge/policies/upstream-control/configuration.md#connection">连接复用与超时</a></td><td>源连接池与连接、读取、发送超时</td><td>连接池 30，超时 10 / 3600 / 3600 秒</td></tr></tbody></table>

它是[多动作配置类插件](/zh/docs/edge/policies/rules.md#rulesets)：每个动作各取序号最小的命中规则，一条规则可以只配其中几个动作。内置一条不可退订的默认规则排在最后，条件为**任意**，配了缓冲区、重试和连接三个动作；三个改写动作只在需要时添加规则。TCP 转发端点只有回源重试生效。

## 边界 <a href="#boundaries" id="boundaries"></a>

<table data-search="false"><thead><tr><th width="260">功能</th><th>配置位置</th></tr></thead><tbody><tr><td>域的源地址、回源协议、端口、Host，按路径或按端口回源</td><td><a href="/zh/docs/edge/endpoints/domains.md#origin-configuration">端点 › 域 › 回源配置</a>，本插件的改写覆盖它</td></tr><tr><td>一组源地址及其负载均衡</td><td><a href="/zh/docs/edge/endpoints/origin-address.md">端点 › 源地址</a>，回源配置改写可以直接引用</td></tr><tr><td>让客户端跳转到新地址</td><td><a href="/zh/docs/edge/policies/request-processing.md#redirect">请求处理 › URL 重定向</a></td></tr><tr><td>回源时传递真实客户端 IP</td><td><a href="/zh/docs/edge/policies/real-ip.md#forward">真实客户端 IP › 转发</a></td></tr><tr><td>回源 TLS 证书校验与客户端证书</td><td><a href="/zh/docs/edge/policies/ssl-tls/configuration.md#origin-tls-verify">SSL/TLS › 源证书校验</a></td></tr></tbody></table>

## 最佳实践 <a href="#best-practices" id="best-practices"></a>

* **流式接口和大文件上传按路径关闭缓冲**：SSE、大模型对话等逐段输出的接口关闭源响应缓冲区，否则客户端整段一次收到或超时；大文件上传的路径关闭请求体缓冲区，否则上传要等边缘收完才回源。各用一条只覆盖这些路径的规则，关闭响应缓冲的请求不写入缓存。
* **不能重复提交的接口禁用重试**：支付、下单等接口默认已不重试非幂等请求，但 GET 形式的扣减类接口不在其中，按路径加一条禁用重试的规则。
* **按 worker 数估算源站连接**：连接池大小是每个 worker 的值，源站看到的空闲连接约为该值乘以边缘的 worker 数再乘以边缘数，源站的连接上限要按此设置。
* **改写源地址时核对 Host**：回源配置改写不改变回源 Host，新源站按 Host 分发时要在同一条规则里显式填写。

## 下一步 <a href="#next-steps" id="next-steps"></a>

<table data-search="false"><thead><tr><th width="160">页面</th><th>内容</th></tr></thead><tbody><tr><td><a href="/zh/docs/edge/policies/upstream-control/configuration.md">配置项</a></td><td>六个动作的取值、默认值与注意事项</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.axisnow.io/zh/docs/edge/policies/upstream-control.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
