Hello!
On Thu, Apr 30, 2015 at 10:11 AM, Duc Nguyen wrote:
> Reverse proxy works fine for hard-coded
> uri (e.g. http://192.168.1.24:8080/mojo) but won't work when a variable is
> used (e.g. http://$target).
What do you mean by "won't work"? What exact phenomena are you seeing?
Are you seeing any errors in your nginx error.log file?
I've tried the following standalone and minimal example based on your
sample and it works perfectly on my side:
server {
listen 8080;
location = /t {
set $target '';
access_by_lua '
ngx.var.target = "http://127.0.0.1:8080/mojo"
';
proxy_pass $target;
}
location = /mojo {
echo "hey, there";
}
}
And then query /t gives:
$ curl localhost:8080/t
hey, there
Please note that we should not specify "http://" again in proxy_pass
above because "http://" is already included in the $target variable
value.
BTW, if you use domain names instead of plain IP addresses in the
variable values, then you should also configure the standard
"resolver" configuration directive accordingly:
http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver
Best regards,
-agentzh