I would like to have nginx set as a reverse proxy following these rules:
http://www.example.com/home/{x}/{y}//index.html?zvalue={z}&a=1&b=2&c=3 etc...
proxied to
http://www.example2.com/home/{x}/{y}/{z}/index.html?a=1&b=2&c=3 etc...
So basically the query string value of {z} is set as part of the path. All other query params such as a,b,c,d etc need to be forwarded as shown in the example.
What are the configuration I need to put in nginx?
Manipulating the query string is best done using a map with named captures. See this document for details.
For example:
map $request_uri $proxy {
default 0;
~*^(?<prefix>/home/.*)/index.html\?zvalue=(?<zvalue>[^&]+)&(?<suffix>.*)$ $prefix/$zvalue/index.html?$suffix;
}
Obviously the regular expression needs to match your exact requirements, and the above was just a proof of concept.
You can use the variable with a proxy_pass statement, within an if block, within an existing location. See this document for details.
For example:
location / {
proxy_pass http://example.com;
if ($proxy) { proxy_pass http://example.com$proxy; }
}
Any request which is not subject to the map will be passed transparently by the first proxy_pass statement.