Можно
так, а именно:
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;
# .. put all Cloudflare ranges like above
# ddos-guard.net range:
set_real_ip_from 186.2.160.0/24;
# DDoS Guard
geo $use_x_real_ip {
default 0;
186.2.160.0/24 1;
}
# Cloudflare
geo $use_x_cf_connecting_ip {
default 0;
103.21.244.0/22 1;
103.22.200.0/22 1;
103.31.4.0/22 1;
# all other Cloudflare's ranges ...
}
map "$use_x_real_ip:$use_x_cf_connecting_ip" $real_ip_header {
default 'X-Forwarded-For';
"1:0" 'X-Real-Ip';
"0:1" 'CF-Connecting-IP';
}
real_ip_header $real_ip_header;