Reputation: 8192
I have one load balancer and three EC2 web servers with Linux and Apache. Whenever I use $_SERVER['REMOTE_ADDR']
in PHP to take website's visitor's IP addresses, It shows me a wrong IP address. When I check the IP in Whois databases then I will find its a reserved IP. I guess its IP of another server in AWS itself instead of client's IP. How Can I get correct client's IP with PHP in EC2 servers?
Upvotes: 1
Views: 1525
Reputation: 199
The IP is a local Amazon IP because the visitors does not connect to your server directly.
Normally the Load balancer forwards the real client IP in the $_SERVER
array under a new key, in most cases $_SERVER['HTTP_X_FORWARDED_FOR']
Upvotes: 6