Global Rules

Description

A Plugin configuration can be bound directly to a Route, a Service or a Consumer. But what if we want a Plugin to work on all requests? This is where we register a global Plugin with Global Rule.

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:

  1. curl -X PUT \
  2. https://{apisix_listen_address}/apisix/admin/global_rules/1 \
  3. -H 'Content-Type: application/json' \
  4. -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
  5. -d '{
  6. "plugins": {
  7. "limit-count": {
  8. "time_window": 60,
  9. "policy": "local",
  10. "count": 2,
  11. "key": "remote_addr",
  12. "rejected_code": 503
  13. }
  14. }
  15. }'

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

  1. curl https://{apisix_listen_address}/apisix/admin/global_rules