gpt4 book ai didi

nginx - 在用作代理 (proxy_pass) 时如何避免 nginx 将 %20 替换为空格?

转载 作者:行者123 更新时间:2023-12-04 16:35:55 25 4
gpt4 key购买 nike

我使用 nginx 作为 apache 服务器的代理。

这是我的配置:

location ~ ^/subsite/(.*)$ {
proxy_pass http://127.0.0.1/subsite/$1?$query_string;
}

问题是,如果我使用 %20 发送请求,例如 mywebsite.com/subsite/variable/value/title/Access%20denied/another/example

%20 被空格替换,apache 不关心 Access/title/Access 之后的所有请求结束

任何的想法 ?

最佳答案

我能够解决一个类似的问题——我们有一个 api,它要求搜索词成为 URL 路径的一部分。将输出直接传递给 proxy_pass 指令会导致它抛出 502,即使请求是正确的 url 编码。

这是我们提出的解决方案:

location ~ /api/search(/.*) {
set $query $1;
proxy_pass http://127.0.0.1:3003$query;

}

“set”指令似乎保持 url 编码完整(或从正则表达式在 $1 中传回的内容重新编码)。

关于nginx - 在用作代理 (proxy_pass) 时如何避免 nginx 将 %20 替换为空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8838905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com