# Where does this IP come from in the log

**URL:** <https://www.ruby-forum.com/t/where-does-this-ip-come-from-in-the-log/132668>\
**Category:** Rails\
**Created:** [March 22, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/where-does-this-ip-come-from-in-the-log/132668 "2008-03-22T22:10:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![atlantageek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@atlantageek](https://www.ruby-forum.com/u/atlantageek)\
**Post date:** [March 22, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/where-does-this-ip-come-from-in-the-log/132668/1 "2008-03-22T22:10:06Z")

</div>

## On the rails production log I am getting this in the log file

## Processing LivetraceController#index (for 127.0.0.1 at 2008-03-22 15:46:17) [GET] Session ID: 385c4a0d728002966e9728f2c1a07eea Parameters: {“action”=\>“index”, “controller”=\>“livetrace”} Rendering template within layouts/livetrace Rendering livetrace/index Completed in 0.39882 (2 reqs/sec) | Rendering: 0.26451 (66%) | DB: 0.00000 (0%) | 200 OK [[http://10.0.1.203/livetrace](http://10.0.1.203/livetrace)]

Notice that the ‘for 127.0.0.1’ is referring to the local host.  
However this is running on an external host and I do not access it by  
typing 127.0.0.1 in the location bar of my web browser. Where is this  
coming from. How can I reconfigure my server so that it will have the  
external IP address instead.

This is running on a Linux/Redhat server.

---

<div class="post-metadata">

**Author:** ![atlantageek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@atlantageek](https://www.ruby-forum.com/u/atlantageek)\
**Post date:** [March 22, 2008, 10:44pm UTC](https://www.ruby-forum.com/t/where-does-this-ip-come-from-in-the-log/132668/2 "2008-03-22T22:44:18Z")

</div>

atlantageek wrote:

> Processing LivetraceController#index (for 127.0.0.1 at 2008-03-22  
> 15:46:17) [GET]
> 
> Notice that the ‘for 127.0.0.1’ is referring to the local host.  
> However this is running on an external host and I do not access it by  
> typing 127.0.0.1 in the location bar of my web browser. Where is this  
> coming from. How can I reconfigure my server so that it will have the  
> external IP address instead.

The controller prints this and it tries to work out the IP address where  
the request is coming from. It does this by looking at request headers.  
The actual IP address is not available as the request doesn’t go to your  
Rails application as such, it goes to the web server (apache, mongrel,  
etc). Rails uses the information in the HTTP header to try to infer  
where the request came from. This will depend on how the browser is  
looking up the address and what it decides to send.

---

<div class="post-metadata">

**Author:** ![atlantageek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@atlantageek](https://www.ruby-forum.com/u/atlantageek)\
**Post date:** [March 22, 2008, 10:49pm UTC](https://www.ruby-forum.com/t/where-does-this-ip-come-from-in-the-log/132668/3 "2008-03-22T22:49:43Z")

</div>

To expand on that, if you are using mongrel behind nginx, apache  
etc… then all the requests to the mongrel come from nginx/apache (ie  
from localhost). The webserver needs to set the right headers so that  
it can pass on what it knows to rails.

Fred

---

<div class="post-metadata">

**Author:** ![atlantageek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@atlantageek](https://www.ruby-forum.com/u/atlantageek)\
**Post date:** [March 23, 2008, 2:48am UTC](https://www.ruby-forum.com/t/where-does-this-ip-come-from-in-the-log/132668/4 "2008-03-23T02:48:19Z")

</div>

Hi,  
After I sent this I realized that this issue was probably caused by  
the lighttpd server sending the requests to the mongrel cluster.  
So what header should I be looking for on lighttpd. Any suggestions  
would be appreciated.

On Mar 22, 5:49 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![atlantageek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@atlantageek](https://www.ruby-forum.com/u/atlantageek)\
**Post date:** [March 23, 2008, 11:30am UTC](https://www.ruby-forum.com/t/where-does-this-ip-come-from-in-the-log/132668/5 "2008-03-23T11:30:01Z")

</div>

atlantageek wrote:

> After I sent this I realized that this issue was probably caused by  
> the lighttpd server sending the requests to the mongrel cluster.  
> So what header should I be looking for on lighttpd. Any suggestions  
> would be appreciated.

Have a look at the definition of #remote\_ip in  
…/gems/actionpack-x.y.z/lib/action\_controller/request.rb

You’ll see it tries to use HTTP\_CLIENT\_IP, HTTP\_X\_FORWARDED\_FOR and  
REMOTE\_ADDR in that order. To see what your Rails app is getting, try  
adding this to one of your views:

\<%= debug request.env %\>

I don’t know anything really about lighttpd so don’t know what you can  
trace there, but you could sniff the network packets from the browser  
and look at the request header that way. Compare with the above Rails  
to see what is being added by lighttpd. Of course, some of this will be  
updated by mongrel, too, so to complete the picture you’d need to look  
at the headers going between lighttpd and mongrel.

If you are only ever seeing 127.0.0.1 in the headers in Rails, then it  
suggests lighttpd is not adding the remote IP address so mongrel things  
the request originates from lighttpd.
