Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




Getting Client IP in Apache/Tomcat
Read original blog post

UserPost

9:12 pm
March 19, 2009


admin

Admin

posts 17

1

This is an issue that just keep coming back to me but I always tend to forget how it’s been resolved before.  I would have to research into the issue every single time.  The problem is that request.getRemoteAddr() doesn’t always return the client IP in Tomcat (or any app servers) when it’s sitting behind a proxy.  In my case, Tomcat is behind Apache’s balancer.  When you call request.getRemoteAddr(), it would return the Apache server’s IP instead of the client IP.  

To get the actual client IP, you need to pull it from the header.  Apache sets a header variable called “x-forwarded-for” with the client IP.  You can simply grab it from the header:

String ip = request.getHeader("x-forwarded-for");

This is just one of the thing I found annoying. I can understand why request.getRemoteAddr() doesn’t always return client IP. I’m hoping eventually Tomcat will have a reliable method to return a proper client IP.


Read original blog post

Search 

About the MySolr forum

Most Users Ever Online:

9


Currently Online:

5 Guests

Forum Stats:

Groups: 2

Forums: 2

Topics: 9

Posts: 22

Membership:

There are 8 Members

There has been 1 Guest

There is 1 Admin

There is 1 Moderator

Top Posters:

mojo – 6

sturlese – 6

fudge – 1

blah – 1

egrobler – 1

phat – 0

Administrators: admin (17 Posts)

Moderators: mysolr (0 Posts)