CodeIgniter Forums
Retrieving visitor ip address in sessions table - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Retrieving visitor ip address in sessions table (/showthread.php?tid=88461)



Retrieving visitor ip address in sessions table - gareth82 - 09-12-2023

Hi all.
I have recently added an AWS Load Balancer to my CI based web app.
Previously, the visitor's ip address was passing through to the server instance and sessions table fine. However, after adding the LB to the setup, I no longer get the ip address of the visitor. Instead, I get one of the 2 private ip addresses associated with the load balancer.
I have followed AWS support's guidance and ensured that the load balancer's X-Forwarded-For header attribute is set to 'preserve'. However, still no luck.
I have printed an array of the $_SERVER variable. It returns the LB's ip address to the following:
[REMOTE_ADDR]
[HTTP_X_REAL_IP]
It doesn't seem to be returning any mention of a [HTTP_X_FORWARDED_FOR] header at all and no mention anywhere of the visitor's ip address in the headers at all..
Can anyone suggest where I should be looking in order to ensure that the visitor's ip address is passed and picked up by my website?
Is it an apache/nginx setting/issue?
Thanks a lot for any assistance you can provide.
Gareth


RE: Retrieving visitor ip address in sessions table - CIDave - 09-12-2023

Do you have mod_remoteip installed for apache?

See: https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html


RE: Retrieving visitor ip address in sessions table - gareth82 - 09-13-2023

Thanks. Yes, it is installed:
root@ip-xxx-xx-x-xxx:/home/ubuntu# apachectl -M | grep remoteip
remoteip_module (shared)