openresty / openresty/lua-nginx-module

Nginx regex match variables not working in lua blocks

Open
#1,605 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

NGX_VERSION='1.16.1'
LUAJIT_VERSION='2.1-20190912'
LUAJIT_MAJOR_VERSION='2.1'
NGX_DEVEL_KIT_VERSION='0.3.0'
LUA_NGINX_MODULE_VERSION='0.10.15'
LUA_RESTY_CORE_VERSION='0.1.17'
LUA_RESTY_LRUCACHE_VERSION='0.09'

URL:- http://example.com/sess1234/phpmyadmin/index.php

location ~ /phpmyadmin {
   root /usr/local/nginx;
   rewrite /sess([a-z0-9]+)/(wordpress|phpmyadmin)(.*) /$2$3;
   default_type 'text/plain';

   set $var1 $1;
   set $wp "valuewp";

   content_by_lua_block {
      ngx.say(ngx.var.var1)
      ngx.say(ngx.var.wp)
   }

   #return 200 "var1 = $var1 and wp = $wp";
}

Above code output
(ngx.var.var1 is empty here, ) I'm expecting it should be 1234
valuewp

when #return... is uncommented output is
-- var1 = 1234 and wp = valuewp

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduced Nginx configuration and the content_by_lua_block entry point, then compare ngx.var.var1 with the commented return output for the same rewritten URL. Reproduce the difference using the stated Nginx, LuaJIT, and module versions; done means the regex-derived value is available in the Lua block as shown by the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.