🧭 管理接口总体分类(基于 REST API)
资源类别 | 接口路径前缀 | 功能说明 |
---|---|---|
路由(Routes) | /apisix/admin/routes/{id} |
定义 HTTP 请求的匹配规则及转发目标 |
服务(Services) | /apisix/admin/services/{id} |
封装上游配置,可被多个路由复用 |
上游(Upstreams) | /apisix/admin/upstreams/{id} |
指定请求转发的后端节点 |
插件配置 | 插入到各资源中(如 routes/plugins) | 控制 API 行为,如限流、日志等 |
全局规则 | /apisix/admin/global_rules/{id} |
所有请求生效的全局插件规则 |
SSL证书 | /apisix/admin/ssl/{id} |
TLS 证书配置 |
消费者 | /apisix/admin/consumers/{id} |
身份认证与访问控制相关 |
插件元信息 | /apisix/admin/plugin_metadata/{name} |
设置插件元配置,如日志格式等 |
分组(多租户) | /apisix/admin/routes?group=xxx |
多环境隔离支持(可选) |
✅ 路由 Routes 示例解析
配置路径转发:
curl --location --request PUT 'http://127.0.0.1:9180/apisix/admin/routes/1' \
--header 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
--header 'Content-Type: application/json' \
--data-raw '{
"uri": "/proxy/generalquery",
"methods": ["POST"],
"plugins": {
"proxy-rewrite": {
"regex_uri": ["^/proxy/generalquery", "/GeneralQuery/defaultSearch"]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"host.docker.internal:6610": 1
}
}
}'
含义:
uri/methods: 匹配规则
plugins: 附加功能,如路径重写
upstream: 请求转发目标节点配置
✅ 全局规则 Global Rules 示例解析
curl --location --request PUT 'http://127.0.0.1:9180/apisix/admin/global_rules/1' \
--header 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
--header 'Content-Type: application/json' \
--data-raw '{
"plugins": {
"clear-x-forwarded-for": {}
}
}'
含义:
- 所有请求都会被应用该插件(比如清除 X-Forwarded-For)
🚀 常用管理操作汇总(速查)
功能 | curl 示例 |
---|---|
创建/更新路由 | PUT /apisix/admin/routes/{id} |
查询单个路由 | GET /apisix/admin/routes/{id} |
查询所有路由 | GET /apisix/admin/routes |
删除路由 | DELETE /apisix/admin/routes/{id} |
创建/更新上游 | PUT /apisix/admin/upstreams/{id} |
配置全局插件规则 | PUT /apisix/admin/global_rules/{id} |
配置 SSL 证书 | PUT /apisix/admin/ssl/{id} |
配置消费者 | PUT /apisix/admin/consumers/{id} |
配置服务 | PUT /apisix/admin/services/{id} |
启用插件元数据 | PUT /apisix/admin/plugin_metadata/{plugin_name} |
🎯 实战配置建议
使用唯一 ID 管理资源:
给每个资源设定唯一的
id
(如 route 1、2、3),方便更新或删除。使用
GET
查询现有 ID 避免重复。
分离资源解耦配置:
将 Upstream 和 Route 分开管理,让多个路由共享一个上游配置。
使用 Service 抽象业务行为。
组合插件:
支持多个插件组合使用,比如日志、限流、认证等。
示例:
"plugins": { "limit-count": { "count": 10, "time_window": 60, "rejected_code": 429 }, "proxy-rewrite": { "regex_uri": ["^/a", "/b"] } }
配置热更新无需重启:
- 所有管理接口变更实时生效,无需重启 APISIX 服务。