使用nginx反向代理时,如何正确获取到用户的真实ip

在记录日志的的时候,获取用户的信息,比如用户的ip,浏览器等等信息是十分重要的。

但是在使用nginx反向代理的时候,可能经过转发无法获取到用户的真实的ip,

在此情况下需要配置nginx,让其在转发的时候在header 带上用户的真实的ip。

举个例子:

 server {

        listen 80;
        server_name xxx.lenny.net;
        root   D:soft
ginx-1.11.4html;
        index  index.php index.html index.htm;
        add_header Access-Control-Allow-Origin "*";
        default_type 'text/html';
        charset utf-8;
        #rewrite_log on;

        # go java
        location /xxx/ {
            proxy_pass http://127.0.0.1:8080;
            proxy_set_header     Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

详细查看:

http://blog.csdn.net/hellolingyun/article/details/34093223

原文地址:https://www.cnblogs.com/nele/p/6362761.html