amazon-web-services - 确定 Amazon ELB 后面的客户端 IP 地址

标签 amazon-web-services locale load-balancing

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

最佳答案

根据AWS docs ,ELB 应该设置保留原始客户端 IP 地址的“X-Forwarded-For”HTTP header :

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 代码(假设为 apache)访问它:
$http_headers = apache_request_headers(); 
$original_ip = $http_headers["X-Forwarded-For"];

关于amazon-web-services - 确定 Amazon ELB 后面的客户端 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15119739/

相关文章:

amazon-web-services - 如何找到 CloudFormation 堆栈的创建者?

python - 通过代码使粘合作业失败(即手动)

android - 为什么 Resources.getString() 可能会间歇性地从错误的语言环境返回字符串?

apache - 如何获取适用于 Windows 的 mod_jk.so/mod_jk.dll 文件?

mysql - NHibernate:读/写分离

duplicates - 负载均衡器向 Web 服务器发送两个请求

amazon-web-services - AWS计算器,ELB处理的数据

java.util.Calendar 困惑

ruby-on-rails - Rails i18n : Translation missing problem, 语言环境未定义

amazon-web-services - AWS API 网关 + Cognito + Lambda - $context.authorizer.principalId 为空