Skip to main content
Version: 3.16

Global Rules

Description#

A Global Rule configures Plugins for incoming requests independently of Plugins bound to a Route, Service, Consumer, or Plugin Config. Rate-limiting and observability Plugins are often enabled globally to apply consistent behavior across APIs.

Compared with the plugin configuration in Route, Service, Plugin Config, and Consumer, the plugin in the Global Rules is always executed first.

Example#

The example below shows how you can use the limit-count Plugin on all requests:

note

You can fetch the admin_key from config.yaml and save to an environment variable with the following command:

admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g')
curl -X PUT \
http://{apisix_listen_address}/apisix/admin/global_rules/1 \
-H 'Content-Type: application/json' \
-H "X-API-KEY: $admin_key" \
-d '{
"plugins": {
"limit-count": {
"time_window": 60,
"policy": "local",
"count": 2,
"key": "remote_addr",
"rejected_code": 503
}
}
}'

You can also list all the Global rules by making this request with the Admin API:

curl http://{apisix_listen_address}/apisix/admin/global_rules -H "X-API-KEY: $admin_key"