参数
有关所有插件均可使用的配置项,请参阅插件通用配置。
count
time_window
rules
array[object]
按顺序应用的限流规则数组。
rules与顶层count和time_window二选一配置,不能同时使用。count
time_window
key
header_prefix
string
插入到该规则限流响应头中的前缀。例如,
foo会生成X-foo-RateLimit-Limit、X-foo-RateLimit-Remaining和X-foo-RateLimit-Reset。
key_type
string
默认值:
var有效值:
var、var_combination或constant键的类型。
如果
key_type为var,则key被解释为变量。如果
key_type为var_combination,则key被解释为变量组合。如果
key_type为constant,则key被解释为常量。key
string
默认值:
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
默认值:
503有效值:
介于 200 和 599 之间(含边界值)
当请求因超过阈值而被拒绝时返回的 HTTP 状态码。
rejected_msg
string
有效值:
任意非空字符串
当请求因超过阈值而被拒绝时返回的响应体。
policy
string
默认值:
local有效值:
local、redis或redis-cluster速率限制计数器的策略。如果为
local,则计数器存储在本地内存中。如果为redis,则计数器存储在 Redis 实例中。如果为redis-cluster,则计数器存储在 Redis 集群中。allow_degradation
boolean
默认值:
false如果为 true,则在插件或其依赖项不可用时,允许网关继续处理请求而不使用该插件。
show_limit_quota_header
boolean
默认值:
true如果为 true,则包含以下速率限制响应头:
X-RateLimit-Limit显示总配额。X-RateLimit-Remaining显示剩余配额。X-RateLimit-Reset显示计数器重置前的剩余秒数。
group
string
有效值:
非空
插件的
groupID,同一group的路由可以共享相同的速率限制计数器。redis_host
string
Redis 节点的地址。当
policy为redis时必填。redis_port
integer
默认值:
6379有效值:
大于或等于 1
Redis 节点的端口。当
policy为redis时使用。redis_username
string
如果使用 Redis ACL,则为 Redis 的用户名。如果你使用传统的认证方法
requirepass,则只需配置redis_password。当policy为redis时使用。redis_password
string
Redis 节点的密码。当
policy为redis或redis-cluster时使用。redis_database
integer
默认值:
0有效值:
大于或等于 0
Redis 中的数据库编号。当
policy为redis时使用。redis_ssl
boolean
默认值:
false如果为 true,则在
policy为redis时使用 SSL 连接到 Redis。redis_ssl_verify
boolean
默认值:
false如果为 true,则在
policy为redis时验证服务器 SSL 证书。redis_timeout
integer
默认值:
1000有效值:
大于或等于 1
Redis 超时时间(毫秒)。当
policy为redis或redis-cluster时使用。redis_keepalive_timeout
integer
默认值:
10000有效值:
大于或等于 1000
当
policy为redis或redis-cluster时,Redis 的保活超时时间,单位为毫秒。此参数在 API7 企业版 3.9.x 系列中自 3.9.16 起可用,在 3.10.x 系列中自 3.10.3 起可用,并且在 APISIX 中自 3.17.0 起可用。
redis_keepalive_pool
integer
默认值:
100有效值:
大于或等于 1
当
policy为redis或redis-cluster时,Redis 的保活连接池大小。此参数在 API7 企业版 3.9.x 系列中自 3.9.16 起可用,在 3.10.x 系列中自 3.10.3 起可用,并且在 APISIX 中自 3.17.0 起可用。
redis_cluster_nodes
array[string]
Redis 集群节点列表,至少包含两个地址。当
policy为redis-cluster时必填。redis_cluster_name
string
Redis 集群的名称。当
policy为redis-cluster时必填。redis_cluster_ssl
boolean
默认值:
false如果为 true,则在
policy为redis-cluster时使用 SSL 连接到 Redis 集群。redis_cluster_ssl_verify
boolean
默认值:
false如果为 true,则在
policy为redis-cluster时验证服务器 SSL 证书。