Problem Statement
I would like to proxy_pass to another url based on the some value present in the request header. All the request details including query parameter(if any), header and everything should be passed to the proxy address.
What i have tried
I have followed SO post and based on the requirement mentioned i have tried the following.
Test.lua file
local token = ngx.var.http_Authorization
if token == "hello"
then
-- ngx.print ("hello")
local res = ngx.location.capture("/someURL")
if res.status == 200
then ngx.print(res.body)
end
end
nginx.conf
location /api/employees {
content_by_lua_file test.lua;
}
location /someURL {
internal;
proxy_pass http://productionURL?q1=123&name=xyz;
#proxy_redirect default;
}
As you can see i am passing the query parameter manually in the proxy_pass statement.
How do i resolve this by not passing actual request during proxy_pass ?