# 配置文件

API7 网关在 `/conf` 目录中提供以下配置文件：

* `config-default.yaml`：包含默认配置值和供参考的内联注释。
* `config.yaml`：用于用户定义的自定义配置。

默认情况下，API7 网关从 `config-default.yaml` 加载设置，**不应修改该文件**。此文件用作参考，并定义了系统的默认行为。

要自定义配置，请在 `config.yaml` 中添加或覆盖设置。`config.yaml` 中定义的任何配置均优先于 `config-default.yaml` 中的相应值。

## 自定义配置[​](#自定义配置 "自定义配置的直接链接")

API7 网关仅在启动时加载配置文件。要应用配置更改，请修改 `config.yaml`（覆盖 `config-default.yaml` 中的默认设置）并重新加载网关。

如果在 Docker 中运行网关，配置文件位于 `/usr/local/apisix/conf/config.yaml`。

修改配置后，重新加载网关容器以使更改生效：

```
docker exec {gateway_container_name} apisix reload
```

通过受控的滚动重启应用共享内存容量变更，并验证报告的容量。重启会清空内存状态，包括指标和计数器。对于 Helm 部署，请修改用于生成 `config.yaml` 的 Chart values。有关容量规划、监控和恢复的指导，请参阅[共享内存容量规划](https://docs.apiseven.com/api7-gateway/configure-and-manage/shared-dict-sizing.md)。

## 默认配置[​](#默认配置 "默认配置的直接链接")

以下快照完整呈现 API7 网关 3.10.9 发布版本的 `config-default.yaml`。使用其他补丁版本时，请以该网关版本实际安装的 `config-default.yaml` 为准。

启动时，网关先加载已发布的默认配置，再用本地 `config.yaml` 覆盖相应值。连接控制面的网关随后会将控制面下发的配置叠加到合并后的本地配置之上。

控制面提供服务发现设置、SSL 启用状态与加密盐、数据加密设置和网关组密钥环、消费者与开发者代理设置，以及遥测设置。已连接的网关还会禁用本地 Admin API。

config-default.yaml

```
#

# Licensed to the Apache Software Foundation (ASF) under one or more

# contributor license agreements.  See the NOTICE file distributed with

# this work for additional information regarding copyright ownership.

# The ASF licenses this file to You under the Apache License, Version 2.0

# (the "License"); you may not use this file except in compliance with

# the License.  You may obtain a copy of the License at

#

#     http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.

#

# 请勿修改此文件！

# 如需设置某个配置项，请在 conf/config.yaml 文件中

# 设置新的值。

#



apisix:

  # node_listen: 9080               # APISIX 监听端口

  node_listen:                      # 这种写法支持配置多个端口

    - 9080

  #   - port: 9081

  #     enable_http2: true          # 如果未设置，默认值为 `false`。

  #   - ip: 127.0.0.2               # 指定 IP。如果未设置，默认值为 `0.0.0.0`。

  #     port: 9082

  #     enable_http2: true

  #   - port: 9082

  #     backlog: 1024               # 设置 listen() 调用中的 backlog 参数，用于限制

                                    # 待处理连接队列的最大长度。

                                    # 默认情况下，FreeBSD、DragonFly BSD 和 macOS 上的 backlog 为 -1，

                                    # 其他平台上为 511。

  enable_admin: true

  enable_dev_mode: false            # 如果设置为 true，则将 NGINX worker_processes 设置为 1

  enable_reuseport: true            # 如果设置为 true，则启用 NGINX SO_REUSEPORT 开关。

  show_upstream_status_in_response_header: false # 为 true 时将所有上游状态写入 `X-APISIX-Upstream-Status`，否则只写入 5xx 状态码

  enable_ipv6: true



  #proxy_protocol:                  # Proxy Protocol 配置

  #  listen_http_port: 9181         # HTTP 的 Proxy Protocol 端口，与 node_listen 和 admin_listen 不同。

                                    # 该端口只能接收带 Proxy Protocol 的 HTTP 请求，而 node_listen 与 admin_listen

                                    # 只能接收普通 HTTP 请求。如果启用 Proxy Protocol，必须使用该端口

                                    # 接收带 Proxy Protocol 的 HTTP 请求

  #  listen_https_port: 9182        # HTTPS 的 Proxy Protocol 端口

  #  enable_tcp_pp: true            # 在每个 stream_proxy.tcp 端口接收 Proxy Protocol，作为

                                    # 默认行为；可通过 stream_proxy.tcp 条目中的

                                    # `proxy_protocol` 字段逐端口覆盖。

  #  enable_tcp_pp_to_upstream: true # 在每个 stream_proxy.tcp 端口向上游发送 Proxy Protocol。

                                    # 作为默认行为；可通过 stream_proxy.tcp 条目中的

                                    # `proxy_protocol_to_upstream` 字段逐端口覆盖。

  enable_server_tokens: true        # 是否在 Server 响应头中显示 APISIX 版本号。

                                    # 默认启用。



  # 用于加载第三方代码和/或覆盖内置代码的配置。

  extra_lua_path: ""                # 扩展 lua_package_path 以加载第三方代码

  extra_lua_cpath: ""               # 扩展 lua_package_cpath 以加载第三方代码

  lua_module_hook: "agent.hook"  # 用于向 APISIX 注入第三方代码的 hook 模块



  proxy_cache:                      # 代理缓存配置

    cache_ttl: 10s                  # 如果上游未指定缓存时间，则使用该磁盘默认缓存时间

    zones:                          # 缓存参数

      - name: disk_cache_one        # 缓存名称，管理员可在 Admin API 中

                                    # 通过名称指定使用哪个缓存（disk|memory）

        memory_size: 50m            # 共享内存大小。disk 策略用于存储缓存索引，

                                    # memory 策略用于存储缓存内容（disk|memory）

        disk_size: 1G               # 磁盘大小，用于存储缓存数据（disk）

        disk_path: /tmp/disk_cache_one  # 缓存数据存储路径（disk）

        cache_levels: "1:2"           # 缓存层级（disk）

      #- name: disk_cache_two

      #  memory_size: 50m

      #  disk_size: 1G

      #  disk_path: "/tmp/disk_cache_two"

      #  cache_levels: "1:2"

      - name: memory_cache

        memory_size: 50m



  delete_uri_tail_slash: false    # 删除 URI 末尾的 '/'

  # servlet 中的 URI 规范化与 RFC 略有不同。

  # 参见 https://github.com/jakartaee/servlet/blob/master/spec/src/main/asciidoc/servlet-spec-body.adoc#352-uri-path-canonicalization，

  # Tomcat 会使用该规范化方式。

  # 如果在匹配 URI 路径时需要兼容 servlet，请启用该选项。

  normalize_uri_like_servlet: false

  # 为 true 时，路由匹配保留 URL 编码的斜杠（%2F），使其

  # 被视为路径参数的一部分，而不是路径分隔符。此设置仅

  # 影响路由匹配；转发给上游的请求仍使用

  # APISIX 常规的已解码 URI。此选项全局生效，会改变所有

  # 路由的匹配方式。

  match_uri_encoded_slash: false

  # 匹配 `post_arg.*` 路由条件时读取的请求体大小上限（MB），

  # 适用于 JSON 和 multipart 请求；设置为 0 禁用此限制。

  max_post_args_readable_size: 64

  router:

    http: radixtree_uri         # radixtree_uri：按 URI 匹配路由（基于 radixtree）

                                  # radixtree_host_uri：按 host + URI 匹配路由（基于 radixtree）

                                  # radixtree_uri_with_parameter：类似 radixtree_uri，但会匹配带参数的 URI，

                                  # 详情参见 https://github.com/api7/lua-resty-radixtree/#parameters-in-path

                                  # 中的说明。

    ssl: radixtree_sni          # radixtree_sni：按 SNI 匹配路由（基于 radixtree）

  #stream_proxy:                  # TCP/UDP 代理

  #  only: true                   # 仅使用 stream 代理，不启用 HTTP 相关功能

  #  tcp:                         # TCP 代理端口列表

  #    - addr: 9100

  #      tls: true

  #    - addr: "127.0.0.1:9101"

  #      proxy_protocol: true              # 仅在此端口接收 Proxy Protocol

  #      proxy_protocol_to_upstream: true  # 仅在此端口向上游发送 Proxy Protocol；

  #                                        # 两者都会覆盖全局 proxy_protocol.enable_tcp_pp* 默认值

  #    - addr: 9500

  #      tls_passthrough: true      # 原样转发 TLS 流，根据预读 ClientHello 中的 SNI

  #                                 # 选择上游。后端终止握手，因此负载检查型流插件

  #                                 # （mqtt-proxy、xrpc、redis）和客户端证书验证

  #                                 # 均不适用。此端口上的所有连接都会透传，

  #                                 # 不受 stream_route 配置影响。

  #    - addr: 9501

  #      tls: true                  # 两个开关同时启用会打开混合端口：监听器仅预读，

  #      tls_passthrough: true      # 每个连接遵循其匹配的 stream_route 上的 `tls_passthrough`

  #                                 # （默认为 false）。会增加一次内部转发，因此整个端口均透传时，

  #                                 # 请优先使用专用 tls_passthrough 端口。

  #                                 # 混合端口拒绝 proxy_protocol_to_upstream，因为上游 PROXY 头

  #                                 # 会将内部 Unix socket 作为目标地址。

  #                                 # 请改用专用监听器。

  #                                 # 该次转发使用 logs/ 下的 Unix socket，并通过 PROXY 协议头

  #                                 # 声明客户端地址，因此能连接这些 socket 的本地用户

  #                                 # 可以伪造该地址。应限制不可信本地用户访问 logs/，

  #                                 # 这与现有 stream_worker_events.sock 的

  #                                 # 安全要求相同。

  #    - "2000-2100"              # 端口范围（NGINX 原生支持）

  #    - addr: "3000-3100"        # 以表形式指定端口范围

  #    - addr: "127.0.0.1:4000-4100"  # 以表形式指定地址和端口范围

  #      tls: true

  #  udp:                         # UDP 代理端口列表

  #    - 9200

  #    - "127.0.0.1:9201"

  #    - "9300-9310"              # 端口范围

  #dns_resolver:                  # 如果未设置，则从 `/etc/resolv.conf` 读取

  #  - 1.1.1.1

  #  - 8.8.8.8

  #dns_resolver_valid: 30         # 如果提供，则覆盖有效记录的 TTL。单位为秒。

  resolver_timeout: 5             # 解析器超时时间

  enable_resolv_search_opt: true  # 启用 resolv.conf 中的 search 选项

  ssl:

    enable: true

    listen:                       # APISIX HTTPS 监听端口。

      - port: 9443

        enable_http2: true

    #   - ip: 127.0.0.3           # 指定 IP。如果未设置，默认值为 `0.0.0.0`。

    #     port: 9445

    #     enable_http2: true

    #   - port: 9446

    #     backlog: 1024           # 设置 listen() 调用中的 backlog 参数，用于限制

                                  # 待处理连接队列的最大长度。

                                  # 默认情况下，FreeBSD、DragonFly BSD 和 macOS 上的 backlog 为 -1，

                                  # 其他平台上为 511。

    # ssl_trusted_combined_path: /usr/local/apisix/conf/cert/.ssl_trusted_combined.pem # 所有受信任证书会合并到单个文件中

    ssl_trusted_certificate: system              # 指定以逗号分隔的受信任 CA 列表。取值可以是 "system"（使用系统可用的 CA 证书），也可以是

                                                # PEM 格式受信任 CA 证书的文件路径，

                                                # 用于在 APISIX 与外部服务（例如 etcd）

                                                # 进行 SSL/TLS 握手时验证证书

    ssl_protocols: TLSv1.2 TLSv1.3

    ssl_ciphers: ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384

    ssl_session_tickets: false              # 默认禁用 ssl_session_tickets，因为启用它会使完全前向保密失效。

                                            #  ref: https://github.com/mozilla/server-side-tls/issues/135



    key_encrypt_salt:             # 如果未设置，会将原始 SSL 密钥保存到 etcd。

      - edd1c9f0985e76a2          # 如果设置，key_encrypt_salt 应为字符串数组，每个字符串为 16 字节；它会使用 AES-128-CBC 加密 SSL 密钥

                                  # !!! 保存 SSL 后不要修改它，否则无法解密已保存的 SSL 密钥 !!

                                  # 仅使用第一个密钥加密，并按数组顺序解密。



    #fallback_sni: "my.default.domain"      # 如果设置，当客户端在握手期间未发送 SNI 时，将改用 fallback SNI

  enable_control: true

  #control:

  #  ip: 127.0.0.1

  #  port: 9090

  disable_sync_configuration_during_start: false  # 安全退出。功能稳定后移除此项



  # 该时间用于区分 worker 是首次启动，还是崩溃后重启；单位为秒。

  worker_startup_time_threshold: 60



  data_encryption:                # 在插件 schema 中添加 `encrypt_fields = { $field },` 以启用加密

    enable: false                 # 如果未设置，默认值为 `false`。

    keyring:

      - qeddd145sfvddff3          # 如果未设置，会将原始值保存到 etcd。

                                  # 如果设置，keyring 应为字符串数组，每个字符串为 16 字节；它会使用 AES-128-CBC 加密字段

                                  # !!! 加密后不要修改它，否则无法解密已保存的字段 !!

                                  # 仅使用第一个密钥加密，并按数组顺序解密。



  # status:                       # 启用后，APISIX 会提供 `/status` 和 `/status/ready` 端点

  #   ip: 127.0.0.1               # 如果 APISIX 已成功启动并正常运行，/status 端点会返回 200 状态码

  #   port: 7085                  # 如果配置的 etcd（dp_manager）均不可用，/status/ready 端点会返回 503 状态码



  # disable_upstream_healthcheck: false # 健康检查的全局开关。默认为 false。

                                        # 设置为 true 时，会覆盖所有上游健康检查配置并全局禁用健康检查。



# trusted_addresses:              # 配置后，APISIX 会信任列表中的 IP/CIDR

#   - 127.0.0.1                   # 发来请求中的 `X-Forwarded-*` 头。

#   - 172.18.0.0/16               # 注意：未配置或请求来自不可信地址时，

                                  # APISIX 会用可信值覆盖 `X-Forwarded-Proto/Host/Port`，

                                  # 并清除 `Forwarded` 头。对于 `X-Forwarded-For`：

                                  # 配置了 `trusted_addresses` 且请求来自不可信

                                  # 地址时，会重置该头，使上游仅看到 APISIX 观测到的

                                  # 连接 IP；未配置 `trusted_addresses` 时，

                                  # 保留该头并追加连接 IP（兼容性默认行为）。

                                  # 覆盖发生在 NGINX 配置层，早于任何 Lua 代码执行。

                                  # Lua 始终读取覆盖后的值，`core.request.header` 和

                                  # `ctx.var.http_x_forwarded_*` 都如此。配置层的行为不同：

                                  # 在访问日志格式、`if` 或 `map` 中使用 `$http_x_forwarded_proto`、

                                  # `$http_x_forwarded_host`、`$http_x_forwarded_port` 或 `$http_forwarded`，

                                  # 读取的是执行覆盖时缓存的值，

                                  # 即客户端发送的原始值。请使用 `$scheme`、

                                  # `$var_x_forwarded_host` 和 `$var_x_forwarded_port` 读取

                                  # 覆盖后的值。`$http_x_forwarded_for` 不受影响。

                                  # 客户端发送的原始值保存在 `$original_x_forwarded_proto`、

                                  # `$original_x_forwarded_host`、`$original_x_forwarded_port`、

                                  # `$original_x_forwarded_for` 和 `$original_forwarded` 中，可从

                                  # 日志格式读取，或在 Lua 中通过 `ctx.var.original_x_forwarded_*` 读取。

                                  # 这些值沿用之前的变量名，因此读取它们的插件

                                  # 不受影响。对 X-Forwarded-For 尤其需要注意：

                                  # 配置了信任边界且对端不在边界内时，

                                  # 该头会被清除，而不是覆盖。



  # 微调密钥等功能使用的 LRU 缓存参数

  lru:

    secret:

      ttl: 300 # 秒

      count: 512

      neg_ttl: 60

      neg_count: 512



  tracing: false                    # 启用完整请求生命周期追踪（SSL/SNI、rewrite、access、header_filter、body_filter 和 log）。

                                    # 禁用时，OpenTelemetry 为每个请求只采集一个 Span。



nginx_config:                     # 用于渲染模板并生成 nginx.conf 的配置

  #user: root                     # 指定 worker 进程的执行用户。

                                  # 只有主进程以超级用户权限运行时，"user" 指令才有意义。

                                  # 如果不是 root 用户，默认值为当前用户。

  error_log: logs/error.log

  error_log_level:  warn          # warn,error

  worker_processes: auto          # 如果要在容器中使用多个核心，可以通过环境变量 "APISIX_WORKER_PROCESSES" 注入 CPU 数量

  enable_cpu_affinity: false      # 默认禁用 CPU 亲和性；如果 APISIX 部署在物理机上，可以启用并正常工作。

  worker_rlimit_nofile: 20480     # worker 进程可打开的文件数量，应大于 worker_connections

  worker_shutdown_timeout: 240s   # worker 进程优雅关闭的超时时间



  max_pending_timers: 16384       # 如果看到 "too many pending timers" 错误，请增大该值

  max_running_timers: 4096        # 如果看到 "lua_max_running_timers are not enough" 错误，请增大该值



  event:

    worker_connections: 10620

  #envs:                          # 允许获取环境变量列表

  #  - TEST_ENV



  meta:

    lua_shared_dict:

      prometheus-metrics: 128m

      standalone-config: 10m         # 仅在 Admin API 提供以下独立模式配置时声明

      standalone-status: 1m          # 跟踪各 worker 应用的摘要，

                                     # 独立模式配置（role: traditional +

                                     # config_provider: yaml + enable_admin)

      status-report: 1m              # 在同一模式下支持 /status/ready：每个

                                     # worker 记录自己是否已加载配置



  stream:

    #real_ip_from:                   # https://nginx.org/en/docs/stream/ngx_stream_realip_module.html#set_real_ip_from

    #  - 192.168.1.0/24              # 已知会发送正确 PROXY 协议头的可信地址。来自可信地址的

                                     # 连接携带入站 PROXY 协议头时，

                                     # 客户端地址会替换为头中的地址。仅对接收

                                     # PROXY 协议的端口生效。默认为空，

                                     # 因此客户端地址始终为直接连接的对端地址。

    enable_access_log: false         # 是否启用访问日志，默认为 false

    access_log: logs/access_stream.log

    access_log_format: "$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time"

                                            # 可访问 http://nginx.org/en/docs/varindex.html 创建自定义日志格式

    access_log_format_escape: default       # 允许在变量中设置 json 或 default 字符转义

    metrics_zone_size: 1m            # 供 apisix_stream_active_connections 和

                                     # apisix_stream_bandwidth 使用的共享内存，由 prometheus 流插件读取，

                                     # 仅在 APISIX-Base 上分配。每个流监听地址占一个槽，

                                     # 该地址上出现的每个 service 标签另占一个槽；1m

                                     # 约容纳 750 个槽。占满后，新 service 的会话

                                     # 仅计入监听地址的总数。

    lua_shared_dict:

      etcd-cluster-health-check-stream: 10m

      lrucache-lock-stream: 10m

      plugin-limit-conn-stream: 10m

      worker-events-stream: 10m

      tars-stream: 1m

      config-stream: 5m

      nacos-stream: 64m



  # 由于用户可以在 snippet 中添加任意配置，

  # 用户需要自行检查配置

  # 是否与 APISIX 冲突。

  main_configuration_snippet: |

    # 将自定义 NGINX main 配置添加到 nginx.conf。

    # 配置应保持良好缩进！

  http_configuration_snippet: |

    # 将自定义 NGINX http 配置添加到 nginx.conf。

    # 配置应保持良好缩进！

  http_server_configuration_snippet: |

    # 将自定义 NGINX http server 配置添加到 nginx.conf。

    # 配置应保持良好缩进！

  http_server_location_configuration_snippet: |

    # 将自定义 NGINX http server location 配置添加到 nginx.conf。

    # 配置应保持良好缩进！

  http_admin_configuration_snippet: |

    # 将自定义 NGINX admin server 配置添加到 nginx.conf。

    # 配置应保持良好缩进！

  http_end_configuration_snippet: |

    # 将自定义 NGINX http end 配置添加到 nginx.conf。

    # 配置应保持良好缩进！

  stream_configuration_snippet: |

    # 将自定义 NGINX stream 配置添加到 nginx.conf。

    # 配置应保持良好缩进！



  http:

    enable_access_log: true         # 是否启用访问日志，默认为 true

    access_log: logs/access.log

    # 可用变量：

    # request_type: traditional_http / ai_chat / ai_stream

    # llm_time_to_first_token: 向 AI 服务器发起请求至收到首个 Token 的时长

    # llm_prompt_tokens: 提示词 Token 数量

    # llm_completion_tokens: 补全 Token 数量

    access_log_format: "$remote_addr - $remote_user [$time_local] $http_host \"$request_line\" $status $body_bytes_sent $request_time \"$http_referer\" \"$http_user_agent\" $upstream_addr $upstream_status $upstream_response_time \"$upstream_scheme://$upstream_host$upstream_uri\" \"$apisix_request_id\""

    access_log_format_escape: default       # 允许在变量中设置 json 或 default 字符转义

    keepalive_timeout: 60s          # keep-alive 客户端连接在服务端保持打开的超时时间。

    client_header_timeout: 60s      # 读取客户端请求头的超时时间，超时后向客户端返回 408 (Request Time-out) 错误

    client_body_timeout: 60s        # 读取客户端请求正文的超时时间，超时后向客户端返回 408 (Request Time-out) 错误

    client_max_body_size: 0         # 允许的客户端请求正文最大大小。

                                    # 如果超过该值，会向客户端返回 413 (Request Entity Too Large) 错误。

                                    # 注意，与 NGINX 不同，默认情况下我们不限制正文大小。



    send_timeout: 10s              # 向客户端传输响应的超时时间。超时后会关闭连接

    underscores_in_headers: "on"   # 默认允许在客户端请求头字段中使用下划线

    real_ip_header: X-Real-IP      # http://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_header

    real_ip_recursive: "off"       # http://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_recursive

    real_ip_from:                  # http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from

      - 127.0.0.1

      - "unix:"

    custom_lua_shared_dict:       # 向 NGINX 配置文件添加自定义共享缓存

    #  ipc_shared_dict: 100m       # 自定义共享缓存，格式为 `cache-key: cache-size`

      config: 5m

      kubernetes: 64m

      nacos: 64m

      consul: 64m



    # 与被代理的 HTTPS 服务器建立连接时，

    # 启用或禁用通过 TLS Server Name Indication 扩展（SNI，RFC 6066）传递服务器名称。

    proxy_ssl_server_name: true

    upstream:

      keepalive: 320                # 设置每个 worker 进程缓存中保留的到上游服务器的最大空闲 keepalive 连接数。

                                    # 超过该数量时，将关闭最近最少使用的连接。

      keepalive_requests: 1000      # 设置一个 keepalive 连接可以处理的最大请求数。

                                    # 达到最大请求数后，连接会关闭。

      keepalive_timeout: 60s        # 设置到上游服务器的空闲 keepalive 连接保持打开的超时时间。

    charset: utf-8                  # 将指定字符集添加到 "Content-Type" 响应头字段中，参见

                                    # http://nginx.org/en/docs/http/ngx_http_charset_module.html#charset

    variables_hash_max_size: 2048   # 设置变量哈希表的最大大小。



    lua_shared_dict:

      internal-status: 10m

      plugin-limit-req: 10m

      plugin-limit-count: 10m

      plugin-limit-conn: 10m

      plugin-limit-conn-redis-cluster-slot-lock: 1m

      plugin-graphql-limit-count: 10m

      plugin-graphql-limit-count-reset-header: 10m

      plugin-saml-auth-replay: 10m

      plugin-ai-rate-limiting: 10m

      plugin-ai-rate-limiting-reset-header: 10m

      upstream-healthcheck: 10m

      upstream-slow-start: 10m

      worker-events: 10m

      lrucache-lock: 10m

      balancer-ewma: 10m

      balancer-ewma-locks: 10m

      balancer-ewma-last-touched-at: 10m

      plugin-limit-req-redis-cluster-slot-lock: 1m

      plugin-limit-count-redis-cluster-slot-lock: 1m

      plugin-limit-count-advanced: 10m

      plugin-limit-count-advanced-redis-cluster-slot-lock: 1m

      tracing_buffer: 32m

      plugin-api-breaker: 10m

      etcd-cluster-health-check: 10m

      discovery: 1m

      jwks: 1m

      introspection: 10m

      access-tokens: 1m

      tars: 1m

      cas-auth: 10m

      status_report: 1m

      api-calls-for-portal: 64m



#discovery:                       # 服务发现中心

#  dns:

#    servers:

#      - "127.0.0.1:8600"         # 使用你的 DNS 服务器真实地址

#    order:                       # 解析时尝试不同 DNS 记录类型的顺序

#      - last                     # "last" 会尝试该主机名上一次成功使用的类型。

#      - SRV

#      - A

#      - AAAA

#      - CNAME

#  eureka:

#    host:                        # 可以定义同一 Eureka 集群的多个 Eureka 主机地址。

#      - "http://127.0.0.1:8761"

#    prefix: /eureka/

#    fetch_interval: 30           # 默认为 30s

#    weight: 100                  # 节点默认权重

#    timeout:

#      connect: 2000              # 默认为 2000ms

#      send: 2000                 # 默认为 2000ms

#      read: 5000                 # 默认为 5000ms

#  nacos:

#    host:

#      - "http://${username}:${password}@${host1}:${port1}"

#    prefix: "/nacos/v1/"

#    fetch_interval: 30    # 默认为 30 秒

#    weight: 100           # 默认为 100

#    timeout:

#      connect: 2000       # 默认为 2000 ms

#      send: 2000          # 默认为 2000 ms

#      read: 5000          # 默认为 5000 ms

#  consul_kv:

#    servers:

#      - "http://127.0.0.1:8500"

#      - "http://127.0.0.1:8600"

#    prefix: "upstreams"

#    skip_keys:                    # 如果需要跳过特定键

#      - "upstreams/unused_api/"

#    timeout:

#      connect: 2000               # 默认为 2000 ms

#      read: 2000                  # 默认为 2000 ms

#      wait: 60                    # 默认为 60 秒

#    weight: 1                     # 默认为 1

#    fetch_interval: 3             # 默认为 3 秒，仅在 keepalive: false 方式下生效

#    keepalive: true               # 默认为 true，使用长轮询方式查询 consul 服务器

#    sort_type: "origin"           # 默认为 origin

#    default_server:               # 未命中时可以定义默认服务器

#      host: "127.0.0.1"

#      port: 20999

#      metadata:

#        fail_timeout: 1           # 默认为 1 ms

#        weight: 1                 # 默认为 1

#        max_fails: 1              # 默认为 1

#    dump:                         # 如有需要，注册节点更新时可以转储到文件

#       path: "logs/consul_kv.dump"

#       expire: 2592000            # 单位为秒，此处为 30 天

#  consul:

#    servers:                          # 确保这些 consul 服务器中的服务名称唯一

#      - "http://127.0.0.1:8500"       # `http://127.0.0.1:8500` 和 `http://127.0.0.1:8600` 是不同集群

#      - "http://127.0.0.1:8600"

#    skip_services:                    # 如果需要跳过特定服务

#      - "service_a"                   # `consul` 服务是默认跳过服务

#    timeout:

#      connect: 2000               # 默认为 2000 ms

#      read: 2000                  # 默认为 2000 ms

#      wait: 60                    # 默认为 60 秒

#    weight: 1                     # 默认为 1

#    fetch_interval: 3             # 默认为 3 秒，仅在 keepalive: false 方式下生效

#    keepalive: true               # 默认为 true，使用长轮询方式查询 consul 服务器

#    default_service:               # 未命中时可以定义默认服务器

#      host: "127.0.0.1"

#      port: 20999

#      metadata:

#        fail_timeout: 1           # 默认为 1 ms

#        weight: 1                 # 默认为 1

#        max_fails: 1              # 默认为 1

#    dump:                         # 如有需要，注册节点更新时可以转储到文件

#       path: "logs/consul.dump"

#       expire: 2592000            # 单位为秒，此处为 30 天

#       load_on_init: true         # 默认为 true，初始化时加载 consul 转储文件

#  kubernetes:

# ### Kubernetes 服务发现同时支持单集群和多集群模式

# ### 适用于服务分布在单个或多个 Kubernetes 集群中的场景。

#

# ### 单集群模式 ###

#    service:

#      schema: https                     # Kubernetes API Server 协议，可选值 [http, https]，默认为 https

#      host: ${KUBERNETES_SERVICE_HOST}  # Kubernetes API Server 主机，可选值 [ipv4, ipv6, 域名, 环境变量]，默认为 ${KUBERNETES_SERVICE_HOST}

#      port: ${KUBERNETES_SERVICE_PORT}  # Kubernetes API Server 端口，可选值 [端口号, 环境变量]，默认为 ${KUBERNETES_SERVICE_PORT}

#    client:

# # ServiceAccount Token 或 token_file 路径

#      token_file: ${KUBERNETES_CLIENT_TOKEN_FILE}

#      # token: |-

#       # eyJhbGciOiJSUzI1NiIsImtpZCI6Ikx5ME1DNWdnbmhQNkZCNlZYMXBsT3pYU3BBS2swYzBPSkN3ZnBESGpkUEEif

#       # 6Ikx5ME1DNWdnbmhQNkZCNlZYMXBsT3pYU3BBS2swYzBPSkN3ZnBESGpkUEEifeyJhbGciOiJSUzI1NiIsImtpZCI

# # Kubernetes 服务发现插件支持使用 namespace_selector

# # 可以使用 [equal, not_equal, match, not_match] 之一过滤命名空间

#    namespace_selector:

# # 仅保存命名空间等于 default 的端点

#      equal: default

# # 仅保存命名空间不等于 default 的端点

#      #not_equal: default

# # 仅保存命名空间匹配 [default, ^my-[a-z]+$] 之一的端点

#      #match:

#      #- default

#      #- ^my-[a-z]+$

# # 仅保存命名空间不匹配 [default, ^my-[a-z]+$] 之一的端点

#      #not_match:

#      #- default

#      #- ^my-[a-z]+$

# # Kubernetes 服务发现插件支持使用 label_selector

# # label_selector 表达式请参见 https://kubernetes.io/docs/concepts/overview/working-with-objects/labels

#    label_selector: |-

#      first="a",second="b"

# # 预留 Lua 共享内存大小，1m 内存约可存储 1000 个端点

#    shared_size: 1m # 默认为 1m

# ### 单集群模式 ###

#

# ### 多集群模式 ###

#  - id: release  # 指向集群的自定义名称，模式为 ^[a-z0-9]{1,8}

#    service:

#      schema: https                     # Kubernetes API Server 协议，可选值 [http, https]，默认为 https

#      host: ${KUBERNETES_SERVICE_HOST}  # Kubernetes API Server 主机，可选值 [ipv4, ipv6, 域名, 环境变量]

#      port: ${KUBERNETES_SERVICE_PORT}  # Kubernetes API Server 端口，可选值 [端口号, 环境变量]

#    client:

# # ServiceAccount Token 或 token_file 路径

#      token_file: ${KUBERNETES_CLIENT_TOKEN_FILE}

#      # token: |-

#       # eyJhbGciOiJSUzI1NiIsImtpZCI6Ikx5ME1DNWdnbmhQNkZCNlZYMXBsT3pYU3BBS2swYzBPSkN3ZnBESGpkUEEif

#       # 6Ikx5ME1DNWdnbmhQNkZCNlZYMXBsT3pYU3BBS2swYzBPSkN3ZnBESGpkUEEifeyJhbGciOiJSUzI1NiIsImtpZCI

# # Kubernetes 服务发现插件支持使用 namespace_selector

# # 可以使用 [equal, not_equal, match, not_match] 之一过滤命名空间

#    namespace_selector:

# # 仅保存命名空间等于 default 的端点

#      equal: default

# # 仅保存命名空间不等于 default 的端点

#      #not_equal: default

# # 仅保存命名空间匹配 [default, ^my-[a-z]+$] 之一的端点

#      #match:

#      #- default

#      #- ^my-[a-z]+$

# # 仅保存命名空间不匹配 [default, ^my-[a-z]+$] 之一的端点

#      #not_match:

#      #- default

#      #- ^my-[a-z]+$

# # Kubernetes 服务发现插件支持使用 label_selector

# # label_selector 表达式请参见 https://kubernetes.io/docs/concepts/overview/working-with-objects/labels

#    label_selector: |-

#      first="a",second="b"

# # 预留 Lua 共享内存大小，1m 内存约可存储 1000 个端点

#    shared_size: 1m # 默认为 1m

# ### 多集群模式 ###



graphql:

  max_size: 1048576               # GraphQL 的最大大小限制，单位为字节，默认为 1MiB



plugins:                          # 插件列表（按优先级排序）

#  - error-log-collect              # 优先级： 12100000

#  - exit-transformer               # 优先级： 9999999

  - real-ip                        # 优先级： 23000

  # - toolset                          # 优先级： 22901

  - ai                             # 优先级： 22900

  - client-control                 # 优先级： 22000

  - proxy-buffering                # 优先级： 21991

  - proxy-control                  # 优先级： 21990

  - request-id                     # 优先级： 12015

  - zipkin                         # 优先级： 12011

  #- skywalking                    # 优先级： 12010

  #- opentelemetry                 # 优先级： 12009

  - fault-injection                # 优先级： 11000

  - mocking                        # 优先级： 10900

  - serverless-pre-function        # 优先级： 10000

  #- batch-requests                # 优先级： 4010

  - cors                           # 优先级： 4000

  - ip-restriction                 # 优先级： 3000

  - ua-restriction                 # 优先级： 2999

  - referer-restriction            # 优先级： 2990

  - csrf                           # 优先级： 2980

  - uri-blocker                    # 优先级： 2900

  - request-decompress             # 优先级： 2850

  - request-validation             # 优先级： 2800

  - portal-auth                    # 优先级： 2750

  - chaitin-waf                    # 优先级： 2700

  - multi-auth                     # 优先级： 2600

  - openid-connect                 # 优先级： 2599

  - saml-auth                      # 优先级： 2598

  - cas-auth                       # 优先级： 2597

  - authz-casbin                   # 优先级： 2560

  - authz-casdoor                  # 优先级： 2559

  - wolf-rbac                      # 优先级： 2555

  - ldap-auth-advanced             # 优先级： 2541

  - ldap-auth                      # 优先级： 2540

  - hmac-auth                      # 优先级： 2530

  - basic-auth                     # 优先级： 2520

  - jwt-auth                       # 优先级： 2510

  - jwe-decrypt                    # 优先级： 2509

  - key-auth                       # 优先级： 2500

  - dingtalk-auth                  # 优先级： 2430

  - feishu-auth                    # 优先级： 2420

  - acl                            # 优先级： 2410

  - consumer-restriction           # 优先级： 2400

  - attach-consumer-label          # 优先级： 2399

  - forward-auth                   # 优先级： 2002

  - opa                            # 优先级： 2001

  - authz-keycloak                 # 优先级： 2000

  - data-mask                      # 优先级： 1500

  #- error-log-logger              # 优先级： 1091

  - proxy-cache                    # 优先级： 1085

  - body-transformer               # 优先级： 1080

  - ai-request-rewrite             # 优先级： 1073

  - ai-prompt-template             # 优先级： 1071

  - ai-prompt-decorator            # 优先级： 1070

  - ai-prompt-guard                # 优先级： 1072

  - ai-rag                         # 优先级： 1060

  - ai-aws-content-moderation      # 优先级： 1050

  - ai-proxy-multi                 # 优先级： 1041

  - ai-proxy                       # 优先级： 1040

  - ai-cache                       # 优先级： 1035

  - ai-rate-limiting               # 优先级： 1030

  - ai-aliyun-content-moderation   # 优先级： 1029

  - ai-lakera-guard                # 优先级： 1028

  - proxy-mirror                   # 优先级： 1010

  - graphql-proxy-cache            # 优先级： 1009

  - proxy-rewrite                  # 优先级： 1008

  - workflow                       # 优先级： 1006

  - api-breaker                    # 优先级： 1005

  - graphql-limit-count            # 优先级： 1004

  - limit-conn                     # 优先级： 1003

  - limit-count                    # 优先级： 1002

  - limit-count-advanced           # 优先级： 1001

  - limit-req                      # 优先级： 999

  #- node-status                   # 优先级： 998

  - traffic-label                  # 优先级： 995

  - gzip                           # 优先级： 994

  - server-info                    # 优先级： 990

  - traffic-split                  # 优先级： 966

  - redirect                       # 优先级： 900

  - response-rewrite               # 优先级： 899

  - soap                           # 优先级： 554

  - openapi-to-mcp                 # 优先级： 540

  - mcp-tools-acl                  # 优先级： 539

  - oas-validator                  # 优先级： 510

  - degraphql                      # 优先级： 509

  - kafka-proxy                    # 优先级： 508

  #- dubbo-proxy                   # 优先级： 507

  - grpc-transcode                 # 优先级： 506

  - grpc-web                       # 优先级： 505

  - public-api                     # 优先级： 501

  - prometheus                     # 优先级： 500

  - datadog                        # 优先级： 495

  - lago                           # 优先级： 415

  - error-page                     # 优先级： 450

  - loki-logger                    # 优先级： 414

  - elasticsearch-logger           # 优先级： 413

  - echo                           # 优先级： 412

  - loggly                         # 优先级： 411

  - http-logger                    # 优先级： 410

  - splunk-hec-logging             # 优先级： 409

  - skywalking-logger              # 优先级： 408

  - google-cloud-logging           # 优先级： 407

  - sls-logger                     # 优先级： 406

  - tcp-logger                     # 优先级： 405

  - kafka-logger                   # 优先级： 403

  - rocketmq-logger                # 优先级： 402

  - syslog                         # 优先级： 401

  - udp-logger                     # 优先级： 400

  - file-logger                    # 优先级： 399

  - clickhouse-logger              # 优先级： 398

  - tencent-cloud-cls              # 优先级： 397

  #- log-rotate                    # 优先级： 100

  # <- 建议你的自定义插件使用优先级 (0, 100)

  - example-plugin                 # 优先级： 0

  #- gm                            # 优先级： -43

  - aws-lambda                     # 优先级： -1899

  - azure-functions                # 优先级： -1900

  - openwhisk                      # 优先级： -1901

  - openfunction                   # 优先级： -1902

  - serverless-post-function       # 优先级： -2000



stream_plugins: # 按优先级排序

  - ip-restriction                 # 优先级： 3000

  - limit-conn                     # 优先级： 1003

  - mqtt-proxy                     # 优先级： 1000

  - traffic-split                  # 优先级： 966

  #- prometheus                    # 优先级： 500

  - syslog                         # 优先级： 401

  # <- 建议你的自定义插件使用优先级 (0, 100)



#wasm:

  #plugins:

    #- name: wasm_log

      #priority: 7999

      #file: t/wasm/log/main.go.wasm



#xrpc:

  #protocols:

    #- name: pingpong



plugin_attr:

  log-rotate:

    enable: false

    timeout: 10000 # 日志轮转的最长等待时间（单位：毫秒）；interval: 3600（轮转间隔，单位：秒）

    max_kept: 168     # 保留的最大日志文件数

    max_size: -1      # 待轮转日志文件的最大字节数，小于 0 时跳过大小检查

    enable_compression: false    # 是否启用日志文件压缩（gzip），默认为 false

  skywalking:

    service_name: APISIX

    service_instance_name: APISIX Instance Name

    endpoint_addr: http://127.0.0.1:12800

  soap:

    endpoint: http://127.0.0.1:5000

    timeout: 3000

  prometheus:

    export_uri: /apisix/prometheus/metrics

    metric_prefix: apisix_

    enable_export_server: true

    export_addr:

      ip: 127.0.0.1

      port: 9091

    fetch_metric_timeout: 5

    allow_degradation: false

    degradation_pause_steps: [ 60 ]

    #metrics:

    #  http_status:

    # # 来自 NGINX 变量的额外标签

    #    extra_labels:

    # # 标签名不需要与变量名相同

    # # 以下标签仅为示例，你可以按需添加任何有效变量

    #      - upstream_addr: $upstream_addr

    #      - upstream_status: $upstream_status

    #    expire: 0 # 指标被移除前的过期时间，单位为秒。

    # # 0 表示指标不会过期

    #  http_latency:

    #    extra_labels:

    #      - upstream_addr: $upstream_addr

    #    expire: 0 # 指标被移除前的过期时间，单位为秒。

    # # 0 表示指标不会过期

    #  bandwidth:

    #    extra_labels:

    #      - upstream_addr: $upstream_addr

    #    expire: 0 # 指标被移除前的过期时间，单位为秒。

    # # 0 表示指标不会过期

    # default_buckets:

    #   - 10

    #   - 50

    #   - 100

    #   - 200

    #   - 500

    # llm_latency_buckets:     # apisix_llm_latency 直方图的桶，同时适用于 type=total 和 type=ttft（单位：毫秒）

    #   - 100

    #   - 500

    #   - 1000

    #   - 5000

    # llm_prompt_tokens_buckets:     # apisix_llm_prompt_tokens_dist 直方图的桶（单位：Token）

    #   - 100

    #   - 1000

    #   - 10000

    # llm_completion_tokens_buckets: # apisix_llm_completion_tokens_dist 直方图的桶（单位：Token）

    #   - 100

    #   - 1000

    #   - 10000

  server-info:

    report_ttl: 60   # etcd 中服务器信息的存活时间（单位：秒）

  dubbo-proxy:

    upstream_multiplex_count: 32

  proxy-mirror:

    timeout:                          # 镜像子请求中的代理超时时间

      connect: 60s

      read: 60s

      send: 60s

#  redirect:

#    https_port: 8443   # HTTP 重定向到 HTTPS 使用的默认端口

  inspect:

    delay: 3            # 单位为秒

    hooks_file: "/usr/local/apisix/plugin_inspect_hooks.lua"

  zipkin:                             # 插件：zipkin

    set_ngx_var: false                # 将 Zipkin 变量导出为 NGINX 变量



deployment:

  role: traditional

  role_traditional:

    config_provider: etcd

  admin:

    admin_key_required: true          # 默认启用 Admin Key。设置为 false 会禁用

                                      # Admin API 身份认证。注意：此操作仅可用于

                                      # 可信网络，禁止在生产环境中禁用。

    # 使用 API 调用 Admin API 时的默认 Token。

    # *注意*：强烈建议修改该值以保护 APISIX Admin API。

    # 禁用该配置项表示 Admin API

    # 不需要任何身份认证。

    admin_key:

      -

        name: admin

        key: edd1c9f034335f136f87ad84b625c8f1

        role: admin                 # admin：管理所有配置数据

                                    # viewer：仅可查看配置数据

      -

        name: viewer

        key: 4054f7cf07e344346cd3f287985e76a2

        role: viewer



    enable_admin_cors: true         # Admin API 支持 CORS 响应头。

    allow_admin:                    # http://nginx.org/en/docs/http/ngx_http_access_module.html#allow

      - 127.0.0.0/24                # 如果未设置任何 IP 列表，则默认允许任意 IP 访问。

      #- "::/64"

    admin_listen:                 # 使用独立端口

      ip: 0.0.0.0                 # 指定 IP。如果未设置，默认值为 `0.0.0.0`。

      port: 9180                  # 指定端口，必须与 node_listen 的端口不同。



    #https_admin: true            # 使用独立端口访问 Admin API 时启用 HTTPS。

                                  # Admin API 会使用 conf/apisix_admin_api.crt 和 conf/apisix_admin_api.key 作为证书。



    admin_api_mtls:               # 依赖 `admin_listen` 和 `https_admin`。

      admin_ssl_cert: ""          # 自签名服务端证书的路径。

      admin_ssl_cert_key: ""      # 自签名服务端密钥的路径。

      admin_ssl_ca_cert: ""       # 自签名 CA 证书的路径。该 CA 用于签发所有 Admin API 调用方证书。



    admin_api_version: v3         # Admin API 版本，最新版本为 v3。



  # fallback_cp:

  #   mode: "read"                # "read"（默认）：故障备用模式，从下方存储拉取配置和资源。

  #                               # "write"：备份模式，数据面实例向下方存储推送配置和资源，

  #                               # 并且不接收或代理任何请求。

  #   interval: 60                # 备份模式的间隔，单位为秒，默认为 60

  #   aws_s3:                     # AWS S3 配置，用于存储配置/资源，可在备份模式下推送，也可在 fallback 模式下拉取

  #     access_key: "just-access"

  #     secret_key: "super-secret"

  #     resource_bucket: "resource_bucket"

  #     config_bucket: "config_bucket"

  #     region: "ap-south-1"

  #     endpoint: "https://minio.test/fallback-cp-config"

  #     use_path_style: true

  #   azure_blob:                 # Azure Blob Storage 配置，用于存储配置/资源，可在备份模式下推送，也可在 fallback 模式下拉取

  #     account_name: devstoreaccount1

  #     account_key: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="

  #     resource_container: yaml

  #     config_container: config

  #     endpoint: "http://localhost:10000/devstoreaccount1"



  etcd:

    host:                           # 可以定义同一 etcd 集群的多个 etcd 主机地址。

      - "http://127.0.0.1:2379"     # 多个 etcd 地址。如果你的 etcd 集群启用了 TLS，请使用 https 协议，

                                    # 例如 https://127.0.0.1:2379。

    prefix: /apisix                 # etcd 中的配置前缀

    timeout: 30                     # 连接/读取/写入 etcd 的超时时间。

    watch_timeout: 50               # 监听 etcd 的超时时间

    #resync_delay: 5                # 同步失败且需要重试时，在配置秒数外加 50% 随机抖动后重新同步

    #health_check_timeout: 10       # etcd 在配置秒数后重试不健康节点

    startup_retry: 2                # 启动期间重试 etcd 的次数，默认为 2

    #user: root                     # etcd 的 root 用户名

    #password: 5tHkHhYkjr6cQY       # etcd 的 root 密码

    tls:

      # 要启用 etcd 客户端证书，需要构建 APISIX-Base，参见

      # https://apisix.apache.org/docs/apisix/FAQ#how-do-i-build-the-apisix-base-environment

      #cert: /path/to/cert          # etcd 客户端使用的证书路径

      #key: /path/to/key            # etcd 客户端使用的密钥路径



      verify: true                  # 与 etcd 建立 TLS 连接时是否验证 etcd 端点证书，

                                    # 默认值为 true，即严格验证证书。

      #sni:                         # etcd TLS 请求的 SNI。如果缺失，将使用 URL 的 host 部分。



api7ee:

  healthcheck_report_interval: 120 # 健康检查数据上报间隔，单位为秒

  raw_api_calls_upload_interval: 3600 # 原始 API 调用的上传间隔，单位为秒，默认为 1 小时

  http_timeout: 30s # 向控制面发送健康检查和遥测数据时使用的 HTTP 超时时间

  consumer_proxy:

    enable: false             # 如果 enable 为 true，消费者资源将由控制面代理。

    cache_success_count: 512  # 缓存从控制面查询到的成功结果数量。

    cache_success_ttl: 60     # 缓存从控制面查询到的成功结果 TTL（单位：秒）。

    cache_failure_count: 512  # 缓存从控制面查询到的失败结果数量。

    cache_failure_ttl: 60     # 缓存从控制面查询到的失败结果 TTL（单位：秒）。

  developer_proxy:            # 代理 portal-auth 插件

    cache_success_count: 256  # 缓存从控制面查询到的成功结果数量。

    cache_success_ttl: 15     # 缓存从控制面查询到的成功结果 TTL（单位：秒）。

    cache_failure_count: 256  # 缓存从控制面查询到的失败结果数量。

    cache_failure_ttl: 15     # 缓存从控制面查询到的失败结果 TTL（单位：秒）。
```
