ASP.NET在linux上的nginx背后



我目前正在学习ASP。NET上发布了我的第一个应用程序。现在我试着把它放在nginx后面。

location / {
try_files $uri $uri/ @dotnet;
}
location @dotnet {
proxy_pass         http://localhost:5000;
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;
}

但这会导致403。在日志中,它说目录列表被禁止用于/path/to/wwwroot/

目前我正在使用

location / {
proxy_pass         http://localhost:5000;
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;
}

但通过这种方式,静态文件由Kestrel提供。

万一其他人有这个问题,下面是我解决它的方法:

root /path/to/wwwroot;
location / {
try_files $uri @dotnet;
}
location @dotnet {
proxy_pass         http://localhost:5000;
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;
}

替换try_files$uri$uri/@dotnet;具有try_files$uri@dotnet;

最新更新