gpt4 book ai didi

asp.net-core - Kestrel 在提供流量时抛出 "Invalid Host header"错误

转载 作者:行者123 更新时间:2023-12-01 17:46:40 25 4
gpt4 key购买 nike

我们最近将 ASP.NET MVC 5 应用程序迁移到 ASP.NET Core 2.2。

一切似乎都工作正常,但是我们经常收到以下异常(大约每秒三次,稍后会详细介绍):

BadHttpRequestException: Invalid Host header: '~^appname.*$'
Module "Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException", line 0, col 0, in Throw
Void Throw(Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.RequestRejectionReason, System.String)
Module "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection", line 95, col 0, in EnsureHostHeaderExists
Void EnsureHostHeaderExists()
Module "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection", line 196, col 0, in TryParseRequest
Boolean TryParseRequest(System.IO.Pipelines.ReadResult, Boolean ByRef)
Module "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol+<ProcessRequests>d__185`1", line 170, col 0, in MoveNext
Void MoveNext()
Module "System.Runtime.ExceptionServices.ExceptionDispatchInfo", line 12, col 0, in Throw
Void Throw()
Module "System.Runtime.CompilerServices.TaskAwaiter", line 46, col 0, in HandleNonSuccessAndDebuggerNotification
Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
Module "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol+<ProcessRequestsAsync>d__184`1", line 135, col 0, in MoveNext
Void MoveNext()

在咨询我们的运营团队成员后,很明显我们有三个 HAProxy 实例,大约每秒检查一次应用程序的每个节点。

对此应用程序的每个请求都将按如下方式流动:

HAProxy -> Nginx -> Kestrel/ASP.NET Core 应用程序

我的问题是,我如何确定这里发生了什么?

最佳答案

当前版本的 Kestrel(我们使用的是 ASP.NET Core 2.2)不支持 HTTP 访问日志记录。

查看此问题:Support access logging with Common Log Format/Extended Log Format

为了追踪问题,我必须让我们的运营团队检查我们的 nginx 日志(nginx 是我们正在使用的反向代理),以确定带有无效主机 header 的请求来自何处。

问题原来是状态检查应用程序配置错误。

关于asp.net-core - Kestrel 在提供流量时抛出 "Invalid Host header"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56136772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com