
我在 nginx 中有以下配置,用於在特定場景下進行重定向。
location /prefix-someurl {
if (condition) {
return 301 $scheme://$host/xyz.html;
}
proxy_pass someValue;
}
在另一個區塊中有一些像這樣的重寫規則
location /someurl {
if (condition) {
rewrite ^(.*)abc(.*)$ $1test/abc$2 break;
rewrite ^(.*)someurl/$(.*) $1someurl/test/index.html$2;
}
proxy_pass value;
}
上述配置按預期工作。但是,如果對於後者我進行此修改;
location /someurl {
if (condition) {
return 301 $scheme://$host/xyz.html;
}
if (condition) {
rewrite ^(.*)abc(.*)$ $1test/abc$2 break;
rewrite ^(.*)someurl/$(.*) $1someurl/test/index.html$2;
}
proxy_pass value;
}
我訪問時遇到太多重定向錯誤/prefix-someurl
.如果我將其修改/someurl
為以下內容,錯誤就會消失;
location /someurl {
if (condition) {
return 301 $scheme://$host/xyz.html;
}
proxy_pass value;
}
我不明白為什麼修改/someurl
會對/prefix-someurl
.或者我是否遺漏了有關 nginx 重寫評估的內容。對此的見解將不勝感激。