title: client-control keywords:
client-control 插件能够通过设置客户端请求体大小的上限来动态地控制 NGINX 处理客户端的请求。
:::info 重要
此插件需要 APISIX 在 APISIX-Base 环境上运行。更多信息请参考 apisix-build-tools。
:::
| 名称 | 类型 | 必选项 | 有效值 | 描述 |
|---|---|---|---|---|
| max_body_size | integer | 否 | [0,...] | 动态设置 client_max_body_size 的大小。 |
以下示例展示了如何在指定路由上启用 client-control 插件,并设置 max_body_size:
curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { "uri": "/index.html", "plugins": { "client-control": { "max_body_size" : 1 } }, "upstream": { "type": "roundrobin", "nodes": { "127.0.0.1:1980": 1 } } }'
启用插件后,使用 curl 命令请求该路由:
curl -i http://127.0.0.1:9080/index.html -d '123'
因为在配置插件时设置了 max_body_size 为 1,所以返回的 HTTP 响应头中如果带有 413 状态码,则表示插件生效:
HTTP/1.1 413 Request Entity Too Large ... <html> <head><title>413 Request Entity Too Large</title></head> <body> <center><h1>413 Request Entity Too Large</h1></center> <hr><center>openresty</center> </body> </html>
当你需要禁用该插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务:
curl http://127.0.0.1:9180/apisix/admin/routes/1 \ -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { "uri": "/index.html", "upstream": { "type": "roundrobin", "nodes": { "127.0.0.1:1980": 1 } } }'