apisix/doc/plugins/proxy-mirror-cn.md

94 lines
2.4 KiB
Markdown
Raw Normal View History

<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->
[English](proxy-mirror.md)
# proxy-mirror
代理镜像插件,该插件提供了镜像客户端请求的能力。
注:镜像请求返回的响应会被忽略。
### 参数
|名称 |必须|类型|描述|
|------- |-----|------|------|
|host|是|string|指定镜像服务地址例如http://127.0.0.1:9797地址中需要包含 schema http或https不能包含 URI 部分)|
### 示例
#### 启用插件
示例1为特定路由启用 `proxy-mirror` 插件:
```shell
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"plugins": {
"proxy-mirror": {
"host": "http://127.0.0.1:9797"
}
},
"upstream": {
"nodes": {
"127.0.0.1:1999": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}'
```
测试:
```shell
$ curl http://127.0.0.1:9080/hello -i
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Length: 12
Connection: keep-alive
Server: APISIX web server
Date: Wed, 18 Mar 2020 13:01:11 GMT
Last-Modified: Thu, 20 Feb 2020 14:21:41 GMT
hello world
```
> 由于指定的 mirror 地址是127.0.0.1:9797所以验证此插件是否已经正常工作需要在端口为9797的服务上确认例如我们可以通过 python 启动一个简单的 server python -m SimpleHTTPServer 9797。
#### 禁用插件
移除插件配置中相应的 JSON 配置可立即禁用该插件,无需重启服务:
```shell
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"uri": "/hello",
"plugins": {},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1999": 1
}
}
}'
```
这时该插件已被禁用。