juzhiyuan commented on a change in pull request #5793:
URL: https://github.com/apache/apisix/pull/5793#discussion_r768272773
##
File path: docs/zh/latest/stream-proxy.md
##
@@ -72,7 +72,11 @@ curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -H
'X-API-KEY: edd1c9f03
## 更多 route 匹配选项
-我们可以添加更多的选项来匹配 route。
+我们可以添加更多的选项来匹配 route。目前 stream 路由配置支持 3 个字段进行过滤:
+
+- server_addr: 接受 L4 连接的 APISIX 服务器的地址。
Review comment:
```suggestion
- server_addr: 接受四层(流式)连接的 APISIX 服务器的地址。
```
##
File path: docs/zh/latest/stream-proxy.md
##
@@ -92,6 +96,68 @@ curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -H
'X-API-KEY: edd1c9f03
例子中 APISIX 会把服务器地址为 `127.0.0.1`, 端口为 `2000` 代理到上游地址 `127.0.0.1:1995`。
+让我们再举一个实际场景的例子:
+
+1. 将此配置放在 `config.yaml` 中
+
+ ```yaml
+ apisix:
+ stream_proxy: # TCP/UDP proxy
+ tcp: # TCP proxy address list
+ - 9100 # by default uses 0.0.0.0
+ - "127.0.0.10:9101"
+ ```
+
+2. 现在运行一个 mysql docker 容器并将端口 3306 暴露给主机
+
+ ```shell
+ $ docker run --name mysql -e MYSQL_ROOT_PASSWORD=toor -p 3306:3306 -d mysql
+ # check it using a mysql client that it works
+ $ mysql --host=127.0.0.1 --port=3306 -u root -p
+ Enter password:
+ Welcome to the MySQL monitor. Commands end with ; or \g.
+ Your MySQL connection id is 25
+ ...
+ mysql>
+ ```
+
+3. 现在我们将创建一个带有服务器过滤的 stream 路由:
+
+ ```shell
+ curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+ {
+ "server_addr": "127.0.0.10",
+ "server_port": 9101,
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:3306": 1
+ },
+ "type": "roundrobin"
+ }
+ }'
+ ```
+
+ 每当 APISIX 服务器 `127.0.0.10` 和端口 `9101` 收到连接时,它只会将请求转发到 mysql 上游。让我们测试这种行为:
Review comment:
```suggestion
每当 APISIX 服务器 `127.0.0.10` 和端口 `9101` 收到连接时,它只会将请求转发到 mysql 上游。我们测试一下:
```
##
File path: docs/zh/latest/stream-proxy.md
##
@@ -72,7 +72,11 @@ curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -H
'X-API-KEY: edd1c9f03
## 更多 route 匹配选项
-我们可以添加更多的选项来匹配 route。
+我们可以添加更多的选项来匹配 route。目前 stream 路由配置支持 3 个字段进行过滤:
+
+- server_addr: 接受 L4 连接的 APISIX 服务器的地址。
+- server_port: 接受 L4 连接的 APISIX 服务器的端口。
Review comment:
```suggestion
- server_port: 接受四层(流式)连接的 APISIX 服务器的端口。
```
##
File path: docs/zh/latest/stream-proxy.md
##
@@ -72,7 +72,11 @@ curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -H
'X-API-KEY: edd1c9f03
## 更多 route 匹配选项
-我们可以添加更多的选项来匹配 route。
+我们可以添加更多的选项来匹配 route。目前 stream 路由配置支持 3 个字段进行过滤:
+
+- server_addr: 接受 L4 连接的 APISIX 服务器的地址。
+- server_port: 接受 L4 连接的 APISIX 服务器的端口。
+- remote_addr: 发出请求的客户地址。
Review comment:
```suggestion
- remote_addr: 发出请求的客户端地址。
```
##
File path: docs/zh/latest/admin-api.md
##
@@ -985,11 +985,11 @@ $ curl
"http://127.0.0.1:9080/apisix/admin/plugins/key-auth" -H 'X-API-KEY:
| 名字 | 可选项| 类型 | 说明 | 示例 |
| | --| | --| -|
-| remote_addr | 可选 | IP/CIDR | 客户端 IP 地址 | "127.0.0.1/32" 或 "127.0.0.1"
|
-| server_addr | 可选 | IP/CIDR | 服务端 IP 地址 | "127.0.0.1/32" 或 "127.0.0.1"
|
-| server_port | 可选 | 整数 | 服务端端口 | 9090 |
-| sni | 可选 | Host | 服务器名称指示| "test.com" |
| upstream | 可选 | Upstream | 启用的 Upstream 配置,详见
[Upstream](architecture-design/upstream.md) | |
| upstream_id | 可选 | Upstream | 启用的 upstream id,详见
[Upstream](architecture-design/upstream.md) | |
+| remote_addr | 可选 | IP/CIDR | 过滤选项:如果客户端 IP 匹配,则转发到上游 | "127.0.0.1/32"
或 "127.0.0.1" |
+| server_addr | 可选 | IP/CIDR | 过滤选项:如果 APISIX 服务器 IP 与 server_addr
匹配,则转发到上游 | "127.0.0.1/32" 或 "127.0.0.1" |
+| server_port | 可选 | 整数 | 过滤选项:如果 APISIX 服务器 port 与 server_port
匹配,则转发到上游 | 9090 |
+| sni | 可选 | Host | 服务器名称指示| "test.com" |
Review comment:
https://github.com/apache/apisix/pull/5783/files#diff-de04caa451665cf4137cdde9804ab1f53de08dedd08fc3d51a2143bb18d46f71R987
##
File path: docs/zh/latest/stream-proxy.md
##
@@ -92,6 +96,68 @@ curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -H
'X-API-KEY: edd1c9f03
例子中 APISIX 会把服务器地址为 `127.0.0.1`, 端口为 `2000` 代理到上游地址 `127.0.0.1:1995`。
+让我们再举一个实际场景的例子:
+
+1. 将此配置放在 `config.yaml` 中
+
+ ```yaml
+ apisix:
+ stream_proxy: # TCP/UDP proxy
+ tcp: # TCP proxy address list
+ - 9100 # by default uses 0.0.0.0
+ - "127.0.0.10:9101"
+ ```
+
+2. 现在运行一个 mysql docker 容器并将端口 3306 暴露给主机
+
+ ```shell
+ $ docker run --name mysql -e MYSQL_ROOT_PASSWORD=toor -p 3306:3306 -d mysql
+ # check it using a mysql client that it works
+ $ mysql --host=127.0.0.1 --port=3306 -u root -p
+ Enter password:
+ Welcome to the MySQL monitor. Commands end with ; or \g.
+ Your MySQL connection id is 25
+ ...
+ mysql>
+ ```
+
+3.