0

I have a mod_jk httpd server (server ip: dummy1) and it sits behind a load balancer (server ip : 0.876.123.12 and 0.876.123.13). Basically when a request comes in it goes to the load balancer then to the httpd server (server ip: dummy2) and then to my application which is deployed on tomcat9 web server (server ip: dummy3).

Note that I have added dummy server IP just in case I need to refer to them and to show that they are on different machines.

My application is currently displaying the ip of the load balancer instead of the client which is using the application.

My code to display the ip is as follows:

 String ipAddress1 =httpServletRequest.getRemoteAddr() - this one gets load balancer ip

 String ipAddress2 = httpServletRequest.getHeader("X-Forwarded-For"); - this one is null

Based on the online resources I saw that mod_remoteip module for apache should solve my issue and my configuration is as follows:

From the /etc/httpd/conf/httpd.conf

# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf

I am assuming that it will load all file in /etc/httpd/conf.d path. Therefore I have created a file mod_remoteip.conf in path /etc/httpd/conf.d and it is as follows:

# Load the mod_remoteip.so module.
LoadModule remoteip_module modules/mod_remoteip.so
# Set the RemoteIPHeader header.
RemoteIPHeader X-Forwarded-For
# Set the back-to-origin IP addresses.
#RemoteIPInternalProxy 0.876.123.12 0.876.123.13
RemoteIPProxiesHeader X-Forwarded-By

After creating the file I have restarted the httpd server but I still get the same behaviour as before, that is:

   String ipAddress1 =httpServletRequest.getRemoteAddr() - this one gets load balancer ip
    
     String ipAddress2 = httpServletRequest.getHeader("X-Forwarded-For"); - this one is null

Can someone please point me out what I am doing wrong?

Thanks in advance

user1999453
  • 125
  • 1
  • 4
  • 2
    I think you don't do anything wrong. It seems that your load balancer simply does not provide information about the original connecting IP, so you can't get an information that is not there. Probably you need to change something on the load balancer, not on your servers. – raj Aug 18 '22 at 10:56
  • You can capture XForwarded IP in the httpd log or you can enable dumio logging which will show more information, – Pandurang Sep 02 '22 at 02:18

0 Answers0