Nginx位置和反向代理配置无法正常工作

时间:2019-09-29 15:26:38

标签: nginx nginx-location nginx-reverse-proxy nginx-config

当前,使用以下配置将“ / _webapi”下的所有请求转发到http://myproject.webapi/api

upstream web_api {
    server myproject.webapi:80;
}
server {
    location /_webapi {
        proxy_pass         http://web_api/api;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}

现在,我要删除“ / api”部分。在我从Web-api进行了一些配置并使用了此配置后,看来它不起作用:

server {
    location /_webapi {
        proxy_pass         http://web_api;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}

如果直接访问http://myproject.webapi/valueshttp://myproject.webapi/weatherforecast可以正常工作。但是,当使用http://localhost/_webapi/valueshttp://localhost/_webapi/weatherforecast之类的URL通过Nginx反向代理时,它不起作用。

0 个答案:

没有答案