How to pass user IP address to cloudflare

I have a website that is using the Cloudflare Manage Transforms rule to add visitor location headers.

My website is using a proxy and Cloudflare is returning the proxy IP address as the (Cf-Connecting-Ip) and the proxy Country as (Cf-Ipcountry).

I’ve tried passing the correct user IP via the (x-forwarded-for) header and the (x-real-ip) header but Cloudflare still uses the Proxy IP address

Is it possible to pass somehow client IP from the proxy server to Cloudflare so geolocation would give me the IP country from the client location?

Thanks.

1 Like

Are you running a proxy server in front of Cloudflare?

Yes, I’m running a proxy server in front of Cloudflare

Is there a reason that you are running a proxy server in front of a proxy service?

You can also use a page rule to set an outbound header with an incoming header


This rule will set a header of client-ip with the value of what ever the x-forwarded-for header is set to.

Thanks, @Cyb3r-Jak3, for the assistance so far.

Yes, we are using the proxy for some essential custom routing.

I’ve set this rule, Cloudflare passes the Client-Ip header correctly but the (‘Cf-Connecting-Ip’) and the (‘Cf-Ipcountry’) still point to the Proxy IP address and Country respectively.

And that’s not going to change. Cloudflare uses those headers to report back about what’s making the connection.

Thank you @sdayman, So how do I get the user’s real IP address and country and not the proxy IP address and country

The User’s IP address will be in the client-ip header you just set. You might be able to use the same trick you used for client-ip, but set client-country from http.requester-headers[“cf-ipcountry”][0].

I’ve set the dynamic header:

client-country => http.requester-headers[“cf-ipcountry”][0]

But Cloudflare just ignores the header and does not send it

I’m not entirely sure that one will work the same way. Now that I think about it, that’s not going to work, since Cloudflare gets the country info from whatever connects to it. So…nevermind. Sorry for the confusion.

You’d have to do a lookup on your server based upon the IP address you passed through. Something like this:

Thank you, we are looking at setting up maxmind geoip2 as a last resort.

We want to know if there is a way to still use Cloudflare without building out our own solution

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