Forum: NGINX nginx1->nginx2->apache and wrong IP address in nginx2 access log

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2009-06-07 00:22
(Received via mailing list)
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;
        }
    }
}
Piotr Gasidło (Guest)
on 2009-06-07 17:00
(Received via mailing list)
2009/6/6  <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 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-
unknown (Guest)
on 2009-06-07 20:24
(Received via mailing list)
Thanks a lot,
that worked for me.
Martin

______________________________________________________________
This topic is locked and can not be replied to.