在现代网站架构中,scalability 已经不再是可有可无的质量属性,而是决定着网站的生死攸关,所以稍微上规模的站点都不会只有一个web server,让internet clients 直接与其交互,出于安全性和scale out的考量,一般都会在web server 和用户之间设置Reverse Proxy server 或者 Load-Balancer, 又或者是RP 和 LB 的组合。其好处,网络上已经有较多的资料,此处不再赘述。

下面看一个RP和LB组合使用的例子:

Here is the flow of the requests and responses:

  1. The client gets connected through the
    firewall to thereverse-proxy in the DMZ and send it its request.
  2. The Reverse-Proxy validates the request, analyzes it to choose the right farm then forward it to theload-balancer in the LAN, through the
    firewall.
  3. The Load-balancer choose a
    server
    in the farm and forward the request to it
  4. The server processes the request then answers to the
    load-balancer
  5. The load-balancer forward the response to the
    reverse-proxy
  6. The reverse-proxy forward the response to the
    client

Bascially, the source IP is modified twice on this kind of architecture: during the steps2 and
3.

And of course, the more you chain load-balancer and reverse proxies, the more the source IP will be changed.

那么怎样获取原始IP呢? 因为source IP 对后端应用非常有用,比如根据IP定位用户所在区域,以便提供localized的服务; 根据用户IP做风险评估 (是不是恶意攻击IP?)

一个比较简单的办法是增加一个自定义的HTTP Header -- X-Forwarded-For (XFF) for identifying originating IP address of a client connecting to a web
server through an HTTP Proxy.

当然你也可以根据你公司的naming convention, 定义自己的Header, 比如在eBay,It is X-eBay-Client-IP

eBay内部描述:

Operations
started introducing Layer 7 load balancers (NetScaler) on site. From application server point of view requests arrive with the source IP address of the load balancer. Many eBay applications need to know the source IP address of the client. To support this
requirement we introduce a standard for eBay HTTP header X-eBay-Client-IP.
Netscaler and other similar devices will set this header and applications will know to use it.

参考:

http://blog.exceliance.fr/2012/06/05/preserve-source-ip-address-despite-reverse-proxies/

http://kb.radware.com/questions/2559/How+to+allow+an+application+to+see+the+client+real+source+IP%3F

版权声明:本文为博主原创文章,未经博主允许不得转载。

反向代理及如何获得原始IP的更多相关文章

  1. 查找“CDN、负载均衡、反向代理”等大型网络真实IP地址的方法

    首先,CDN.负载均衡.反向代理还分为很多层,有时查出来的是最外层的 CDN 服务器群,真实的机器是不对外开放的,类似这样的: 用户 → CDN 网络 → 一台或多台真实机器 ↗ CDN Server ...

  2. Apache 2.4.7在CentOS6.4中安装配置反向代理解决单外网IP对应多个内网主机的方法实践

    欢迎转载,转载时请保留全文及出处. Apache 2.4.7在CentOS6.4中安装配置反向代理解决单外网IP对应多个内网主机的方法实践 Apache安装 下载源程序(http://httpd.ap ...

  3. [转]用apache反向代理解决单外网ip对应内网多个web主机的问题

    用apache反向代理解决单外网ip对应内网多个web主机的问题 转载一个有独立外网IP,需内网服务器对外发布的例子,是应用apache虚拟主机的. 来源地址:http://www.itshantou ...

  4. 让pomelo可以获取到反向代理websockets的真实用户IP

    /node_modules/pomelo/lib/connectors/hybridsocket.js 找到 var Socket = function(id, socket) { 给remoteAd ...

  5. nginx反向代理node.js获取客户端IP

    使用Nginx做node.js程序的反向代理,会有这么一个问题:在程序中获取的客户端IP永远是127.0.0.1 如果想要拿到真实的客户端IP改怎么办呢? 一.首先配置Nginx的反向代理 proxy ...

  6. Nginx 反向代理获取设备真实的IP地址

    package com.das.common.util; import org.apache.commons.lang3.StringUtils; import org.springframework ...

  7. Nginx反向代理下IIS获取真实IP

    1. iis 如果放在反向代理后面,日志里的c-ip是反向代理服务器的ip,不是真正用户的ip,想要记录用户的ip要做两件事. 一.在反向代理设置X-Forwarded-For段,以下为nginx下的 ...

  8. nginx反向代理Tomcat/Jetty获取客户端IP地址

    使用nginx做反向代理,Tomcat服务器和Jetty服务器如何获取客户端真实IP地址呢?首先nginx需要配置proxy_set_header,这样JSP使用request.getHeader(& ...

  9. Nginx 反向代理Tomcat服务器获取真实IP问题

    1.nginx.conf 配置 修改 Server location配置 增加 proxy_set_header X-Real-IP $remote_addr; #保留代理之前的真实客户端ip pro ...

随机推荐

  1. CF 628B New Skateboard --- 水题

    CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...

  2. ORACLE PL/SQL编程详解

    ORACLE PL/SQL编程详解 编程详解 SQL语言只是访问.操作数据库的语言,并不是一种具有流程控制的程序设计语言,而只有程序设计语言才能用于应用软件的开发.PL /SQL是一种高级数据库程序设 ...

  3. (MST) HDOJ 1102 Constructing Roads

    怎么说呢 这题就是个模板题 但是 hud你妹夫啊说好的只有一组数据呢??? 嗯??? wa到家都不认识了好吗 #include <cstdio> #include <cstring& ...

  4. Javascript操作Cookie的脚本 — CookieHelper

    var HttpCookie = function(name, value, expires, path, domain) { if (name) this.Name = name; if (valu ...

  5. linux服务之maven

    curl -O http://mirrors.noc.im/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip [root@d ...

  6. HighCharts使用心得

    HighCharts使用心得 前言: 之前很早的一个项目中使用过highcharts,感觉挺方便的,图表类型也比较丰富,而且还支持数据的下钻,但是如果投入商业使用的话还会有一些版权的问题,所以后来就使 ...

  7. [转]Windows系统中监控文件复制操作的几种方式

    1. ICopyHook 作用: 监视文件夹和打印机移动,删除, 重命名, 复制操作. 可以得到源和目标文件名. 可以控制拒绝操作. 缺点: 不能对文件进行控制. 只对Shell文件操作有效, 对原生 ...

  8. 使用新浪云(SAE)实现基于mySql和微信公众平台的关键字请求响应服务

    本例是作者初次尝试微信公众平台开发之作,实现传统的关键字请求响应功能.即:用户发关键字,公众号通过关键字进行检索, 在mysql数据库中读取与关键字相关的信息,并返回给用户.本例在微信订阅号(开发者模 ...

  9. 黄聪:WordPress: 使用 wp_insert_attachment 上传附件

    我们来研究一下如何在主题或者插件的开发中上传附件: 主要参考这个函数:https://codex.wordpress.org/Function_Reference/wp_insert_attachme ...

  10. sql查询指定范围内的所有月份

    ),) FROM master..spt_values WHERE type='P' AND DATEADD(MONTH,number,'2016-01-01')<='2017-01-01'