I am new to Nginx. As I know, we can configure proxy_pass url in nginx.conf like:
location /test
{
proxy_pass http://10.10.10.10:10000;
}
But now, I need to proxy_pass to a variable url, we could get this url in http request header or request body(for example).
How could I implement this? Thanks for any help!
EDIT 1(explain my question):
There is a http request with a param named "redirectUrl" in its header send to Nginx, I just want Nginx modify this http request header and then send this request to the redirectUrl. Because the redirectUrl is a variable, so I guess "proxy_pass $request" can implement this, but I don't know how. Who can give me a hint or is there any documentation?
EDIT 2:
I tried ngx_lua :
location /apiproxytest {
set_by_lua $redirectURL '
return ngx.req.get_headers()["Host"]
';
header_filter_by_lua '
ngx.header["RedirectURL"] = nil;
ngx.header["Host"] = nil;
';
echo "1:" $redirectURL;
set_by_lua $redirectURL2 '
return ngx.req.get_headers()["Host"]
';
echo "2:" $redirectURL2;
#proxy_pass $redirectURL;
}
I found that echo 1 and echo 2 were the same, as ngx.header.HEADER explains, ngx.header["Host"] = nil is supposed to remove Host in http request header. Why echo "2:" $redirectURL2 can also print the value of Host?