参数
请参阅 插件通用配置 了解所有插件可用的配置选项。
该插件支持使用 env:// 前缀引用环境变量中的敏感参数值,或使用 secret:// 前缀引用 Secret 管理器(如 HashiCorp Vault 的 KV 密钥引擎 中的值。更多信息,请参阅环境变量中的插件和Secrets。
count
integer
required
vaild vaule:
大于 0
给定时间间隔内允许的最大请求数。
time_window
integer
required
vaild vaule:
大于 0
与限速
count相对应的时间间隔(以秒为单位)。key_type
string
default:
varvaild vaule:
var,var_combination, orconstant密钥类型。
如果
key_type为var,则key将被解释为变量。如果
key_type为var_combination,则key将被解释为变量组合。如果
key_type为constant,则key将被解释为常量。key
string
default:
remote_addr用于计数请求的密钥。
如果
key_type为var,则key将被解释为变量。变量不需要以美元符号($)作为前缀。请参阅内置变量以获取可用变量。如果
key_type为var_combination,则key将被解释为变量组合。所有变量都应以美元符号($)作为前缀。例如,要配置key使用两个请求头custom-a和custom-b的组合,则key应配置为$http_custom_a $http_custom_b。如果
key_type为constant,则key将被解释为常量值。rejected_code
integer
default:
503vaild vaule:
介于 200 到 599 之间(含边界值)
当请求因超过阈值而被拒绝时返回的 HTTP 状态码。
rejected_msg
string
vaild vaule:
任意非空字符串
当请求因超过阈值而被拒绝时返回的响应体。
policy
string
default:
localvaild vaule:
local,redis, orredis-cluster限速计数器的策略。如果为
local,则计数器存储在本地内存中。如果为redis,则计数器存储在 Redis 实例上。如果为redis-cluster,则计数器存储在 Redis 集群中。allow_degradation
boolean
default:
false如果为 true,则在插件或其依赖项不可用时允许 APISIX 继续处理请求(不使用该插件)。
show_limit_quota_header
boolean
default:
true如果为 true,则包含限速响应头。具体为:
X-RateLimit-Limit显示总配额。X-RateLimit-Remaining显示剩余配额。X-RateLimit-Reset显示计数器重置前的秒数。
group
string
vaild vaule:
non-empty
插件的
groupID,以便同一group的路由可以共享相同的限速计数器。redis_host
string
Redis 节点的地址。当
policy为redis时必填。redis_port
integer
default:
6379vaild vaule:
大于或等于 1
当
policy为redis时 Redis 节点的端口。redis_username
string
如果使用 Redis ACL,则为 Redis 用户名。如果你使用传统的身份验证方法
requirepass,请仅配置redis_password。当policy为redis时使用。redis_password
string
当
policy为redis或redis-cluster时 Redis 节点的密码。redis_database
integer
default:
0vaild vaule:
大于或等于 0
当
policy为redis时 Redis 中的数据库编号。redis_ssl
boolean
default:
false如果为 true,则在
policy为redis时使用 SSL 连接到 Redis。redis_ssl_verify
boolean
default:
false如果为 true,则在
policy为redis时验证服务器 SSL 证书。redis_timeout
integer
default:
1000vaild vaule:
大于或等于 1
当
policy为redis或redis-cluster时的 Redis 超时值(以毫秒为单位)。redis_keepalive_timeout
integer
default:
10000vaild vaule:
大于或等于 1000
当
policy为redis或redis-cluster时的 Redis keepalive 超时时间(以毫秒为单位)。此参数自 APISIX 3.15.0 版本起可 用,尚未在 API7 企业版中提供。
redis_keepalive_pool
integer
default:
100vaild vaule:
大于或等于 1
当
policy为redis或redis-cluster时的 Redis keepalive 连接池大小。此参数自 APISIX 3.15.0 版本起可用,尚未在 API7 企业版中提供。
redis_cluster_nodes
array[string]
Redis 集群节点列表,至少包含两个地址。当
policy为redis-cluster时必填。redis_cluster_name
string
Redis 集群的名称。当
policy为redis-cluster时必填。redis_cluster_ssl
boolean
default:
false如果为 true,则在
policy为redis-cluster时使用 SSL 连接到 Redis 集群。redis_cluster_ssl_verify
boolean
default:
false如果为 true,则在
policy为redis-cluster时验证服务器 SSL 证书。sync_interval
number
default:
-1vaild vaule:
大于或等于 0.1,或默认值 -1
将计数器数据同步到 Redis 的频率。仅在企业版中可用。
sync_interval值应小于time_window。值为1会导致每秒同步一次计数器数据。值为-1不会改变同步行为,即每次请求都会同步计数器数据。