当前,使用以下配置将“ / _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/values
和http://myproject.webapi/weatherforecast
可以正常工作。但是,当使用http://localhost/_webapi/values
或http://localhost/_webapi/weatherforecast
之类的URL通过Nginx反向代理时,它不起作用。