【问题标题】:Ngnix not matching location adressNginx 不匹配位置地址
【发布时间】:2020-02-22 14:16:56
【问题描述】:
我对 Nginx + .Net 核心有疑问。我只在带有“/”的位置块上使用默认的 nginx 配置,任何其他位置块(如“/api”)都不起作用。这是我的配置文件
location /api{
proxy_pass https://localhost:5002/api/;
}
location /auth
{
proxy_pass https://localhost:5002/auth/;
}
location /
{
proxy_pass https://localhost:5002/; #home adress of spa app
}
【问题讨论】:
标签:
c#
nginx
asp.net-core
hosting
single-page-application
【解决方案1】:
这是因为您在代理传递的末尾指定了一个 URI,这意味着该位置也将附加到 URI。检查以下示例:
www.site.com/api -> http://localhost:5002/api/api
www.site.com/auth -> http://localhost:5002/auth/auth
相反,不要在位置中提供 URI,以便路径匹配。像这样:
location /api {
proxy_pass http://localhost:5002;
}
location /auth {
proxy_pass http://localhost:5002;
}
location / {
proxy_pass https://localhost:5002/; #home adress of spa app
}
所以现在 URI 是这样结束的。
www.site.com/api -> http://localhost:5002/api/
www.site.com/auth -> http://localhost:5002/auth
PD.- 检查您所在位置的 https:// 架构,您真的需要它吗?使用 http,我认为您没有为该端口启用 SSL。