nginx proxy_pass 和 URL 解码 [英] nginx proxy_pass and URL decoding
问题描述
原始网址:/api/url%2Fencoded%2F/?with=queryParams
Original URL: /api/url%2Fencoded%2F/?with=queryParams
nginx:
location /api {
client_max_body_size 2G;
proxy_pass https://oursite;
}
使用此配置,我能够在通过代理时保留 URL 编码.如果我在oursite"后添加/",它会解码 URL.
With this configuration, I was able to preserve the URL encoding when passing through the proxy. If I add a "/" after "oursite", it will decode the URL.
问题:
现在代理后的 URL 仍然包含/api/".我只需要删除/api/",同时仍然保留 URL 编码部分.
Now the URL after being proxied still contains "/api/". I need to remove "/api/" only while still preserving the URL encoded parts.
推荐答案
不久前有相同的问题没有答案.在我看来,您应该重新设置 api 以免出现如此奇怪的 URL.另一种方法是在子域上使用 api.– 阿列克谢十 15 年 3 月 11 日,22:58
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 10 2015 年 3 月 11 日 23:01
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 子目录,无需 url 解码,但它也适用于查询字符串:
More details at Nginx pass_proxy subdirectory without url decoding, but it does work even with the query string, too:
% curl "localhost:81/api/url%2Fencoded%2F/?with=queryParams"
/url%2Fencoded%2F/?with=queryParams
%
这篇关于nginx proxy_pass 和 URL 解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!