确定客户的亚马逊ELB背后的IP地址 [英] Determine IP Address of Client Behind Amazon ELB

查看:2028
本文介绍了确定客户的亚马逊ELB背后的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们对后面ELB EC2一些PHP服务器。我们想通过连接到我们的服务器的客户端的IP地址,以确定区域设置/地区。现在的问题是PHP的服务器只能看到ELB的IP地址。我们希望看到通过ELB通过客户端的IP地址。

We have some PHP servers on EC2 behind ELB. We would like to determine the locale/region by IP address of the clients connecting to our servers. The problem is the PHP servers only see the IP address of the ELB. We would like to see the IP addresses of the clients passed through the ELB.

推荐答案

按照<一个href="http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#x-forwarded-for">AWS文档,该ELB应该设置的X - 转发,对于HTTP标头,preserves原始客户端IP地址:

According to the AWS docs, the ELB should be setting the 'X-Forwarded-For' HTTP header which preserves the original client ip address:

的X转发,对于请求头可帮助您识别客户端的IP地址。由于负载均衡器拦截客户端和服务器之间的流量,你的服务器访问日志中包含了负载均衡的唯一的IP地址。要查看客户端的IP地址,使用X - 转发,对于请求头。

The X-Forwarded-For request header helps you identify the IP address of a client. Because load balancers intercept traffic between clients and servers, your server access logs contain only the IP address of the load balancer. To see the IP address of the client, use the X-Forwarded-For request header.

您可以使用下面的PHP code访问它(假设阿帕奇):

You can access it using the following PHP code (assuming apache):

$http_headers = apache_request_headers(); 
$original_ip = $http_headers["X-Forwarded-For"];

这篇关于确定客户的亚马逊ELB背后的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆