# Nginx1-\>nginx2-\>apache and wrong IP address in nginx2 access log

**URL:** <https://www.ruby-forum.com/t/nginx1-nginx2-apache-and-wrong-ip-address-in-nginx2-access-log/169682>\
**Category:** NGINX\
**Created:** [June 6, 2009, 10:22pm UTC](https://www.ruby-forum.com/t/nginx1-nginx2-apache-and-wrong-ip-address-in-nginx2-access-log/169682 "2009-06-06T22:22:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 6, 2009, 10:22pm UTC](https://www.ruby-forum.com/t/nginx1-nginx2-apache-and-wrong-ip-address-in-nginx2-access-log/169682/1 "2009-06-06T22:22:38Z")

</div>

Hello,  
I have a machine 1 with nginx as a proxy before apache, and machine2  
with nginx as a proxy before apache. I am moving websites from machine1  
to machine2. Because DNS still points to machine1, I need to pass  
traffic from machone1 to machine2 for a while.  
Everything is working fine, but in machine2 nginx log I have IP of  
machine1 as clients address. This is a problem because of awstats.

Can please anybody advise me that I have wrong in my configuration?

Thanks,  
Martin

My machine1 configuration:  
server {  
listen machine1ip:80;  
server\_name list-of-moved-websites;

```
            location / {
              client_max_body_size 10m;
              client_body_buffer_size 128k;

              proxy_send_timeout 90;
              proxy_read_timeout 90;

              proxy_buffer_size 4k;
              proxy_buffers 16 32k;
              proxy_busy_buffers_size 64k;
              proxy_temp_file_write_size 64k;

              proxy_connect_timeout 30s;

              proxy_pass http://machine2:80;
              proxy_redirect off;

              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For 

```

$proxy\_add\_x\_forwarded\_for;  
}  
}

Machine2 configuration:

log\_format main ‘$remote\_addr - $remote\_user [$time\_local] “$request”  
$status $bytes\_sent “$http\_referer” “$http\_user\_agent” “$gzip\_ratio”’;

server {  
listen 80;  
server\_name website;

```
access_log /var/log/nginx/website/access-website.log main;
error_log /var/log/nginx/website/error-website.log;

#default proxy settings shared are among all virtual hosts
            location / {
              client_max_body_size 10m;
              client_body_buffer_size 128k;

              proxy_send_timeout 90;
              proxy_read_timeout 90;

              proxy_buffer_size 4k;
              proxy_buffers 16 32k;
              proxy_busy_buffers_size 64k;
              proxy_temp_file_write_size 64k;

              proxy_connect_timeout 30s;

              proxy_pass http://machine2:81; #apache
              proxy_redirect off;

              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For 

```

$proxy\_add\_x\_forwarded\_for;  
}

```
location ~* 

```

^.+.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|html?|txt|tar|mid|midi|wav|bmp|rtf|js|swf|avi|mp3)$  
{  
#forcing browser to cache locally static content for 30 days  
expires 30d;  
root /var/www/squashe.cz/web/www/htdocs;

```
    #graceful fallback in case if static content doesn't exist
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    if (!-f $request_filename) {
      break;
      proxy_pass http://machine2ip:81;
    }
}

```

}

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 7, 2009, 3:00pm UTC](https://www.ruby-forum.com/t/nginx1-nginx2-apache-and-wrong-ip-address-in-nginx2-access-log/169682/2 "2009-06-07T15:00:19Z")

</div>

2009/6/6 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hello,  
> I have a machine 1 with nginx as a proxy before apache, and machine2 with nginx as a proxy before apache. I am moving websites from machine1 to machine2. Because DNS still points to machine1, I need to pass traffic from machone1 to machine2 for a while.  
> Everything is working fine, but in machine2 nginx log I have IP of machine1 as clients address. This is a problem because of awstats.
> 
> Can please anybody advise me that I have wrong in my configuration?

Have a look at [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpRealIpModule) and  
configure it on machine2:

#v+  
set\_real\_ip\_from outgoing\_ip\_address\_of\_machine1;  
real\_ip\_header X-Real-IP;  
#v-

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 7, 2009, 6:24pm UTC](https://www.ruby-forum.com/t/nginx1-nginx2-apache-and-wrong-ip-address-in-nginx2-access-log/169682/3 "2009-06-07T18:24:24Z")

</div>

Thanks a lot,  
that worked for me.  
Martin

* * *
