I'm using cloudflare for my website.
The issue I got is, after I enabled realip module on nginx, all CDN ips are replaced to user's realip. Then when I check the nginx log, I can't find out whether user is connecting via CDN or connection directly to server.
Below is my configuration:
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
...
real_ip_header X-Forwarded-For;
....
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
Is there any way I can keep both realip and CDN IPs?
Taken from: Including the original visitor IP in your logs
If you want both the CDN IP and the
CF-Connecting-IP
don't use thereal_ip_header
and add$http_cf_connecting_ip
to yourlog_format
: