Originally I had a conf like this:
location /some/path/ {
proxy_pass http://other.host/foo/;
}
And requests to http://my.domain/some/path/bar
would be proxied to http://other.host/foo/bar
I started using variables in the proxy_pass to force nginx to re-resolve DNS:
location /some/path/ {
resolver 1.2.3.4;
set $proxy_root "other.host/foo"
proxy_pass http://$proxy_root/;
}
But I found that the remainder of the uri path was no longer being appended, so now requests to http://my.domain/some/path/bar
would be proxied to simply http://other.host/foo/
.
So I changed it to a regex
location ~ ^/some/path/(.*) {
resolver 1.2.3.4;
set $proxy_root "other.host/foo"
proxy_pass http://$proxy_root/$1;
}
But that doesn't include any query parameters, so I updated again
location ~ ^/some/path/(.*) {
resolver 1.2.3.4;
set $proxy_root "other.host/foo"
proxy_pass http://$proxy_root/$1?$args;
}
This kinda works, but it means there's a ? in every target address, when only some of the incoming requests actually have a ?query section...
I think I could do some further string manipulation, but this feels like a bit much. Is there a simpler way to proxy_pass as I did originally, but with the proxy target as a variable to force re-resolution?
$is_args
variable instead of hardcoded?
– Alexey Ten