Plugin Config

Plugin Configs are used to extract commonly used Plugin configurations and can be bound directly to a Route.

The example below illustrates how this can be used:

  1. # create a plugin config
  2. $ curl http://127.0.0.1:9080/apisix/admin/plugin_configs/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
  3. {
  4. "desc": "blah",
  5. "plugins": {
  6. "limit-count": {
  7. "count": 2,
  8. "time_window": 60,
  9. "rejected_code": 503
  10. }
  11. }
  12. }'
  13. # bind it to route
  14. $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
  15. {
  16. "uris": ["/index.html"],
  17. "plugin_config_id": 1,
  18. "upstream": {
  19. "type": "roundrobin",
  20. "nodes": {
  21. "127.0.0.1:1980": 1
  22. }
  23. }
  24. }'

When APISIX can’t find the Plugin Config with the id, the requests reaching this Route are terminated with a status code of 503.

If a Route already has the plugins field configured, the plugins in the Plugin Config will effectively be merged to it. The same plugin in the Plugin Config will override the ones configured directly in the Route.

For example, if we configure a Plugin Config as shown below

  1. {
  2. "desc": "I am plugin_config 1",
  3. "plugins": {
  4. "ip-restriction": {
  5. "whitelist": [
  6. "127.0.0.0/24",
  7. "113.74.26.106"
  8. ]
  9. },
  10. "limit-count": {
  11. "count": 2,
  12. "time_window": 60,
  13. "rejected_code": 503
  14. }
  15. }
  16. }

to a Route as shown below,

  1. {
  2. "uris": ["/index.html"],
  3. "plugin_config_id": 1,
  4. "upstream": {
  5. "type": "roundrobin",
  6. "nodes": {
  7. "127.0.0.1:1980": 1
  8. }
  9. }
  10. "plugins": {
  11. "proxy-rewrite": {
  12. "uri": "/test/add",
  13. "scheme": "https",
  14. "host": "apisix.iresty.com"
  15. },
  16. "limit-count": {
  17. "count": 20,
  18. "time_window": 60,
  19. "rejected_code": 503,
  20. "key": "remote_addr"
  21. }
  22. }
  23. }

the effective configuration will be as the one shown below:

  1. {
  2. "uris": ["/index.html"],
  3. "upstream": {
  4. "type": "roundrobin",
  5. "nodes": {
  6. "127.0.0.1:1980": 1
  7. }
  8. }
  9. "plugins": {
  10. "ip-restriction": {
  11. "whitelist": [
  12. "127.0.0.0/24",
  13. "113.74.26.106"
  14. ]
  15. },
  16. "proxy-rewrite": {
  17. "uri": "/test/add",
  18. "scheme": "https",
  19. "host": "apisix.iresty.com"
  20. },
  21. "limit-count": {
  22. "count": 2,
  23. "time_window": 60,
  24. "rejected_code": 503
  25. }
  26. }
  27. }