如何在openresty中通过lua在运行时获取匹配的location_name

问题描述

在 rewrite_by_lua 阶段,我想在运行时获取匹配的位置名称

例如: Nginx服务器配置:

server {
    listen 80;
    server_name 127.0.0.1;
    location /test {
        return 200 "test";
    }
    location /test/api {
        return 200 "test";
    }
    location ~ /id/\d* {
        return 200 "api";
    }
}

如果我访问 http://127.0.0.1/test/api/abc,我想获取 Nginx 位置名称:/test/api

如果我访问 http://127.0.0.1/test/ddd,我想获取 Nginx 位置名称:/test

如果我访问 http://127.0.0.1/id/123,我想获取 Nginx 位置名称:/id/\d*

openresty 版本:1.19.3.1

你能帮我吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)