Stand-alone mode
This method is more suitable for two types of users:
- kubernetes(k8s):Declarative API that dynamically updates the routing rules with a full yaml configuration.
- Different configuration centers: There are many implementations of the configuration center, such as Consul, etc., using the full yaml file for intermediate conversion.
The routing rules in the file are loaded into memory immediately after the APISIX node service starts. And every time interval (default 1 second), will try to detect whether the file content is updated, if there is an update, reload the rule.
Note: When reloading and updating routing rules, they are all hot memory updates, and there will be no replacement of working processes, it is a hot update.
To enable Stand-alone mode, we can set apisix.config_center
to yaml
and disable Admin API in file conf/config.yaml
.
Refer to the example below:
All of the rules are stored in one file which named conf/apisix.yaml
, the APISIX will check if this file has any changed every second. If the file changed and we found #END
at the end of the file, APISIX will load the rules in this file and update to memory of APISIX.
routes:
-
uri: /hello
upstream:
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
NOTE: APISIX will not load the rules into memory from file conf/apisix.yaml
if there is no #END
at the end.
How to configure Router
Single Router:
routes:
-
uri: /hello
upstream:
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
Multiple Router:
routes:
-
uri: /hello
upstream:
nodes:
type: roundrobin
-
uri: /hello2
nodes:
"127.0.0.1:1981": 1
type: roundrobin
#END
How to configure Router + Service
routes:
-
uri: /hello
upstream_id: 1
upstreams:
-
id: 1
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
How to configure Router + Service + Upstream
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
How to configure Plugins
plugins:
- name: jwt-auth
- name: mqtt-proxy
stream: true # set 'stream' to true for stream plugins
#END
How to configure global rule
global_rules:
-
id: 1
plugins:
response-rewrite:
body: "hello\n"
How to configure consumer
consumers:
- username: jwt
plugins:
jwt-auth:
key: user-key
secret: my-secret-key
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 # note the id is the plugin name
log_format:
remote_addr: "$remote_addr"