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

时间:2021-7-4 作者:qvyue

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

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

2. 创建路由

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

下一步, 选择upstream,

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

设置插件重写 路径

Apache Apisix 网关之 路由配置入门篇
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
声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:qvyue@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。