0
votes

I have some issues with a "basic" rewriting rule under a proxy_pass location type :

location ~* /test1/network/v1/operator/ke3/dataUp {
              rewrite ^(?<begin>/test1/network/v1/operator/ke3/dataUp)(?<parametersPart>.*)(?<mustDie>/dataUp)$ $parametersPart break;
              proxy_pass http://server_preproduction;
              proxy_set_header X-Real-IP  $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Forwarded-Proto https;
              proxy_set_header X-Forwarded-Port 443;
              proxy_set_header Host $host;
       }

I expect any calls sent to : .../test1/network/v1/operator/ke3/dataUp?param1=GHJ&param2=865/dataUp

To be equal to : .../test1/network/v1/operator/ke3/dataUp?param1=GHJ&param2=865

So I just want to parse the parameters section in order to remove any extra /dataUp from the original request. But when I try to use any kind of regex to do so, nginx seems to return to the location / and use the default request...

I'm sure that the proper location is use, becanse when I use a rewrite like : rewrite ^(?<begin>/test1/network/v1/operator/ke3/dataUp)(?<parametersPart>.*)$ TEST$parametersPart break; The log on the proxy server received : TEST?param1=GHJ&param2=865/dataUp

I do not add a / at the end of the proxy_pass because I want replace all the url.(but it's not mandatory ! I tried lot of combinations...)

If someone can save my day :p

Thanks !!

1
Your rewrite statement will not work. The query string is not part of the normalized URI used to match rewrite and location directives. - Richard Smith
@RichardSmith hey thanks for your response, but obvisouly I need more precision I read the documentation and try another type or URI, I catch the request but I can parse it "completly" during the rewrite. So the rewrite do something for example I can parse the first part of the URI / test1/network/v1/operator/ke3/dataUp and the second part with the arguments, but I can't parse the argument distinctly... - Mech45

1 Answers

0
votes

I find a way to manipulate the argument with a simple if statement...

    if ($query_string ~ "^(?<argsok>/dataUp.*)(?<argsko>/dataUp)$") {
        proxy_pass http://server_preproduction/$argsok;
    }