0

在我的 .net 核心应用程序的日志中,我可以看到所有请求的 URL 前面都带有反斜杠。该应用程序使用 .net core 2.0 托管在 Amazon Linux 2 上。这是请求中使用 url 的方式:http://www.mvc.meetcorepoint.com/这是 .net core 接收到的 url http://\www.mvc.meetcorepoint.com/。这是日志的一部分,也显示了其他 url:

dotnet-ids.mvc[22185]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
dotnet-ids.mvc[22185]: Request starting HTTP/1.1 GET http://\www.mvc.meetcorepoint.com/
dotnet-ids.mvc[22185]: info:     Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
dotnet-ids.mvc[22185]: Executing action method     MvcClient.Controllers.HomeController.Index (MvcClient) with arguments ((null)) -
dotnet-ids.mvc[22185]: info:     Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor[1]
dotnet-ids.mvc[22185]: Executing ViewResult, running view at path     /Views/Home/Index.cshtml.
dotnet-ids.mvc[22185]: info:     Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
dotnet-ids.mvc[22185]: Executed action     MvcClient.Controllers.HomeController.Index (MvcClient) in 0.5249ms
dotnet-ids.mvc[22185]: info:     Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
dotnet-ids.mvc[22185]: Request finished in 0.7982ms 200 text/html;     charset=utf-8
dotnet-ids.mvc[22185]: info:     Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
dotnet-ids.mvc[22185]: Request starting HTTP/1.1 GET     http://\www.mvc.meetcorepoint.com/lib/bootstrap/dist/css/bootstrap.css
dotnet-ids.mvc[22185]: info:     Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
dotnet-ids.mvc[22185]: Sending file. Request path: '/lib/bootstrap/dist/css/bootstrap.css'. Physical path: '/var/www/dotnet/ids
dotnet-ids.mvc[22185]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
dotnet-ids.mvc[22185]: Request finished in 1.6629ms 200 text/css
dotnet-ids.mvc[22185]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
dotnet-ids.mvc[22185]: Request starting HTTP/1.1 GET http://\www.mvc.meetcorepoint.com/css/site.css
dotnet-ids.mvc[22185]: info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
dotnet-ids.mvc[22185]: Sending file. Request path: '/css/site.css'. Physical path: '/var/www/dotnet/ids.mvc/wwwroot/css/site.cs
dotnet-ids.mvc[22185]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
dotnet-ids.mvc[22185]: Request finished in 0.3626ms 200 text/css
4

1 回答 1

1

事实证明,这与 Linux 无关,也与 .net 核心本身无关。问题出在我的 nginx 配置中,该配置用作 .net 核心应用程序的反向代理。当我从网络处理代理 nginx 配置时,它以某种方式在UpgradeandHost标头上添加了反斜杠。所以proxy_set_header Host $host;我没有使用proxy_set_header Host \$host;

于 2018-02-24T11:40:09.363 回答