windows IIS 日志文件和负载平衡器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/821352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:23:57  来源:igfitidea点击:

IIS log files and load balancer?

windowsloggingiis-6windows-server-2003

提问by twlichty

We host our ASP.NET applications on two web servers (Server 2003, IIS 6) that reside behind a hardware load balancer. When I look at the IIS logs, the c-ip value in the IIS (v6) logs are ALWAYS the IP address of the load balancer. I noticed in the http headers, there is an X-Forwarded-For header that appears to have the requesting IP address. Is there something I can do to make IIS log this header value in the logs?

我们将 ASP.NET 应用程序托管在位于硬件负载平衡器后面的两台 Web 服务器(Server 2003、IIS 6)上。当我查看 IIS 日志时,IIS (v6) 日志中的 c-ip 值始终是负载均衡器的 IP 地址。我注意到在 http 标头中,有一个 X-Forwarded-For 标头似乎具有请求的 IP 地址。我可以做些什么来让 IIS 在日志中记录这个标头值?

采纳答案by u07ch

When going through a proxy you the x-forwarded-for is what is most commonly usedby load balancers. You can probably write an httpfilterwhich will swap this around yourself; or IIS Tracerhas the ability to play with the standard files; including swapping the c-ip and x-forwarded field.

当通过代理时,x-forwarded-for 是负载均衡器最常用的。您可能可以编写一个httpfilter来自己交换它;或者IIS Tracer能够处理标准文件;包括交换 c-ip 和 x-forwarded 字段。

If this isnt being done for the use of a third party reporting tool; you might want to dump your logs into SQL Server where you can manipulate the columns whenever you want.

如果这不是为了使用第三方报告工具;您可能希望将日志转储到 SQL Server 中,您可以在其中随时操作这些列。

Personally i go for the latter so that i can get aggregate data for all the servers; i dump into different tables in the same db and then report from all the web servers in the farm. I also find it easier than managing 500mb or so log files all over the place.

我个人倾向于后者,以便我可以获得所有服务器的汇总数据;我转储到同一个数据库中的不同表中,然后从场中的所有 Web 服务器报告。我还发现它比到处管理 500 mb 左右的日志文件更容易。

回答by Oliver

I don't know how long it's been around, but the Advanced Logging extensionfor IIS 7 and up(on Windows Server 2008 and up) offers Custom logging functionalitywhich can be used to gather (almost) arbitrary information in IIS log files, including custom HTTP request (and response) headers like X-Forwarded-For.

我不知道它是如何长久以来一直围绕,但高级日志扩展IIS 7及以上(在Windows Server 2008及以上)提供自定义日志记录功能,可用于收集(几乎)在IIS日志文件中的任意信息,包括自定义 HTTP 请求(和响应)标头,如X-Forwarded-For

I've just today set this up on our server and it works beautifully.

我今天刚刚在我们的服务器上设置了它,它运行良好。

One thing to note: instead of editing the default Log Definition by the name of %COMPUTERNAME%-Server, just create a new one on your site or globally on your server to avoid the exception "The request is not supported." when trying to save your changes. This happens when you try to edit that default definition on the site level (thanks to this threadfor the answer).

需要注意的一件事:不要编辑名称为%COMPUTERNAME%-Server的默认日志定义,只需在您的站点上或在您的服务器上全局创建一个新定义,以避免出现“不支持该请求”的异常。尝试保存更改时。当您尝试在站点级别编辑该默认定义时会发生这种情况(感谢此线程的答案)。

回答by JohnW

F5 networks offers an ISAPI filter on devcentral.f5.com that will take x-forwarded-for and use it in the logs.

F5 网络在 devcentral.f5.com 上提供了一个 ISAPI 过滤器,它将采用 x-forwarded-for 并在日志中使用它。

Beyond that, though, there's not much you can do - this is how TCP works. :)

但是,除此之外,您无能为力——这就是 TCP 的工作方式。:)

回答by Rob Potter

This is a pretty old question, but thought I'd add that IIS 8.5 has the ability to write custom HTTP headers to the IIS logs. This is a much nicer option than installing an ISAPI filter or HTTP module.

这是一个很老的问题,但我想我会补充说 IIS 8.5 能够将自定义 HTTP 标头写入 IIS 日志。这是一个比安装 ISAPI 过滤器或 HTTP 模块更好的选择。

This walk through shows how to set this up through IIS Manager: http://www.iis.net/learn/get-started/whats-new-in-iis-85/enhanced-logging-for-iis85

本演练展示了如何通过 IIS 管理器进行设置:http: //www.iis.net/learn/get-started/whats-new-in-iis-85/enhanced-logging-for-iis85

This other SO question shows how to do it with PowerShell: Add IIS 8.5 Custom Logging Fields with Powershell

另一个 SO 问题显示了如何使用 PowerShell 进行操作: Add IIS 8.5 Custom Logging Fields with Powershell

回答by Doolali

IIS 8.5 advanced logging will let you log the X-FORWAREDED-FOR header easily.

IIS 8.5 高级日志记录将让您轻松记录 X-FORWARDED-FOR 标头。

IIS 8.5 Advanced Logging

IIS 8.5 高级日志记录