【发布时间】:2021-08-21 22:57:47
【问题描述】:
我想在内部将多个位置 /customers/foo?bar=2 重写为我的 nginx 配置中/blah 的现有位置,这样就好像请求是针对/blah/customers/foo?bar=2。
location /blah {
# View in fiddler
proxy_pass http://127.0.0.1:8888/;
# Lots of config here I don't want to repeat everywhere else
}
location /customers/ {
rewrite ^/customers/(.*) /blah/customers/$1$is_args$args;
}
location /other/ {
rewrite ^/other/(.*) /blah/other/$1$is_args$args;
}
# etc...
Nginx 正在使用编码为路径/blah/customers/foo%34bar=2 的查询字符串重写 URL。
rewrite ^ /blah$request_uri; 也会发生同样的事情。它将? 编码为%3F,有效地混淆了URL。
如果我执行客户端重定向 rewrite ^ /blah$request_uri permanent;,则 URL 是正确的并且包含 ?,但我想要在我的 NGINX 配置中进行内部重定向。
【问题讨论】:
标签: nginx