【问题标题】:make endpath to lowercase in nginx using lua module使用 lua 模块在 nginx 中将 endpath 设为小写
【发布时间】:2021-07-23 16:33:46
【问题描述】:

我想将请求 url 设置为小写,然后再将其设置为代理传递。

这是我的 nginx 文件

location ^~ /admin/(?<endpath>.*)
            {
                set_by_lua     ngx.var.endpath string.lower(ngx.var.endpath)
                proxy_pass     http://api.sample.com/api/portal/admin/$endpath$is_args$args;
            }

但我收到错误:无效的变量名“ngx.var.endpath”

【问题讨论】:

  • 你在哪里创建了那个变量?
  • @Piglet: 因为我的位置是^~ /admin/(?&lt;endpath&gt;.*) 所以ngx.var 应该有endpath

标签: nginx lua nginx-reverse-proxy nginx-config nginx-location


【解决方案1】:

我不太了解nginx,但是根据docs lua 代码应该是一个字符串。

所以不是

set_by_lua     ngx.var.endpath string.lower(ngx.var.endpath)

试试类似的东西

set_by_lua $endpath 'return string.lower(ngx.var.endpath)'

【讨论】:

    猜你喜欢
    • 2017-05-01
    • 2019-01-06
    • 2017-07-31
    • 2018-05-02
    • 2013-07-13
    • 1970-01-01
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多