I have experimented with regex and rewrites but was unsuccessful mainly
because regex on “location” directive does not apply to url parameters.
And
rewrites do not allow me to change the outgoing port number.
I had also tried to use
if ($args ~ "p=(\d+)") {
set $port $1;
rewrite ^ ??????
}
But I ended up with either a browser redirect which is not desirable, or
I
ended up sending traffic to local file which does not exist.
Unfortunately I cannot change the incoming request to include ‘1234’ as
part
of path, e.g. http://foobar.com/p/1234/. I have no control of that.
Thanks for the advice on $arg_PARAMETER. It allows me to retrieve the
parameter. However I am not able to use it as a port number for
proxy_pass.
This shows that I can get the parameter and use it in rewrite:
location /test {
rewrite ^ Google;
}
This does not work. Got error “no resolver defined to resolve www.google.com” in log.
location /path {
proxy_pass Google;
}
This shows that I can use the parameter in a rewrite prior to
proxy_pass:
location /path {
rewrite ^(.*)$ /?q=$arg_p break;
proxy_pass http://www.google.com/;
}
Unfortunately I still can’t use the paramrter value as an upstream port
number:
location /path2 {
rewrite ^(.*)$ :$arg_p break;
proxy_pass http://www.google.com;
}