# Incorrect IP Address Deducted by Nginx version: nginx/1.2.1

**URL:** <https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262>\
**Category:** NGINX\
**Created:** [February 19, 2014, 3:36pm UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262 "2014-02-19T15:36:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [February 19, 2014, 3:36pm UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262/1 "2014-02-19T15:36:55Z")

</div>

Hi,

```
 We have strange issue on our swiss based on server.

```

Issue: Incorrect IP Address value in REMOTE\_ADDR Header

```
           Nginx Version : 1.2.1

          Server OS : Debian 7.1

          Modules :

 nginx -V

```

nginx version: nginx/1.2.1  
TLS SNI support enabled  
configure arguments: --prefix=/etc/nginx  
–conf-path=/etc/nginx/nginx.conf  
–error-log-path=/var/log/nginx/error.log  
–http-client-body-temp-path=/var/lib/nginx/body  
–http-fastcgi-temp-path=/var/lib/nginx/fastcgi  
–http-log-path=/var/log/nginx/access.log  
–http-proxy-temp-path=/var/lib/nginx/proxy  
–http-scgi-temp-path=/var/lib/nginx/scgi  
–http-uwsgi-temp-path=/var/lib/nginx/uwsgi  
–lock-path=/var/lock/nginx.lock  
–pid-path=/var/run/nginx.pid --with-pcre-jit --with-debug  
–with-http\_addition\_module --with-http\_dav\_module  
–with-http\_geoip\_module  
–with-http\_gzip\_static\_module --with-http\_image\_filter\_module  
–with-http\_realip\_module --with-http\_stub\_status\_module  
–with-http\_ssl\_module --with-http\_sub\_module --with-http\_xslt\_module  
–with-ipv6 --with-sha1=/usr/include/openssl  
–with-md5=/usr/include/openssl  
–with-mail --with-mail\_ssl\_module  
–add-module=/tmp/buildd/nginx-1.2.1/debian/modules/nginx-auth-pam  
–add-module=/tmp/buildd/nginx-1.2.1/debian/modules/nginx-echo  
–add-module=/tmp/buildd/nginx-1.2.1/debian/modules/nginx-upstream-fair  
–add-module=/tmp/buildd/nginx-1.2.1/debian/modules/nginx-dav-ext-module

We have IP based security token for our application , the token  
created  
by nginx+php will be checked in wowza before stream play. Recently lot  
of NZ  
visitors complained about video not playing , it due to security token  
failed between nginx+php vs wowza. here are more information

```
        1 . We have installed Apache on same server and deduction 

```

IP  
Address as expected.

```
        2. Even Nginx access log printing incorrect IP Address , 

```

so we  
feel nothing missed on FastCGI setting

```
        3. Based on IPLocation info incorrect IP is gateway 

```

IPAddress

```
        NGINX $_SERVER

        Array

```

(  
[FCGI\_ROLE] =\> RESPONDER  
[SCRIPT\_FILENAME] =\> xxxxxx  
[QUERY\_STRING] =\>  
msg=Error%20loading%20stream:%20Could%20not%20connect%20to%20server  
[REQUEST\_METHOD] =\> GET  
[CONTENT\_TYPE] =\>  
[CONTENT\_LENGTH] =\>  
[SCRIPT\_NAME] =\> /trackfail.php  
[REQUEST\_URI] =\>  
/trackfail.php?msg=Error%20loading%20stream:%20Could%20not%20connect%20to%20server  
[DOCUMENT\_URI] =\> /trackfail.php  
[DOCUMENT\_ROOT] =\> xxxxx  
[SERVER\_PROTOCOL] =\> HTTP/1.1  
[GATEWAY\_INTERFACE] =\> CGI/1.1  
[SERVER\_SOFTWARE] =\> nginx/1.2.1  
[REMOTE\_ADDR] =\> 210.x5.2x2.93  
[REMOTE\_PORT] =\> 60187  
[SERVER\_ADDR] =\> xxxxxxx  
[SERVER\_PORT] =\> 80  
[SERVER\_NAME] =\> xxxxx  
[HTTPS] =\>  
[REDIRECT\_STATUS] =\> 200  
[GEOIP\_COUNTRY\_CODE] =\> NZ  
[GEOIP\_COUNTRY\_NAME] =\> New Zealand  
[HTTP\_HOST] =\> xxxxxxx  
[HTTP\_ACCEPT] =\> _/_  
[HTTP\_X\_REQUESTED\_WITH] =\> XMLHttpRequest  
[HTTP\_USER\_AGENT] =\> Mozilla/5.0 (Macintosh; Intel Mac OS X 10\_9\_1)  
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107  
Safari/537.36  
[HTTP\_REFERER] =\> xxxxxxxxxxxxxx  
[HTTP\_ACCEPT\_ENCODING] =\> gzip,deflate,sdch  
[HTTP\_ACCEPT\_LANGUAGE] =\> en-US,en;q=0.8  
[HTTP\_COOKIE] =\> zmad=1; 2bfd\_unique\_user=1; defaults=1  
[HTTP\_CACHE\_CONTROL] =\> max-stale=0  
[HTTP\_CONNECTION] =\> Keep-Alive  
[PHP\_SELF] =\> /trackfail.php  
)

Apache $\_SERVER

```
      Array

```

(  
[GEOIP\_ADDR] =\> 115.1x8.3x.37  
[GEOIP\_CONTINENT\_CODE] =\> OC  
[GEOIP\_COUNTRY\_CODE] =\> NZ  
[GEOIP\_COUNTRY\_NAME] =\> New Zealand  
[HTTP\_HOST] =\> xxxx:8080  
[HTTP\_CONNECTION] =\> keep-alive  
[HTTP\_ACCEPT] =\> _/_  
[HTTP\_USER\_AGENT] =\> Mozilla/5.0 (Macintosh; Intel Mac OS X 10\_9\_1)  
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107  
Safari/537.36  
[HTTP\_REFERER] =\> xxxx  
[HTTP\_ACCEPT\_ENCODING] =\> gzip,deflate,sdch  
[HTTP\_ACCEPT\_LANGUAGE] =\> en-US,en;q=0.8  
[HTTP\_COOKIE] =\> zmad=1; 2bfd\_unique\_user=1; defaults=1  
[PATH] =\> /usr/local/bin:/usr/bin:/bin  
[SERVER\_SIGNATURE] =\> Apache/2.2.22 (Debian) Server at  
xxxxx  
Port 8080

```
[SERVER_SOFTWARE] => Apache/2.2.22 (Debian)
[SERVER_NAME] => xxxxxx
[SERVER_ADDR] => xxxxx
[SERVER_PORT] => 8080
[REMOTE_ADDR] => 115.1x8.3x.37
[DOCUMENT_ROOT] => xxxxxx
[SERVER_ADMIN] => webmaster@localhost
[SCRIPT_FILENAME] => xxxxxxx
[REMOTE_PORT] => 51777
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => reqid=662&callback=jsonCallback&_=1392745097470
[REQUEST_URI] =>

```

/trackfail.php?reqid=662&callback=jsonCallback&\_=1392745097470  
[SCRIPT\_NAME] =\> /trackfail.php  
[PHP\_SELF] =\> /trackfail.php  
)

Thanks  
Siva

Posted at Nginx Forum:

> **[Incorrect IP Address Deducted by Nginx version: nginx/1.2.1](https://forum.nginx.org/read.php?2,247736,247736#msg-247736)**
>
> Hi, We have strange issue on our swiss based on server. Issue: Incorrect IP Address value in REMOTE\_ADDR Header Nginx Version : 1.2.1 Server OS : Debian 7.1 Modules :

---

<div class="post-metadata">

**Author:** ![sivakr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@sivakr](https://www.ruby-forum.com/u/sivakr)\
**Post date:** [February 19, 2014, 5:14pm UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262/2 "2014-02-19T17:14:39Z")

</div>

Despite what you are stating, I see a valid NZ IP address in the  
'$\_SERVER’​ environment variables of the PHP instance running behind  
Nginx  
(most probably 210.55.x.x prefix).

The Apache remote address is not the right one.

## Since you failed to explain your setup, I suppose Nginx proxies traffic to Apache. That would explain the REMOTE\_ADDR is the one from the gateway. Your proxy configuration fails to pass the original visitor IP address through the HTTP\_X\_FORWARDED\_FOR field.

_B. R._

---

<div class="post-metadata">

**Author:** ![sivakr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@sivakr](https://www.ruby-forum.com/u/sivakr)\
**Post date:** [February 19, 2014, 5:41pm UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262/3 "2014-02-19T17:41:08Z")

</div>

Hello,

If your trackfail.php (behind FastCGI) detects IP address based on  
$\_SERVER[‘REMOTE\_ADDR’], you may would like to place additional headers  
in your nginx configuration:

proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;

Then pass X-Real-IP as param to FastCGI:

fastcgi\_param REMOTE\_ADDR $http\_x\_real\_ip;

or direct to change you trackfail.php to detects IP address based on  
$\_SERVER[‘HTTP\_X\_REAL\_IP’] (after adding additional X-Real-IP header).

---

<div class="post-metadata">

**Author:** ![sivakr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@sivakr](https://www.ruby-forum.com/u/sivakr)\
**Post date:** [February 19, 2014, 6:03pm UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262/4 "2014-02-19T18:03:30Z")

</div>

Hi Bozhidara,

```
   Thanks for the suggesting . I will try your setting and let you 

```

know  
soon.

Thanks  
Siva

Posted at Nginx Forum:

> **[Re: Incorrect IP Address Deducted by Nginx version: nginx/1.2.1](https://forum.nginx.org/read.php?2,247736,247744#msg-247744)**
>
> Hi, We have strange issue on our swiss based on server. Issue: Incorrect IP Address value in REMOTE\_ADDR Header Nginx Version : 1.2.1 Server OS : Debian 7.1 Modules :

---

<div class="post-metadata">

**Author:** ![sivakr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@sivakr](https://www.ruby-forum.com/u/sivakr)\
**Post date:** [February 19, 2014, 6:02pm UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262/5 "2014-02-19T18:02:55Z")

</div>

Hi BR,

```
      www.whatismyip.com shows 115.1x8.3x.37 , Apache shows

```

115.1x8.3x.37

```
      But nginx shows 210.55.x.x

     Server Setup like follows

     Nginx on Port 80 backend FastCGI Php

     Apache on Port 8080

     nginx conf

```

user www-data;  
worker\_processes 4;  
worker\_rlimit\_nofile 204800;  
error\_log /var/log/nginx/error.log;  
pid /var/run/nginx.pid;

events {  
worker\_connections 65535;  
multi\_accept on;  
}

http {

#include /etc/nginx/mime.types;

```
access_log /var/log/nginx/access.log;
geoip_country /usr/share/GeoIP/GeoIP.dat;

```

sendfile on;  
tcp\_nopush on;  
tcp\_nodelay on;  
keepalive\_timeout 65;  
types\_hash\_max\_size 2048;

# server\_tokens off;

# server\_names\_hash\_bucket\_size 64;

server\_tokens off;

include /etc/nginx/mime.types;  
default\_type application/octet-stream;

## 

# Logging Settings

## 

access\_log /var/log/nginx/access.log;  
error\_log /var/log/nginx/error.log;

## 

# Gzip Settings

## 

gzip on;  
gzip\_static on;  
gzip\_vary on;  
gzip\_comp\_level 6;  
gzip\_proxied any;  
gzip\_types text/plain text/css application/json  
application/x-javascript text/xml application/xml application/xml+rss  
text/javascript application/javascript text/x-js;  
gzip\_buffers 16 8k;

```
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

```

## 

# nginx-naxsi config

## 

# Uncomment it if you installed nginx-naxsi

## 

#include /etc/nginx/naxsi\_core.rules;

## 

# nginx-passenger config

## 

# Uncomment it if you installed nginx-passenger

## 

#passenger\_root /usr;  
#passenger\_ruby /usr/bin/ruby;

## 

# Virtual Host Configs

## 

include /etc/nginx/conf.d/_.conf;  
include /etc/nginx/sites-enabled/_;  
}

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,247736,247743#msg-247743](http://forum.nginx.org/read.php?2,247736,247743#msg-247743)

---

<div class="post-metadata">

**Author:** ![sivakr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@sivakr](https://www.ruby-forum.com/u/sivakr)\
**Post date:** [February 19, 2014, 6:19pm UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262/6 "2014-02-19T18:19:24Z")

</div>

REAL IP value not passing

location ~ .php$ {  
root /var/www;  
fastcgi\_pass 127.0.0.1:9000;  
#fastcgi\_pass unix:/var/run/php5-fpm.sock;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For  
$proxy\_add\_x\_forwarded\_for;  
include fastcgi\_params;  
}  
fastcgi\_param REMOTE\_ADDR $remote\_addr;  
fastcgi\_param HTTP\_X\_REAL\_IP $http\_x\_real\_ip;  
fastcgi\_param REMOTE\_PORT $remote\_port;

\<?php print\_r($\_SERVER); ?\>

response

Array ( [USER] =\> www-data [HOME] =\> /var/www [FCGI\_ROLE] =\> RESPONDER  
[SCRIPT\_FILENAME] =\> /var/www/test.php [QUERY\_STRING] =\>  
[REQUEST\_METHOD] =\>  
GET [CONTENT\_TYPE] =\> [CONTENT\_LENGTH] =\> [SCRIPT\_NAME] =\> /test.php  
[REQUEST\_URI] =\> /test.php [DOCUMENT\_URI] =\> /test.php [DOCUMENT\_ROOT]  
=\>  
/var/www [SERVER\_PROTOCOL] =\> HTTP/1.1 [GATEWAY\_INTERFACE] =\> CGI/1.1  
[SERVER\_SOFTWARE] =\> nginx/1.2.1 [REMOTE\_ADDR] =\> 122.1xx.xx.227  
[HTTP\_X\_REAL\_IP] =\> [REMOTE\_PORT] =\> 17467 [SERVER\_ADDR] =\> xxxx  
[SERVER\_PORT] =\> 80 [SERVER\_NAME] =\>xxxx [HTTPS] =\> [REDIRECT\_STATUS] =\>  
200  
[GEOIP\_COUNTRY\_CODE] =\> IN [GEOIP\_COUNTRY\_NAME] =\> India [HTTP\_HOST] =\>  
xxxx  
[HTTP\_CONNECTION] =\> keep-alive [HTTP\_CACHE\_CONTROL] =\> max-age=0  
[HTTP\_ACCEPT] =\>  
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,_/_;q=0.8  
[HTTP\_USER\_AGENT] =\> Mozilla/5.0 (Windows NT 6.3; WOW64)  
AppleWebKit/537.36  
(KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36  
[HTTP\_ACCEPT\_ENCODING] =\> gzip,deflate,sdch [HTTP\_ACCEPT\_LANGUAGE] =\>  
en-GB,en-US;q=0.8,en;q=0.6 [PHP\_SELF] =\> /test.php [REQUEST\_TIME\_FLOAT]  
=\>  
1392830171.8188 [REQUEST\_TIME] =\> 1392830171 )

Thanks

Posted at Nginx Forum:

> **[Re: Incorrect IP Address Deducted by Nginx version: nginx/1.2.1](https://forum.nginx.org/read.php?2,247736,247745#msg-247745)**
>
> Hi, We have strange issue on our swiss based on server. Issue: Incorrect IP Address value in REMOTE\_ADDR Header Nginx Version : 1.2.1 Server OS : Debian 7.1 Modules :

---

<div class="post-metadata">

**Author:** ![sivakr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@sivakr](https://www.ruby-forum.com/u/sivakr)\
**Post date:** [February 19, 2014, 7:15pm UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262/7 "2014-02-19T19:15:18Z")

</div>

## I am tempted to copy an URL recently provided by Maxim in another thread: [How To Ask Questions The Smart Way](http://www.catb.org/~esr/faqs/smart-questions.html)

_B. R._

---

<div class="post-metadata">

**Author:** ![sivakr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@sivakr](https://www.ruby-forum.com/u/sivakr)\
**Post date:** [February 19, 2014, 11:29pm UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262/8 "2014-02-19T23:29:35Z")

</div>

Hello,

Your FastCGI params are wrong.

It should be as I wrote previously:  
fastcgi\_param REMOTE\_ADDR $http\_x\_real\_ip;

In your fastcgi\_params file  
remove:  
fastcgi\_param REMOTE\_ADDR $remote\_addr;  
fastcgi\_param HTTP\_X\_REAL\_IP $http\_x\_real\_ip;

and add on their place only:  
fastcgi\_param REMOTE\_ADDR $http\_x\_real\_ip;

Also you may place proxy\_set\_headers outside location, for example in  
server section

server  
{  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
some other …

```
 location ...{
 ...
 include fastcgi_params;
 }

```

}

---

<div class="post-metadata">

**Author:** ![sivakr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@sivakr](https://www.ruby-forum.com/u/sivakr)\
**Post date:** [February 19, 2014, 7:22pm UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262/9 "2014-02-19T19:22:58Z")

</div>

Hi BR,

```
  I am really sorry , if you feel not good the way of I am asking.

  Since I am not a English person nature , perhaps I am lagging in 

```

this  
part

Sorry

Thanks  
Siva

Posted at Nginx Forum:

> **[Re: Incorrect IP Address Deducted by Nginx version: nginx/1.2.1](https://forum.nginx.org/read.php?2,247736,247750#msg-247750)**
>
> Hi, We have strange issue on our swiss based on server. Issue: Incorrect IP Address value in REMOTE\_ADDR Header Nginx Version : 1.2.1 Server OS : Debian 7.1 Modules :

---

<div class="post-metadata">

**Author:** ![sivakr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@sivakr](https://www.ruby-forum.com/u/sivakr)\
**Post date:** [February 21, 2014, 4:29am UTC](https://www.ruby-forum.com/t/incorrect-ip-address-deducted-by-nginx-version-nginx-1-2-1/239262/10 "2014-02-21T04:29:38Z")

</div>

We are professional Ring Die manufacturers and factory.We can produce  
high  
quality Pellet Die according to your requirements.More types of Pellet  
Mill  
Die wanted,please contact us right now

Posted at Nginx Forum:

> **[Nginx Forum :: Nginx Mailing List - English](https://forum.nginx.org/read.php?2,247736,247824#msg-247824)**
>
> A portal to and from the mailing list.
