Why does a variable not work in proxy_pass
?
This works perfectly:
location /foo/ {
proxy_pass http://127.0.0.1/;
}
This doesn't work at all:
location /foo/ {
set $FOO http://127.0.0.1/;
proxy_pass $FOO;
add_header x-debug $FOO;
}
I see the x-header: http://127.0.0.1/
but the result is 404 so I don't know where it's proxying to but it's not identical to the first example.
Source where it is explained that using a variable in proxy_pass will prevent NGINX startup errors when the upstream is not available.
UPDATE: The issue is the upstream path rewriting. I expect it to rewrite /foo/blah
to the upstream at /blah
removing the /foo
prefix. It works fine with static host/uri entries but not with a variable.