# On proxy my nginx show wrong ip (private)

**URL:** <https://www.ruby-forum.com/t/on-proxy-my-nginx-show-wrong-ip-private/199544>\
**Category:** NGINX\
**Created:** [November 23, 2010, 7:46pm UTC](https://www.ruby-forum.com/t/on-proxy-my-nginx-show-wrong-ip-private/199544 "2010-11-23T19:46:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 23, 2010, 7:46pm UTC](https://www.ruby-forum.com/t/on-proxy-my-nginx-show-wrong-ip-private/199544/1 "2010-11-23T19:46:34Z")

</div>

Hello, Im using FreeBSD and jail. I have main nginx server in jail (ip  
192.168.1.2). Second www server is apache22 (192.168.1.3).

Port 80 from 192.168.1.2 is forwarding to public IP.

Problem is in this that php scripts from apache (192.168.1.3) showing  
client IP from nginx (192.168.1.2). For example: phpBB showing on line  
users and ips 192.168.1.2.

Its my settings in nginx (192.168.1.2):  
— START—  
server {  
listen 80;  
server\_name www.skuter-forum.pl skuter-forum.pl;  
access\_log /var/log/nginx/skuter-forum.pl.access.log;

```
    if ($host = 'www.skuter-forum.pl' ) {
                                rewrite ^/(.*)

```

[http://skuter-forum.pl/$1](http://skuter-forum.pl/$1) permanent;  
}

location / {  
proxy\_pass [http://192.168.1.3:80](http://192.168.1.3:80);  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header Host $http\_host;  
}  
}

— END —

How set real clients ips?

Posted at Nginx Forum:

> **[On proxy my nginx show wrong ip (private)](https://forum.nginx.org/read.php?2,152732,152732#msg-152732)**
>
> Hello, Im using FreeBSD and jail. I have main nginx server in jail (ip 192.168.1.2). Second www server is apache22 (192.168.1.3). Port 80 from 192.168.1.2 is forwarding to public IP. Problem is in this that php scripts from apache (192.168.1.3)...

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 24, 2010, 1:52am UTC](https://www.ruby-forum.com/t/on-proxy-my-nginx-show-wrong-ip-private/199544/2 "2010-11-24T01:52:31Z")

</div>

On Tue, Nov 23, 2010 at 01:45:02PM -0500, dong wrote:

Hi there,

> Problem is in this that php scripts from apache (192.168.1.3) showing  
> client IP from nginx (192.168.1.2). For example: phpBB showing on line  
> users and ips 192.168.1.2.

The php scripts are probably using REMOTE\_ADDR, which is the address of  
the client connecting to Apache, which is nginx.

> ```
> }
> 
> ```

Aside – there’s a better way of doing that.

> location / {  
> proxy\_pass [http://192.168.1.3:80](http://192.168.1.3:80);  
> proxy\_set\_header X-Real-IP $remote\_addr;  
> proxy\_set\_header Host $http\_host;  
> }  
> }
> 
> — END —
> 
> How set real clients ips?

You have told nginx to send the http header X-Real-IP with this  
value. That’s pretty much all you can do on the nginx side. So either  
get your Apache to set that value as REMOTE\_ADDR for the php scripts,  
or get the php scripts to read HTTP\_X\_REAL\_IP instead of REMOTE\_ADDR.

Good luck,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
