nginx proxy_pass和URL解码

Sea*_*lin 8 nginx

原始网址:/ api/url%2已编码%2F /?with = queryParams

nginx的:

location /api {
    client_max_body_size 2G;
    proxy_pass https://oursite;
}
Run Code Online (Sandbox Code Playgroud)

使用此配置,我可以在通过代理时保留URL编码.如果我在"ourite"之后添加"/",它将解码URL.

问题:

现在代理后的URL仍然包含"/ api /".我只需要在保留URL编码部分的同时删除"/ api /".

cns*_*nst 14

不久之前,没有答案就有同样的问题.在我看来,你应该知道没有这样奇怪的URL.另一种方法是在子域上使用api. - 阿列克谢十月十一日2015年3月11日22:58

stackoverflow.com/q/28684300/1016033 - Alexey十月十一日2015年3月11日23:01

接受了一年的挑战!

    location /api/ {
        rewrite ^ $request_uri;
        rewrite ^/api/(.*) $1 break;
        return 400;
        proxy_pass http://127.0.0.1:82/$uri;
    }
Run Code Online (Sandbox Code Playgroud)

伙计就是这样!

Nginx pass_proxy子目录中没有url解码的更多细节,但它甚至可以与查询字符串一起工作:

%  curl "localhost:81/api/url%2Fencoded%2F/?with=queryParams"
/url%2Fencoded%2F/?with=queryParams
%
Run Code Online (Sandbox Code Playgroud)