We are running behind CloudFlare (on most sites, but not all). I’m still seeing some traffic coming from what seems to be countries we have blocked. So I’m trying to see if I can actually see the CF IP as well in the log. So I added this into nginx.conf:
map $realip_remote_addr $via_cf {
"" "direct"; # no real_ip rewrite -> not from Cloudflare range
default "cloudflare"; # real_ip rewrote -> came from a Cloudflare IP
}
We are using nginx + Apache, so in nginx config we have:
We are blocking them at Cloudflare’s end via the rules. Most of them are blocked, but I’m still seeing some getting through that I’m not convinced should be. So I’m trying to see if I can set a flag / show the proxy IP of Cloudflare, if it exists - so I could then confirm if they are bypassing CF (by using the old exposed IPs from the old DNS). If thats the case, then I need to lock the sites down so they only allow CF IPs - but I don’t really want to do it server-wide, as not all accounts use it
To test it, edit the nginx conf of one of your domains /etc/nginx/conf.d/domains/example.net.conf and /etc/nginx/conf.d/domains/example.net.ssl.conf and instead of combined, use the new cloudflare log format.
Thanks. I finally figured it out… CF was accessing the http version, and I was editing the ssl version config… duh! So although what I was seeing on the frontend was SSL, the bit CF was calling was http … thus is was never calling my new log. Now it works perfectly.
I apologize if this is a stupid question, I’ve been reading for several days and there are a lot of concepts, as I’m looking to migrate my sites to this new panel.
My idea is that, since I’m also using Cloudflare, I want site visitors to log in with their real IP addresses. Is the procedure described here the correct one for this? I’ve seen that the Cloudflare IPs are in this file: /etc/nginx/conf.d/cloudflare.inc, so I deduced that it’s configured for this, but right now, I’m completely confused…
No worries, you don’t need to do anything. The real IP will appear in your logs. This topic was about logging Cloudflare’s IP as well, not only the clients’ IPs.