原始网址:/ 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
%