nginx代理程式為什麼要重新導向請求?

nginx代理程式為什麼要重新導向請求?

我正在嘗試將 API 請求傳遞到後端NGINX 反向代理。

當我發送一個 get 請求到/api/testdata,它發送一個請求到{frontendURL}/api/testData其中,傳回 301(重定向)狀態碼。之後它將請求重定向到正確的 url{backendURL}/api/testData

網路選項卡 網路選項卡 1 網路選項卡 2 網路選項卡 3

nginx 設定:

server {
    listen 80 default_server;
    listen [::]:80 default_server;



    root /usr/share/nginx/html;

    server_name _;

    location /health {
            access_log off;
            add_header 'Content-Type' 'application/json';
            return 200 '{"status":"Healthy"}';
    }

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
    }

    location /api {
        proxy_pass http://localhost:3001; 
        proxy_redirect off;
    }

我可以以某種方式阻止重定向請求,以便只有一個請求發出嗎?還是這是正常行為?

相關內容