在proxy上设置:(安装时需要添加--with-http_realip_module)

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $remote_addr;

set_real_ip_from ip;(这个ip填写的是proxy的ip)

real_ip_header X-Forwarded-For;



在web后端设置:(安装时需要添加--with-http_realip_module)

set_real_ip_from ip;(这个ip填写的是proxy的ip)

real_ip_header X-Forwarded-For;

在log_format里添加$remote_addr或者$http_x_forwarded_for参数。