# Nginx logged ip different than php $\_SERVER

**URL:** <https://www.ruby-forum.com/t/nginx-logged-ip-different-than-php-server/221829>\
**Category:** NGINX\
**Created:** [August 1, 2012, 9:56am UTC](https://www.ruby-forum.com/t/nginx-logged-ip-different-than-php-server/221829 "2012-08-01T09:56:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 1, 2012, 9:56am UTC](https://www.ruby-forum.com/t/nginx-logged-ip-different-than-php-server/221829/1 "2012-08-01T09:56:12Z")

</div>

nginx/0.8.49  
php in fastcgi mode, php version 5.3.5  
pieces of nginx cofig file:

default log format:  
log\_format main '$remote\_addr - - [$time\_local] “$request” ’  
'$status $body\_bytes\_sent “$http\_referer” ’  
‘“$http\_user\_agent”’;

access\_log /app/logs/default.log main;

```
    location ~ .*\.php$ {
        fastcgi_pass 127.0.0.1:9000;
        #fastcgi_pass unix:/tmp/php-cgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME

```

/usr/local/www/default$fastcgi\_script\_name;  
include /usr/local/nginx/conf/fastcgi\_params;  
}

contents of fastcgi\_params:

fastcgi\_param QUERY\_STRING $query\_string;  
fastcgi\_param REQUEST\_METHOD $request\_method;  
fastcgi\_param CONTENT\_TYPE $content\_type;  
fastcgi\_param CONTENT\_LENGTH $content\_length;

fastcgi\_param SCRIPT\_NAME $fastcgi\_script\_name;  
fastcgi\_param REQUEST\_URI $request\_uri;  
fastcgi\_param DOCUMENT\_URI $document\_uri;  
fastcgi\_param DOCUMENT\_ROOT $document\_root;  
fastcgi\_param SERVER\_PROTOCOL $server\_protocol;

fastcgi\_param GATEWAY\_INTERFACE CGI/1.1;  
fastcgi\_param SERVER\_SOFTWARE nginx/$nginx\_version;

fastcgi\_param REMOTE\_ADDR $remote\_addr;  
fastcgi\_param REMOTE\_PORT $remote\_port;  
fastcgi\_param SERVER\_ADDR $server\_addr;  
fastcgi\_param SERVER\_PORT $server\_port;  
fastcgi\_param SERVER\_NAME $server\_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi\_param REDIRECT\_STATUS 200;

problem is:  
I got this in my log:  
124.95.xx.yy - - [01/Aug/2012:15:22:48 +0800] “GET  
/ch111/index.php?111234 HTTP/1.0” 200 1483 “-” “Mozilla/4.0 (compatible;  
MSIE 8.0; Windows NT 5.1; Trident/4.0)”  
And I got $\_SERVER[‘REMOTE\_ADDR’] with a different ip when it is shown  
on client’s browser.  
I am sure that the different ips are from the same client.

Before my web server, I have no balancers or other devices, but I am not  
of the client’s side.

Even if the client goes through some kind of proxy, no matter squid or  
commercial ones, $\_SERVER[‘REMOTE\_ADDR’] should be always the same with  
what is shown in nginx’s log.

Posted at Nginx Forum:

> **[nginx logged ip different than php $\_SERVER\['REMOTE\_ADDR'\]](https://forum.nginx.org/read.php?2,229169,229169#msg-229169)**
>
> nginx/0.8.49 php in fastcgi mode, php version 5.3.5 pieces of nginx cofig file: default log format: log\_format main '$remote\_addr - - \[$time\_local\] "$request" ' '$status $body\_bytes\_sent "$http\_referer" '
