微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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
%

原文地址:https://www.jb51.cc/nginx/434993.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐