2

I have a Nginx proxy configured for a Minio S3 object storage server.

Can I remove some of the query params (more than one agrs) when I'm passing a request to the upstream (Minio) and keep the rest of args?

for example: this is the request that received by Nginx:

/my-private-bucket/my-image.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&w=320&X-Amz-Date=20211218T231908Z&h=200

I need to transform the above link to the below link (i.e. removing the extra args: w=320 and h=200) and then use proxy_pass:

/my-private-bucket/my-image.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20211218T231908Z

Of course I can use multiple IF statements in the location block: Here is a sample or this one. but I think there should be something more rational. Something like using regex and sed in bash:

echo [mentioned uri] | sed -E 's/&?[wh]=[0-9]*//g'

...or even using map blocks in Nginx:

map $args $polished-args
{
    default $args
    ~&?[wh]=[0-9]* ((something magical))
}

Any ideas?

1 Answers1

0

If you can work the other way around, that is, pass a known list of parameters, you can use:

proxy_pass http://backend.example.com/path?param1=$arg_param1&param2=$arg_param2

If the argument order of dropped keys stays always the same, then you can use map:

map $args $cleaned_args {
    default $args;
    ^(.*)[?&]w=[0-9]+(.*)&h=[0-9]+(.*)$ $1$2$3;
    ^(.*)[?&]h=[0-9]+(.*)&w=[0-9]+(.*)$ $1$2$3;
}

The regular expression captures everything before &w or ?w, then everything before &h and the rest into capture groups. The second option does the same for opposite parameter ordering.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63