Setup 1:

Internet -> nginx[1] -> apache[2] -> php-fpm

Để log IP thật cho apache, cần module remoteip

Config cho apache[2]:

LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For

Setup 2:

Internet -> nginx[1] -> nginx[2] -> php-fpm

Config cho nginx[2]:

set_real_ip_from 0.0.0.0/0;
real_ip_header X-Real-IP;
real_ip_recursive on;

Config cho nginx1:

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

Tham khảo: https://serverfault.com/questions/837915/forwarding-real-remote-ip-to-proxied-server-with-nginx