如果在 nginx proxy_pass 中指定了 URI 的上游伺服器重定向,則出現意外重定向

如果在 nginx proxy_pass 中指定了 URI 的上游伺服器重定向,則出現意外重定向

這是我的反向代理伺服器區塊

server {
    listen 80;
    server_name test.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header HOST $host;
    }
}

我在上游伺服器中創建了所有端點,沒有尾隨斜杠,將所有尾隨斜杠端點重定向到上游伺服器中的非尾隨斜杠端點,test.com/foo/將重定向到test.com/foo,一切都很好,直到我想要代理test.comhttp://127.0.0.1:8080/app/,這是伺服器區塊

server {
    listen 80;
    server_name test.com;

    location / {
        proxy_pass http://127.0.0.1:8080/app/;
        proxy_set_header HOST $host;
    }
}

這就是發生的事情:

  1. test.com重定向到test.com/app, 期望test.com
  2. test.com/foo仍然和預期一樣
  3. test.com/foo/重定向到test.com/app/foo, 期望test.com/foo

找不到解決方案,有幫助嗎?

相關內容