Pass real client IP to web servers

bdroste nginx-list at forum.nginx.org
Thu Mar 26 02:53:31 MSK 2009


Subject: Pass real client IP to web servers
Author: bdroste

I'm sure this has been asked before, but I can't find an answer.  I'm running nginx-0.7.44 on a server, load balancing port 80 to port 8080 on 2 other servers running Apache.  I am trying to figure out how to get Nginx to pass the real IP address of the browser client through to the web servers.  The web servers always log the IP address of the Nginx server instead of the client.

A Google search suggested that I needed to run a Apache proxy server on each of my web servers that then pass the request on to my real web server, so the headers are rewritten.  That works, but it seems I should be able to do this with Nginx and not need to run an intermediate web server just to pass the traffic to my real web servers.

Here is my nginx.conf
-----
worker_processes  4;

events {
    worker_connections  8192;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  60;

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

    upstream serverpool {
       server 192.168.20.170:7080;
       server 192.168.20.171:8080;
    }

    server {
        listen 80;
        server_name www.mydomain.com;
        location / {
           proxy_pass http://serverpool;
           proxy_redirect default;
        }
    }
}
----

Any help or clarification on the issue would be greatly appreciated.

Thanks,
Bruce

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,449,449#msg-449






More information about the nginx mailing list