openresty / openresty/lua-nginx-module

ngx.exec is not redirecting in the following condition

Open
#1,966 3 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

Using openresty based nginx.
nginx version: openresty/1.19.9.1
I have a lua file in my project from there I want to call exec method for internal redirection.
My code is something like.. some rest apis call will be there as per result I want to do redirect to some location block

(In lua file)
local redirectToLogFile = function()
local redirecturl = ngx.var.scheme .. '://' .. ngx.var.host .. ":" .. ngx.var.server_port.. "/redirectlog"
return ngx.exec(redirecturl)
end

and correspondingly I have location block in nginx.conf

location ~ /redirectlog {
error_log /usr/local/openresty/nginx/logs/custom.log error;
content_by_lua_block {
ngx.log(ngx.ERR, "calling from the client " .. ngx.var.remote_addr)

}
}
What I observe is some time ngx.exec(redirecturl) is not going to /redirectlog location block when calling the api through browser. same thing is working perfectly when execute via postman.
Is it the correct way. If not how we can achieve this.

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 Lua file containing redirectToLogFile and the corresponding location block in nginx.conf; reproduce the behavior through both a browser and Postman while tracing ngx.exec(redirecturl). Confirm whether requests consistently reach /redirectlog and document the conditions that distinguish the two request paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.