加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx proxy_pass和URL解码

发布时间:2020-12-13 21:06:16 所属栏目:Nginx 来源:网络整理
导读:原始网址:/ api / url / encoded //?with = queryParams nginx的: location /api { client_max_body_size 2G; proxy_pass https://oursite;} 通过此配置,我可以在通过代理时保留URL编码.如果我在“ourite”之后添加“/”,它将解码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
%

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读