如果结构里有个反向代理,那后端机器的日志记录的就会是代理的ip,真实的ip看不到了,后端代码可以通过在header里设置真实ip来解决,nginx加入下面一段即可:


        proxy_set_header X-Real-IP $remote_addr;


后端通过X-REAL-IP或者HTTP_X_REAL_IP变量获取.

日志记录的话,nginx可以定义$http_x_real_ip变量,例如:
    log_format main '$http_x_real_ip - $remote_user '
                      '[$time_local] "$request_method $scheme://$host$request_uri $server_protocol" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" - $remote_addr';
apache可以通过%{X-Real-Ip}i来获取:
    LogFormat "%{X-Real-Ip}i %l %u %t \"%m
http://%v%U%q\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" - %h" combinedall