I've switched to using an Amazon AWS Elastic Load Balancer and now I'm getting a private IP address for $_SERVER['REMOTE_ADDR']
- which used to give me the client's IP address.
How do I get the clients IP address now?
Your webserver receives HTTP requests from the Amazon ELB. Therefore, the remote address will always be one of the ELB ip addresses. If you need the remote host's address from behind the ELB, get it from HTTP header "X-Forwarded-For".
The below works for me in httpd.conf global section where the LogFormat is defined. With the change below, $_SERVER['REMOTE_ADDR']
will be set to the client ip on php-fpm and not the ELB ip.
<IfModule remoteip_module>
RemoteIPHeader X-Forwarded-For
LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%a %l %u %t \"%r\" %>s %b" common
</IfModule>
Solution is from https://medium.com/@jiraknet/apache-2-4-mod-remoteip-for-get-real-ip-on-aws-elb-6e9f40876b06
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With