Hoy vamos a aprender cómo podemos capturar la IP real del cliente pasando por el proxy de cloudflare y recibiendolo en nginx proxy manager (NPM) o nginx.

Abrimos nuestro proxy inverso y vamos a Proxy Hosts

Ahora seleccionamos el proxy que queremos enviar las IPs reales y pusamos en Advanced.
En el apartado de Custom Nginx Configuration tenemos que añadir lo siguiente:
Para que tu backend vea la IP real del cliente, tienes que usar CF-Connecting-IP
y confiar en los rangos de Cloudflare. Tu configuración quedaría así:
set_real_ip_from 03.21.244.0/22; set_real_ip_from 103.22.200.0/22; set_real_ip_from 103.31.4.0/22; set_real_ip_from 104.16.0.0/13; set_real_ip_from 104.24.0.0/14; set_real_ip_from 108.162.192.0/18; set_real_ip_from 131.0.72.0/22; set_real_ip_from 141.101.64.0/18; set_real_ip_from 162.158.0.0/15; set_real_ip_from 172.64.0.0/13; set_real_ip_from 173.245.48.0/20; set_real_ip_from 188.114.96.0/20; set_real_ip_from 190.93.240.0/20; set_real_ip_from 197.234.240.0/22; set_real_ip_from 198.41.128.0/17; #use any of the following two real_ip_header CF-Connecting-IP; #real_ip_header X-Forwarded-For;
Ahora pulsamos en Save
Y tendremos la cabecera disponible en x-real-ip

Ingeniero en Informática, Investigador, me encanta crear cosas o arreglarlas y darles una nueva vida. Escritor y poeta. Más de 20 APPs publicadas y un libro en Amazon.