文件驱动的独立模式
在 文件驱动的独立模式 中,APISIX 从 apisix.yaml 或 apisix.json 获取配置,而不是使用 etcd 作为配置中心。这些配置在启动时加载到内存中,并定期监控更改,无需手动重新加载 APISIX。
important
如果你使用的是 apisix.yaml,请注意,如果文件末尾没有 #END,APISIX 将不会加载配置。
本文档提供了在文件驱动的独立模式下部署的 APISIX 的一些配置示例。要了解有关可用配置选项的更多信息,请参阅 Admin API 参考(但不要使用这些端点)。这些配置选项可以转换为 YAML 或 JSON,以便在文件驱动的独立模式下使用。
配置路由
此示例创建了两个路由,将对 /hello 和 /hello2 的请求转发到不同的上游:
- YAML
- JSON
apisix.yaml
routes:
-
uri: /hello
upstream:
nodes:
"127.0.0.1:1980": 1
type: roundrobin
-
uri: /hello2
upstream:
nodes:
"127.0.0.1:1981": 1
type: roundrobin
#END
apisix.json
{
"routes": [
{
"uri": "/hello",
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
},
{
"uri": "/hello2",
"upstream": {
"nodes": {
"127.0.0.1:1981": 1
},
"type": "roundrobin"
}
}
]
}
配置路由和服务
- YAML
- JSON
apisix.yaml
routes:
-
uri: /hello
service_id: 1
services:
-
id: 1
upstream:
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
apisix.json
{
"routes": [
{
"uri": "/hello",
"service_id": 1
}
],
"services": [
{
"id": 1,
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}
]
}
配置路由和上游
- YAML
- JSON
apisix.yaml
routes:
-
uri: /hello
upstream_id: 1
upstreams:
-
id: 1
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
apisix.json
{
"routes": [
{
"uri": "/hello",
"upstream_id": 1
}
],
"upstreams": [
{
"id": 1,
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
]
}
配置路由、服务和上游
- YAML
- JSON
apisix.yaml
routes:
-
uri: /hello
service_id: 1
services:
-
id: 1
upstream_id: 2
upstreams:
-
id: 2
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
apisix.json
{
"routes": [
{
"uri": "/hello",
"service_id": 1
}
],
"services": [
{
"id": 1,
"upstream_id": 2
}
],
"upstreams": [
{
"id": 2,
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
]
}
配置插件
此示例启用了三个 插件:
- YAML
- JSON
apisix.yaml
plugins:
- name: ip-restriction
- name: jwt-auth
- name: mqtt-proxy
stream: true
#END
apisix.json
{
"plugins": [
{
"name": "ip-restriction"
},
{
"name": "jwt-auth"
},
{
"name": "mqtt-proxy",
"stream": true
}
]
}
对于 L4 插件,将 stream 设置为 true。
请注意,此配置将覆盖默认启用或在 配置文件 中启用的插件列表。