鑑於以下http塊,nginx按預期執行。也就是說,它會將一個網址(如http://localhost/3ba48599-8be8-4326-8bd0-1ac6591c2041/
)重寫爲http://localhost/modif/3ba48599-8be8-4326-8bd0-1ac6591c2041/
並將其傳遞給uwsgi服務器。爲什麼我的nginx「重寫」指令導致重定向循環?
http {
upstream frontend {
server frontend:8000;
}
server {
listen 8000;
server_name localhost;
root /www/;
location ~* "^/([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})/?$" {
include uwsgi_params;
set $uuid $1;
if ($cookie_admin) {
# if cookie exists, rewrite /<uuid> to /modif/<uuid> and pass to uwsgi
rewrite//modif/$uuid break;
uwsgi_pass frontend;
}
content_by_lua_block {
ngx.say("Ping! You got here because you have no cookies!")
}
}
}
}
然而,當我以這樣的方式顯示打擊再添location
塊,東西掉下APPART和我ERR_TOO_MANY_REDIRECTS
。
http {
# access_log /dev/stdout; # so we can `docker log` it.
upstream frontend {
server frontend:8000;
}
server {
listen 8000;
server_name localhost;
root /www/;
location/{ # THIS MAKES EVERYTHING FALL APART :(
uwsgi_pass frontend;
include uwsgi_params;
}
location ~* "^/([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})/?$" {
include uwsgi_params;
set $uuid $1;
if ($cookie_admin) {
# if cookie exists, rewrite /<uuid> to /modif/<uuid> and pass to uwsgi
rewrite//modif/$uuid break;
uwsgi_pass frontend;
}
content_by_lua_block {
ngx.say("Ping! You got here because you have no cookies!")
}
}
}
}
究竟發生了什麼?我怎樣才能解決這個問題?
哪個URL導致問題,它被重定向到了什麼地方? –
@RichardSmith,由位置正則表達式捕獲的任何URL(即'/'將導致我注意到的錯誤;我提供了一個這樣的URL在這個問題中的例子,我不知道我怎麼能檢查它被重定向的位置,粗略地看一下chrome開發者工具,似乎表明它一次又一次被相同的位置塊捕獲(但是我再也不確定了) –
blz
我沒有使用chrome,但是它看起來像資源 - >標題標籤應該顯示你的細節。響應標題中的'location'字段是你正在尋找的。因爲你的'nginx'配置似乎沒有產生外部重定向,它可能是從上游應用程序 –