美文网首页
Apache Apisix 网关之 路由配置入门篇

Apache Apisix 网关之 路由配置入门篇

作者: 山间草夫 | 来源:发表于2020-12-27 18:41 被阅读0次

    1. 需求如下

    location /api/ {
      proxy_pass http://localhost:8013/;
    }
    
    访问 http://localhost:9080/api/admin
    实际访问: http://localhost:8013/admin
    

    由于Apisix 使用的是radixtree 的写法, 导致只支持匹配规则(Full match,Prefix matching) , 并且不会去掉匹配的路径, 这个时候, 为了去掉上面的 /api/ , 需要使用到插件 proxy write.

    1. 创建 upstream , 假设我们本地有个服务,端口是8013

    image.png

    2. 创建路由

    image.png

    下一步, 选择upstream,


    image.png

    设置插件重写 路径


    image.png

    保存后, 当我们访问网关的, 这里的路由重写和nginx的写法类型, 非常简单.(apisix 2.1, apisix dashborad 2.2)
    访问 http://localhost:9080/api/admin
    实际访问到上游: http://localhost:8013/admin

    参考资料

    1. 代理重写 https://github.com/apache/apisix/blob/master/doc/plugins/proxy-rewrite.md
    2. 配置路由规则 https://github.com/apache/apisix/blob/master/doc/router-radixtree.md

    相关文章

      网友评论

          本文标题:Apache Apisix 网关之 路由配置入门篇

          本文链接:https://www.haomeiwen.com/subject/hboonktx.html