`

use x-forwarded-for

    博客分类:
  • web
 
阅读更多

X-Forwarded-For (XFF )是用来识别通过HTTP 代理负载均衡 方式连接到Web服务器 的客户端最原始的IP地址 的HTTP请求头字段。 Squid 缓存代理服务器的开发人员最早引入了这一HTTP头字段,并由IETFForwarded-For HTTP头字段标准化草案 中正式提出。

当今多数缓存服务器的使用者为大型ISP,为了通过缓存的方式来降低他们的外部带宽,他们常常通过鼓励或强制用户使用代理服务器来接入互联网 。有些情况下, 这些代理服务器是透明代理, 用户甚至不知道自己正在使用代理上网。

如果没有XFF或者另外一种相似的技术,所有通过代理服务器的连接只会显示代理服务器的IP地址(而非连接发起的原始IP地址), 这样的代理服务器实际上充当了匿名服务提供者的角色, 如果连接的原始IP地址不可得,恶意访问的检测与预防的难度将大大增加。XFF的有效性依赖于代理服务器提供的连接原始IP地址的真实性,因此, XFF的有效使用应该保证代理服务器是可信的, 比如可以通过建立可信服务器白名单的方式。

 

格式

这一HTTP头一般格式如下:

X-Forwarded-For: client1, proxy1, proxy2

其中的值通过一个 逗号+空格 把多个IP地址区分开, 最左边(client1)是最原始客户端的IP地址, 代理服务器每成功收到一个请求,就把请求来源IP地址 添 加到右边。 在上面这个例子中,这个请求成功通过了三台代理服务器:proxy1, proxy2 及 proxy3。请求由client1发出,到达了proxy3(proxy3可能是请求的终点)。请求刚从client1中发出时,XFF是空的,请求被 发往proxy1;通过proxy1的时候,client1被添加到XFF中,之后请求被发往proxy2;通过proxy2的时候,proxy1被添加 到XFF中,之后请求被发往proxy3;通过proxy3时,proxy2被添加到XFF中,之后请求的的去向不明,如果proxy3不是请求终点,请 求会被继续转发。

鉴于伪造这一字段非常容易,应该谨慎使用X-Forwarded-For字段。正常情况下XFF中最后一个IP地址是最后一个代理服务器的IP地址, 这通常是一个比较可靠的信息来源。

 

apache日志中 X-Forwarded-For 参数的设定

apache 日志中可以设定 X-Forwarded-For 参数来获取客户端真实的ip地址

对于使用了反向代理的客户端,跟踪真实的ip地址
X-Forwarded-For header is supported by most proxy servers, including Squid,[1] Apache mod_proxy,[2] Pound,[3] Varnish cache,[4] IronPort Web Security Appliance,[5] Radware AppXcel, F5 Big-IP, [6] Blue Coat ProxySG, Cisco Cache Engine, Phion Airlock, Finjan's Vital Security, NetApp NetCache, jetNEXUS, Crescendo Networks' Maestro, and Microsoft ISA Server 2004/2006 with Winfrasoft X-Forwarded-For for ISA Server.[7]
X-Forwarded-For header logging is supported by many web servers including Apache and Microsoft IIS 6.0 & 7.0 with the addition of Winfrasoft X-Forwarded-For for IIS.[7]

##########################################
this is a apache's seting for X-Forwarded-For (f5):

%{X-Forwarded-For}i

LogFormat "%{X-Forwarder-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" f5_forwarder
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

SetEnvIf X-Forwarder-For "^.*\..*\..*\..*" is-forwarder

CustomLog logs/access_log combined env=!is-forwarder
CustomLog logs/access_log f5_forwarder env=is-forwarder

 

http://zh.wikipedia.org/wiki/X-Forwarded-For

 

分享到:
评论

相关推荐

    gin-gonic-realip:Gin的Real IP中间件将http.Request的RemoteAddr设置为解析X-Forwarded-For标头或X-Real-IP标头的结果

    的Real IP中间件,将http.Request的RemoteAddr设置为解析X-Forwarded-For标头或X-Real-IP标头的结果。 用法 package main import ( "github.com/gin-gonic/gin" "github.com/thanhhh/gin-gonic-realip" ) func ...

    express-extras:ExpressJS 附加功能

    当使用代理(如 nginx)时,此中间件模块尝试将req.socket.remoteAddress和headers['x-forwarded-for'] req.ip为req.ip var extras = require('express-extras'); app.configure(function() { app.use(extras....

    PHP代理脚本php-proxy.zip

     $event['request']->headers->set('X-Forwarded-For', 'php-proxy'); }); $proxy->getEventDispatcher()->addListener('request.sent', function($event){  if($event['response']->getStatusCode() != 200){...

    remote_ip:一个插件,用于基于转发头重写Plug.Conn的remote_ip

    可以识别通用逗号分隔的标头,例如X-Forwarded-For , X-Real-Ip和X-Client-Ip ,以及 Forwarded标头。 您可以指定任意数量的转发头来识别甚至配置自己的解析器。 IP的处理是从后到先的,以防止IP欺骗。 默认情况下...

    tomcat8 + nginx + memcached + cas 实现负载均衡的配置包

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; index index....

    SFC模拟器00000

    Snes9x is freeware for PERSONAL USE only. Commercial users should seek permission of the copyright holders first. Commercial use includes charging money for Snes9x or software derived from Snes9x. ...

    计算机网络第六版答案

    First, the content provider has more control over the user experience, since it has to use few intermediary ISPs. Second, it can save money by sending less traffic into provider networks. Third, if ...

    depends22_x64

    Dependency Walker 最新版, dll 依赖项查看工具. ...Dependency Walker is completely free to use. However, you may not profit from the distribution of it, nor may you bundle it with another product.

    Nginx+Tomcat负载均衡

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; proxy_...

    SIP - Understanding the Session Initiation Protocol, 2nd Ed - 1459

    x SIP: Understanding the Session Initiation Protocol 5.4.32 489 Bad Event 122 5.4.33 491 Request Pending 122 5.4.34 493 Request Undecipherable 122 5.5 Server Error 123 5.5.1 500 Server Internal Error ...

    Java邮件开发Fundamentals of the JavaMail API

    * Use search terms to search for messages Prerequisites Instructions on how to download and install the JavaMail API are contained in the course. In addition, you will need a development ...

Global site tag (gtag.js) - Google Analytics