# Correct IP in access log

**URL:** <https://www.ruby-forum.com/t/correct-ip-in-access-log/149808>\
**Category:** NGINX\
**Created:** [September 30, 2008, 2:03am UTC](https://www.ruby-forum.com/t/correct-ip-in-access-log/149808 "2008-09-30T02:03:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unclouded](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/6bbea6/32.png) [@unclouded](https://www.ruby-forum.com/u/unclouded)\
**Post date:** [September 30, 2008, 2:03am UTC](https://www.ruby-forum.com/t/correct-ip-in-access-log/149808/1 "2008-09-30T02:03:23Z")

</div>

Hello,

I’m in the process of upgrading my setup. We’re installing nginx on a  
new server. While we transition (and dns propogates), I will keep the  
old nginx server running. I’m going to route requests that hit the  
old nginx server to my new nginx server, and then from there to the  
new backend webservers.

Now, to keep my stats up to date, I need to capture the correct IP  
address in the logs on the new nginx server. On the old nginx server,  
I have the following:

proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $remote\_addr;

Looking at the access log on the new server, I see all requests coming  
from the same IP - that of the old server. Any thoughts?

Thanks!

---

<div class="post-metadata">

**Author:** ![unclouded](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/6bbea6/32.png) [@unclouded](https://www.ruby-forum.com/u/unclouded)\
**Post date:** [September 30, 2008, 3:11am UTC](https://www.ruby-forum.com/t/correct-ip-in-access-log/149808/2 "2008-09-30T03:11:48Z")

</div>

On Mon, Sep 29, 2008 at 4:48 PM, Neil S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Looking at the access log on the new server, I see all requests coming  
> from the same IP - that of the old server. Any thoughts?

you need to configure the backend nginx to “trust” the header of the  
frontend using “set\_real\_ip\_from”

set\_real\_ip\_from 192.168.1.0/24;

etc.

---

<div class="post-metadata">

**Author:** ![unclouded](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/6bbea6/32.png) [@unclouded](https://www.ruby-forum.com/u/unclouded)\
**Post date:** [September 30, 2008, 3:14am UTC](https://www.ruby-forum.com/t/correct-ip-in-access-log/149808/3 "2008-09-30T03:14:09Z")

</div>

On Mon, Sep 29, 2008 at 5:58 PM, mike [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> you need to configure the backend nginx to “trust” the header of the  
> frontend using “set\_real\_ip\_from”

Oops, minor correction. You need to set both of these. Igor has  
written a patch for latest 0.7.x (and who knows what other versions  
work) to allow -any- header to be used as the “real ip”, otherwise an  
unaltered nginx can use either X-Forwarded-For or X-Real-IP.

set\_real\_ip\_from 192.168.1.0/24;  
real\_ip\_header X-Forwarded-For;

You also need to make sure the “realip” module is enabled. Not sure if  
it’s own by default.

---

<div class="post-metadata">

**Author:** ![unclouded](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/6bbea6/32.png) [@unclouded](https://www.ruby-forum.com/u/unclouded)\
**Post date:** [September 30, 2008, 3:31am UTC](https://www.ruby-forum.com/t/correct-ip-in-access-log/149808/4 "2008-09-30T03:31:06Z")

</div>

How can I check what modules are enabled?

---

<div class="post-metadata">

**Author:** ![unclouded](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/6bbea6/32.png) [@unclouded](https://www.ruby-forum.com/u/unclouded)\
**Post date:** [September 30, 2008, 4:26am UTC](https://www.ruby-forum.com/t/correct-ip-in-access-log/149808/5 "2008-09-30T04:26:48Z")

</div>

nginx -V
