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
2. 创建路由
下一步, 选择upstream,
设置插件重写 路径
保存后, 当我们访问网关的, 这里的路由重写和nginx的写法类型, 非常简单.(apisix 2.1, apisix dashborad 2.2)
访问 http://localhost:9080/api/admin
实际访问到上游: http://localhost:8013/admin
参考资料