反向代理的nginx日志设置显示源ip

阅读更多
外层代理 A设置为
location /*** {
            index hainan.html index.jsp;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass  http://代理B的ip地址;
        }


内部的服务器 B的nginx需要设置,否则ip地址是显示的外部代理的内网ip

http {
    passenger_root /home/hainan/.rvm/gems/ruby-2.3.5/gems/passenger-5.3.0;
    passenger_ruby /home/hainan/.rvm/gems/ruby-2.3.5/wrappers/ruby;

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

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    set_real_ip_from  反向代理A的那个内网ip;
    real_ip_header    X-Forwarded-For;

**省略若干**

}



注意
http_realip_module 这个模块必须是已经安装好的

你可能感兴趣的:(反向代理的nginx日志设置显示源ip)