nginx proxy_pass和URL解码

原始网址:/ api / url / encoded //?with = queryParams

Nginx的:

location /api {
    client_max_body_size 2G;
    proxy_pass https://oursite;
}

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

问题:

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

最佳答案

Not a long time ago there was identical question without an answer. In my opinion,you should rething api to not have such weird URLs. Another way is to have api on subdomain. – Alexey Ten Mar 11 ’15 at 22:58

stackoverflow.com/q/28684300/1016033 – Alexey Ten Mar 11 ’15 at 23:01

接受了一年的挑战!

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

伙计就是这样!

更多细节在Nginx pass_proxy subdirectory without url decoding,但它甚至可以使用查询字符串:

%  curl "localhost:81/api/url%2Fencoded%2F/?with=queryParams"
/url%2Fencoded%2F/?with=queryParams
%

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...