Where does this IP come from in the log

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]

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.

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.

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

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. [email protected]

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.