删除编码值为nginx的path段

我有一个像下面的location

 location ^api/([^/]+)(/.+)$ { set $my_host $1; set $my_path $2; proxy_pass http://$myhost$my_path$is_args$args; } 

对于大多数正常情况下,如/api/foo/bar?1234

但是,当我介绍特殊的URL编码值,南下。 当URI是/api/foo/bar[%7B%7D]$my_path被解码,并作为/foo/bar[{}]传递给$my_host 。 这不是一个有效的url

我试图通过使用条件来匹配$request_uri$uri来解决NGINX的限制,但是结果要么是双重编码的,要么是未编码的。

 location ~* ^api/([^/]+)(/.+)$ { set $my_host $1; if ( $request_uri ~* ^api/([^/]+)(/.+)$ ) { set $my_path $2; } proxy_pass http://$myhost$my_path$is_args$args; } 

在上面的例子中, $my_path/foo/bar[%257B%257D]

我也尝试使用第二个正则expression式的set misc模块中的set_unescape_uri

我怎样才能让NGINX以与客户端提供的格式相同的格式删除path组件?

我猜想set_unescape_uri和正则expression式variables或其他东西是错误的。 使用set_unescape_uri的单参数forms工作。

 location ~* ^api/([^/]+)(/.+)$ { set $my_host $1; if ( $request_uri ~* ^api/([^/]+)(/.+)$ ) { set $my_path $2; set_unescape_uri $my_path; } proxy_pass http://$myhost$my_path$is_args$args; }