Skip to content

Commit

Permalink
docs: allow to use environment variables for limit-count plugin setti…
Browse files Browse the repository at this point in the history
…ngs (#10804)
  • Loading branch information
smileby authored Jan 12, 2024
1 parent 52c368d commit 686a0de
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/zh/latest/plugins/limit-count.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,37 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \
}'
```

此外,插件中的属性值可以引用 APISIX 中的密钥。APISIX 当前支持两种存储密钥的方式 - [环境变量和 HashiCorp Vault](../terminology/secret.md)
如果您设置了环境变量 `REDIS_HOST``REDIS_PASSWORD` ,如下所示,您可以在插件配置中使用它们:

```shell
curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/index.html",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"policy": "redis",
"redis_host": "$ENV://REDIS_HOST",
"redis_port": 6379,
"redis_password": "$ENV://REDIS_PASSWORD",
"redis_database": 1,
"redis_timeout": 1001
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}'
```

## 测试插件

在上文提到的配置中,其限制了 60 秒内请求只能访问 2 次,可通过如下 `curl` 命令测试请求访问:
Expand Down

0 comments on commit 686a0de

Please sign in to comment.