Unable to get Visitors IP in Nginx


#1

Hello,

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.

Please help


#2

Which guide did you follow?

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;

#3

Thanks for the reply.

I checked this Guide:

No matter what I do I get this kind of response:

“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”}


#4

Those are your visitors’ IP addresses. I have IPv6 at home, so when I visit sites, that’s the IP address they will get in the request headers.


#5

so can I get ipv4 IP?. When I tried on third party sites like whatsmyip they showed both ipv6 and ipv4 IPs. How can I get Ipv4 IP? Any idea?


#6

Cloudflare’s cf-connecting-ip and that x-forwarded-for header just show the browser’s IP address. That’s all you’re going to get from IPv6 visitors.


#7

If a visitor visited you using IPv6 that is the only address you have access to… it is the IP address of the visitor.


#8

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?


#9

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.


closed #10

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.