反向代理及如何获得原始IP

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

在现代网站架构中,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

相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
目录
相关文章
|
应用服务中间件 nginx
JavaWeb - 获取客户端真实 IP(通过反向代理 Nginx)非服务器 IP(二)
JavaWeb - 获取客户端真实 IP(通过反向代理 Nginx)非服务器 IP(二)
377 0
|
10月前
|
域名解析 存储 负载均衡
实现服务器多IP的实现方法
实现服务器多IP的实现方法
275 1
|
应用服务中间件 定位技术 nginx
Nginx反向代理后无法获取客户端真实IP地址
当我们使用 Nginx 代理转发服务后,会发现我们无法获取客户端的真实IP地址,从而无法获取客户端的地理位置等信息。
579 0
|
负载均衡 Java 应用服务中间件
【Nginx】如何获取客户端真实IP、域名、协议、端口?看这一篇就够了!
Nginx最为最受欢迎的反向代理和负载均衡服务器,被广泛的应用于互联网项目中。这不仅仅是因为Nginx本身比较轻量,更多的是得益于Nginx的高性能特性,以及支持插件化开发,为此,很多开发者或者公司基于Nginx开发出了众多的高性能插件。使用者可以根据自身的需求来为Nginx指定某款插件以增强Nginx在某种特定场景下的功能或者提升Nginx在某种特定场景下的性能。
1353 0
|
缓存 负载均衡 应用服务中间件
【Nginx】如何封禁IP和IP段?看完这篇我会了!!
Nginx不仅仅只是一款反向代理和负载均衡服务器,它还能提供很多强大的功能,例如:限流、缓存、黑白名单和灰度发布等等。在之前的文章中,我们已经介绍了Nginx提供的这些功能。小伙伴们可以到【Nginx专题】进行查阅。今天,我们来介绍Nginx另一个强大的功能:禁用IP和IP段。
421 0
|
监控 负载均衡 应用服务中间件
X-Forwarded-For 负载均衡 7 层 HTTP 模式获取来访客户端真实 IP 的方法(IIS/Apache/Nginx/Tomcat)
https://help.aliyun.com/knowledge_detail/13051859.html?pos=1 1、IIS 6 配置方案2、IIS 7 配置方案3、Apache 配置方案4、Nginx 配置方案5、Tomcat 配置方案 4 层负载均衡(TCP 协议)服务可以直接在后端 ECS 上获取来访者真实 IP 地址,无需进行额外的配置,以下介绍的内容均是针对 7 层(HTTP 协议)的负载均衡服务而言。
4935 0
|
负载均衡 网络协议 网络架构
|
监控 应用服务中间件 nginx
首层nginx 传递 二级代理nginx 客户端真实IP的方法
首层nginx:先获取真实IP($remote_addr),再将真实IP传递给X-Forwarded-For    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $remote_addr; 二级代理nginx:设置从上级nginx传递过来的X-Forwarded-For为真实IP,日志文件设置获取用户真实IP的变量设置为$remote_addr即可。
2008 0
|
负载均衡 应用服务中间件 nginx
nginx做反向负载均衡,后端服务器获取真实客户端ip
nginx增加header配置 server { listen 80; server_name admin.
1368 0
|
应用服务中间件 nginx 运维