Giter Site home page Giter Site logo

apisix-plugins's Introduction


apisix-plugins

GitHub License codecov

一些自定义的Apisix插件,用于入门学习记录

以下docs 只针对client-ip.lua

如何使用

cd /usr/local/apisix/apisix/plugins
rz ${custom_plugins}.lua

确认插件有优先级

vim /usr/local/apisix/conf/config-default.yaml

...
...

plugins:                          # plugin list (sorted by priority)
  - real-ip                        # priority: 23000
  - ai                             # priority: 22900
  - client-control                 # priority: 22000
  - proxy-control                  # priority: 21990
  - request-id                     # priority: 12015
...  
...
  #找一个没有被占用的优先级数值

更改插件脚本优先级

local _M = {
    version = 0.1,
    priority = 415,   -- 优先级, 数值越小优先级越低
    name = plugin_name,
    schema = schema,
    metadata_schema = metadata_schema
}

使插件生效

systemctl reload apisix
#查看插件列表
curl "http://127.0.0.1:9180/apisix/admin/plugins/list" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'

创建路由

curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/482183271426993588' \
    -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
    -H 'Content-Type: application/json' \
    -d '{
    "uri": "/client-ip",
    "name": "client-ip", 
    "host": "xxxxx.com",
    "desc": "自定义插件,暴露公共API,获取客户端IP并返回",
    "plugins": {
        "public-api": {
            "uri": "/apisix/plugin/client-ip"
        }
    }
}'

验证

curl xxxxx.com/client-ip
{"client_ip":"192.168.8.120"}

日志

如果apisix的日志级别为debuginfo,可查看apisix日志来确认插件是否正确执行 conf/config.yaml

tail -f  logs/error.log

2022/10/04 15:59:34 [info] 32345#32345: *1310355 [lua] client-ip.lua:64: phase_func(): Custom plugin client-ip in request has been processed! while logging request, client: 192.168.8.120, server: _, request: "GET /clientIp HTTP/1.1", host: "xxxxx.com"

apisix-plugins's People

Contributors

yahahaff avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.