Nginx variable in proxy pass does not work
Those two cases are not the same. If you use a variable, that value will replace the entire URI.
In this case:
location /site {
proxy_pass http://docker-site/site/mobile;
}
the URI /site/foo
is passed upstream as /site/mobile/foo
.
To use your variable, you can use a rewrite (see this document for details):
location /site {
rewrite ^/site(.*)$ /site/$myvariable$1 break;
proxy_pass http://docker-site;
}
Or a regular expression location:
location ~ ^/site(.*)$ {
proxy_pass http://docker-site/site/$myvariable$1;
}
The evaluation order of regular expression location blocks is significant. See this document for details.