I installed varnish version 5.2.1 / ubuntu 18.04 / nginx 1.21.6 and I have Cloudflare and I managed to get the real IP addresses if I open direct links through the browser or just with $_SERVER [‘REMOTE_ADDR’] using this;
if (req.http.cf-connecting-ip) {
set req.http.X-Forwarded-For = req.http.cf-connecting-ip;
} else {
set req.http.X-Forwarded-For = req.http.rlnclientipaddr;
}
and this code in vhost in nginx
set_real_ip_from 204.93.240.0/24;
set_real_ip_from 204.93.177.0/24;
set_real_ip_from 199.27.128.0/21;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.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 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 127.0.0.1;
#real_ip_header X-Real-IP;
#real_ip_header X-Forwarded-For;
real_ip_header CF-Connecting-IP;
real_ip_recursive on;
However, I have a problem with the logs in varnish (/var/log/varnishvarnishncsa.log)
I always receive the following IP addresses in the logs: 172.68.50.173, 172.68.50.67, 172.68.50.29
Can anyone help me how to make the logs appear with the real IP addresses of the users?