openresty / openresty/lua-nginx-module

ngx.var.VARIABLE is empty after rewrtie_by_lua

Open
#787 4 comments 1 reaction 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

Hello,
Location block-
` location /api/abc/ {

            rewrite_log on;
            include upstreams/allCors.settings;
            include upstreams/proxy.settings;
            proxy_pass http://xyz/api/abc/;
            set $rId '';
            set $aId '';
            rewrite_by_lua_file $lua_base/abcAccess.lua;
            rewrite ^(.*)$ $1?rId=$rId&aId=$aId break;
    }`

In the abcAccess.lua file, I set the rId and aId after some processing by using ngx.var.rId = some value and ngx.var.aId = some value.
I can even see that this is correct by using ngx.log in the same file.

However, in the rewrite directive of nginx, the rId and aId are empty.
I have set "rewrite_by_lua_no_postpone" to "on" in the http block.
The rewrite log also shows rId and aId being set in the abcAccess file first and then the rewrite directive being executed.

Why are the Ids empty?

My openresty version -1.7.10.1

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 provided location block and abcAccess.lua, then trace the interaction between rewrite_by_lua_file, rewrite_by_lua_no_postpone, and the following rewrite directive. Use the rewrite log and ngx.log output to compare variable values at each phase. Done means explaining why rId and aId are empty or documenting a confirmed fix for OpenResty 1.7.10.1.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.