我们在 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/