Я создал простое базовое веб-приложение ASP.NET (в виде API), и все отлично работает в Windows.Я пытаюсь запустить его через обратный прокси-сервер на Nginx, и приложение завершается с ошибкой аутентификации:
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://ite.photosite.shop/Ite/Status
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://ite.photosite.shop/Ite/Status
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method IteWebCore.Controllers.IteController.Status (IteWebCore) with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method IteWebCore.Controllers.IteController.Status (IteWebCore) with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.ForbidResult[1]
Executing ForbidResult with authentication schemes ().
info: Microsoft.AspNetCore.Mvc.ForbidResult[1]
Executing ForbidResult with authentication schemes ().
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action IteWebCore.Controllers.IteController.Status (IteWebCore) in 48.0151ms
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action IteWebCore.Controllers.IteController.Status (IteWebCore) in 48.0151ms
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLDAN95N3T3V", Request id "0HLDAN95N3T3V:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: No authenticationScheme was specified, and there was no DefaultForbidScheme found.
at Microsoft.AspNetCore.Authentication.AuthenticationService.<ForbidAsync>d__12.MoveNext()
Работает нормально, напрямую через Kestral через порт 5000 (выглядит так):
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:5000/Ite/Status
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method IteWebCore.Controllers.IteController.Status (IteWebCore) with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:5000/Ite/Status
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method IteWebCore.Controllers.IteController.Status (IteWebCore) with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.Internal.ContentResultExecutor[1]
Executing ContentResult with HTTP Response ContentType of text/html
info: Microsoft.AspNetCore.Mvc.Internal.ContentResultExecutor[1]
Executing ContentResult with HTTP Response ContentType of text/html
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action IteWebCore.Controllers.IteController.Status (IteWebCore) in 10.979ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 12.1335ms 200 text/html
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action IteWebCore.Controllers.IteController.Status (IteWebCore) in 10.979ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 12.1335ms 200 text/html
Я перепробовал все предложения о различных способах настройки службы аутентификации, текущий класс запуска выглядит следующим образом:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthentication(Microsoft.AspNetCore.Server.HttpSys.HttpSysDefaults.AuthenticationScheme);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller=Ite}/{action=Execute}");
});
}
}
Текущая конфигурация nginx выглядит следующим образом:
server {
listen 80;
server_name ite.photosite.shop;
access_log /var/log/nginx/ite-photosite-access.log;
error_log /var/log/nginx/ite-photosite-error.log notice;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
}
}
Что я взял из этой инструкции по развертыванию на linux .Несмотря на то, что в настоящее время я не выполняю аутентификацию, я также добавил (и удалил, и попробовал каждую комбинацию):
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
В разделе конфигурации.
Каждый раз, когда я получаю одну и ту же ошибку.
Редактировать - добавлен класс запуска