如何在lua中获取当前nginx/openresty位置的路径?

问题描述

我有这个位置块:

location /somewhere/ {
    access_by_lua_file /path/to/file.lua;
    add_header X-debug-message "Using location: /somewhere/" always;
    ...
}

我想做两件事:

  1. 我想将标题设置行移到 lua 文件中。
  2. 为此,我必须从变量中读取位置定义(匹配字符串/正则表达式/...),而不是将其作为静态字符串(“/somewhere/”)输入。

所以最后它应该看起来像 lua 文件中的魔法(我知道如何在 lua 中设置响应头)。

location /somewhere/ {
    access_by_lua_file /path/to/file.lua;
    ...
}

我的问题:我不知道...

  1. ...如果有一个变量存储位置描述(“/somewhere/”) - 而不是请求的 URI/URL/PATH 和
  2. 如果是 - 可以在何处找到该变量。

那么我如何从 lua 代码中访问这些信息?

示例

调用的 URL:https://mydomain.nowhere/somewhere/servicex/1234

匹配的位置:“location /somewhere/ { ...”

我想得到的字符串:“/somewhere/”(正是位置块的定义)。

解决方法

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

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

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