I have nginx and setup simple node application but due to some reason I am not able to get visitors IP, when I dump all the request header I get long string of IPv6 IP. I have follow guide where we need to update “Cloudflare’s latest IP ranges” in nginx config but still not able to get ipv4 IP address.
It’s been a while since I configured my NGINX for this, but I believe all I did was create this /etc/nginx/conf.d/Cloudflare.conf. And now that I look at it, I’m wondering why it doesn’t include Cloudflare’s IPv6 addresses.
# $remote_addr rewriting in case of NGINX behind Cloudflare.
# See also mod_Cloudflare Apache module configuration.
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 104.16.0.0/12;
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;
set_real_ip_from 199.27.128.0/21;
real_ip_header CF-Connecting-IP;
“host”:“mydummy.com”,“x-real-ip”:“2a32:b650:gc3:1:q08c:aha8:44b0:7kb9”,“x-forwarded-for”:“2a32:b650:gc3:1:q08c:aha8:44b0:7kb9, 2a32:b650:gc3:1:q08c:aha8:44b0:7kb9”,“x-nginx-proxy”:“true”,“connection”:“upgrade”,“accept-encoding”:“gzip”,“cf-ipcountry”:“IN”,“cf-ray”:“49773dddd9cf9d44-AMS”,“x-forwarded-proto”:“https”,“cf-visitor”:"{“scheme”:“https”}",“accept”:“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”,“user-agent”:“Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15”,“accept-language”:“in-in”,“cookie”:“connect.sid=s%4Ar-kddfdA67PME.SgfdfdfdfdfeZ%2B7q2cd2Qp9tdfdf0; GPSLSC=1v_vdfdf!x1V6dfdfbNd; io=wLfffddfsdfeEqAAEA; _cfduid=d8d1d899fdfdfsdfsfdsfsdfdsfdf30091”,“cf-connecting-ip”:“2a32:b650:gc3:1:q08c:aha8:44b0:7kb9”,“cdn-loop”:“Cloudflare”}
Actually I am ok with ipv6 but its not consistent on different servers. Some show ipv4 and some ipv6. There is a setting in Cloudflare to disable ipv6 and one more to enable ipv4, do you think this will help?
Some ISPs still fail to properly support IPv6, so the visitor might end up visiting via IPv4 as fallback. Currently 25% of the internet is IPv6-capable -> https://www.google.com/intl/en/ipv6/statistics.html
If you cannot support both formats at the same time, you can disable IPv6 via the API.