Standalone Configurations
In standalone mode, APISIX fetches configuration from apisix.yaml
instead of using etcd as the configuration center. These configurations are loaded into memory at startup and monitored for changes at a regular interval, without the requirement of manually reloading APISIX. It is important to note that APISIX will not load the configurations if there is no #END
at the end of the file.
This document provides some configuration examples for APISIX deployed in standalone mode. To learn more information about the available configuration options, see Admin API reference.
Configure Routes
This example creates two routes to forward requests to /hello
and /hello2
to different upstreams:
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
Configure Routes and Services
This example creates a service and a route within the service:
routes:
-
uri: /hello
service_id: 1
services:
-
id: 1
upstream:
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
Configure Routes and Upstreams
This example creates an upstream and a route that points to the upstream:
routes:
-
uri: /hello
upstream_id: 1
upstreams:
-
id: 1
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
Configure Routes, Services, and Upstreams
This example creates an upstream, a service, and a route within the service:
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
Configure Plugins
This example enables three plugins:
plugins:
- name: ip-restriction
- name: jwt-auth
- name: mqtt-proxy
stream: true # set 'stream' to true for stream plugins
#END
Note that the list of plugins will override the list of plugins enabled in default-config.yaml
.
Configure Plugin Configs
This example creates a plugin config which is referenced by a route:
plugin_configs:
-
id: 1
plugins:
response-rewrite:
body: "hello\n"
routes:
- id: 1
uri: /hello
plugin_config_id: 1
upstream:
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
Configure Plugin Global Rules
This example creates a plugin global rule:
global_rules:
-
id: 1
plugins:
response-rewrite:
body: "hello\n"
#END
Configure Plugin Metadata
This example creates plugin metadata:
upstreams:
- id: 1
nodes:
"127.0.0.1:1980": 1
type: roundrobin
routes:
-
uri: /hello
upstream_id: 1
plugins:
http-logger:
batch_max_size: 1
uri: http://127.0.0.1:1980/log
plugin_metadata:
- id: http-logger
log_format:
host: "$host",
remote_addr: "$remote_addr"
#END
Configure SSL
This example configures SSL:
ssls
-
cert: ${{SERVER_CERT}}
key: ${{SERVER_KEY}}
snis: ${{DOMAIN_NAME}}
#END
To learn more about setting environment variables, see Use Environment Variables in Configuration Files.
Configure Consumers
This example creates a consumer:
consumers:
- username: jwt
plugins:
jwt-auth:
key: user-key
secret: my-secret-key
#END
Configure Stream Routes
This example creates a stream route:
stream_routes:
- server_addr: 127.0.0.1
server_port: 1985
id: 1
upstream:
nodes:
"127.0.0.1:1981": 1
type: roundrobin
plugins:
mqtt-proxy:
protocol_name: "MQTT"
protocol_level: 4
#END
Configure Protos
This example creates a proto object:
protos:
- id: helloworld
desc: hello world
content: >
syntax = "proto3";
package helloworld;
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
#END