跳到主要内容

参数

有关所有插件均可使用的配置项,请参阅插件通用配置

  • count

    integer | string


    有效值:

    大于 0


    给定时间间隔内允许累计的最大 GraphQL 查询深度。未配置 rules 时必填。当配置为字符串时,该值可以使用内置变量

  • time_window

    integer | string


    有效值:

    大于 0


    与限流 count 对应的时间间隔,单位为秒。未配置 rules 时必填。当配置为字符串时,该值可以使用内置变量

  • rules

    array[object]


    按顺序应用的限流规则数组。rules 与顶层 counttime_window 二选一配置,不能同时使用。

    • count

      integer | string


      必填


      有效值:

      大于 0


      规则的 time_window 内允许累计的最大 GraphQL 查询深度。当配置为字符串时,该值可以使用内置变量

    • time_window

      integer | string


      必填


      有效值:

      大于 0


      与规则 count 对应的时间间隔,单位为秒。当配置为字符串时,该值可以使用内置变量

    • key

      string


      必填


      用于计数请求的 Key。支持内置变量组合,每个变量必须以美元符号($)为前缀。如果 Key 无法解析,则不会应用该规则。

    • header_prefix

      string


      插入到该规则限流响应头中的前缀。例如,foo 会生成 X-foo-RateLimit-LimitX-foo-RateLimit-RemainingX-foo-RateLimit-Reset

  • key_type

    string


    默认值:var


    有效值:

    varvar_combinationconstant


    键的类型。

    如果 key_typevar,则 key 被解释为变量。

    如果 key_typevar_combination,则 key 被解释为变量组合。

    如果 key_typeconstant,则 key 被解释为常量。

  • key

    string


    默认值:remote_addr


    用于计数请求的键。

    如果 key_typevar,则 key 被解释为变量。变量不需要以美元符号($)作为前缀。查看内置变量以获取可用变量。

    如果 key_typevar_combination,则 key 被解释为变量组合。所有变量都应以美元符号($)作为前缀。例如,要将 key 配置为使用两个请求头 custom-acustom-b 的组合,key 应配置为 $http_custom_a $http_custom_b

    如果 key_typeconstant,则 key 被解释为常量值。

  • rejected_code

    integer


    默认值:503


    有效值:

    介于 200 和 599 之间(含边界值)


    当请求因超过阈值而被拒绝时返回的 HTTP 状态码。

  • rejected_msg

    string


    有效值:

    任意非空字符串


    当请求因超过阈值而被拒绝时返回的响应体。

  • policy

    string


    默认值:local


    有效值:

    localredisredis-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


    有效值:

    非空


    插件的 group ID,同一 group 的路由可以共享相同的速率限制计数器。

  • redis_host

    string


    Redis 节点的地址。当 policyredis 时必填。

  • redis_port

    integer


    默认值:6379


    有效值:

    大于或等于 1


    Redis 节点的端口。当 policyredis 时使用。

  • redis_username

    string


    如果使用 Redis ACL,则为 Redis 的用户名。如果你使用传统的认证方法 requirepass,则只需配置 redis_password。当 policyredis 时使用。

  • redis_password

    string


    Redis 节点的密码。当 policyredisredis-cluster 时使用。

  • redis_database

    integer


    默认值:0


    有效值:

    大于或等于 0


    Redis 中的数据库编号。当 policyredis 时使用。

  • redis_ssl

    boolean


    默认值:false


    如果为 true,则在 policyredis 时使用 SSL 连接到 Redis。

  • redis_ssl_verify

    boolean


    默认值:false


    如果为 true,则在 policyredis 时验证服务器 SSL 证书。

  • redis_timeout

    integer


    默认值:1000


    有效值:

    大于或等于 1


    Redis 超时时间(毫秒)。当 policyredisredis-cluster 时使用。

  • redis_keepalive_timeout

    integer


    默认值:10000


    有效值:

    大于或等于 1000


    policyredisredis-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


    policyredisredis-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 集群节点列表,至少包含两个地址。当 policyredis-cluster 时必填。

  • redis_cluster_name

    string


    Redis 集群的名称。当 policyredis-cluster 时必填。

  • redis_cluster_ssl

    boolean


    默认值:false


    如果为 true,则在 policyredis-cluster 时使用 SSL 连接到 Redis 集群。

  • redis_cluster_ssl_verify

    boolean


    默认值:false


    如果为 true,则在 policyredis-cluster 时验证服务器 SSL 证书。