I took the "Dynamic Request Routing Based on Redis" example from openresty.org and enabled reverse proxy but haven't been able to get the reverse proxy part of it to work. 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). Here's an example:
server {
listen 192.168.1.24:80;
server_name 192.168.1.24;
location /mojo {
set $target '';
access_by_lua '
-- code using redis to lookup dynamic target removed for simplicity, using hard-coded value here
ngx.var.target = "192.168.1.24:8080/mojo";
';
# reverse proxy setup
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# this works with reverse proxy
#proxy_pass http://192.168.1.24:8080/mojo;
# this does not
proxy_pass http://$target;
}
}
I would like to hide the internal hosts/posts from the user but reverse proxy doesn't seem to work when proxy_pass is used with a variable. When it works, user sees http://192.168.1.24/mojo. When it doesn't work, user sees http://192.168.1.24:8080/mojo. Any ideas? I'm really stuck.
server {
listen 192.168.1.24:80;
server_name 192.168.1.24;
location /mojo {
set $target '';
access_by_lua '
-- code using redis to lookup dynamic target removed for simplicity, using hard-coded value here
ngx.var.target = "192.168.1.24:8080/mojo";
';
# reverse proxy setup
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# this works with reverse proxy
#proxy_pass http://192.168.1.24:8080/mojo;
# this does not
proxy_pass http://$target;
}
}
I would like to hide the internal hosts/posts from the user but reverse proxy doesn't seem to work when proxy_pass is used with a variable. When it works, user sees http://192.168.1.24/mojo. When it doesn't work, user sees http://192.168.1.24:8080/mojo. Any ideas? I'm really stuck.