Restoring original visitor IPs: Logging visitor IP addresses with mod_cloudflare Tutorial

outplayed

Moderator
Moderator
Collaborate
Registered
Joined
Oct 27, 2019
Messages
151
Points
63

Reputation:

This steps worked for me, doesn´t mean this a 100% trusted Guide, but any other user could have the same problem.

When i installed my xenforo comunity into a VPS from contabo, i found that everyone connected showed on the online page the same IP. Im ussing google adsense and maybe that could be a problem with monetization
Im using Ubuntu 16.04 and VestaCP

You have to do this to fix this problem.

Due im using Nginx and Apache2 i had to follow these steps

Modifications on Apache 2

.Debian/Ubuntu


Code:
sudo apt-get install apache2-dev libtool git

Clone the following for the most recent build of mod_cloudflare:

Code:
git clone https://github.com/cloudflare/mod_cloudflare.git; cd mod_cloudflare

. Restart and verify the module is active:

Debian/Ubuntu:

Code:
sudo apachectl restart; apache2ctl -M|grep cloudflare


Modifications for Ngixn

Add these IP, in this exactly location etc/nginx/nginx.conf

Code:
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 2400:cb00::/32;

set_real_ip_from 2606:4700::/32;

set_real_ip_from 2803:f800::/32;

set_real_ip_from 2405:b500::/32;

set_real_ip_from 2405:8100::/32;

set_real_ip_from 2c0f:f248::/32;

set_real_ip_from 2a06:98c0::/29;


real_ip_header CF-Connecting-IP;

#real_ip_header X-Forwarded-For;


After this, restart Nginx and Apache2 services

And add this into xenforo config file at the end


Code:
if (isset($_SERVER['HTTP_CF_CONNECTING_IP']))
{ $_SERVER['REMOTE_ADDR']
= $_SERVER['HTTP_CF_CONNECTING_IP'];}
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_X_FORWARDED_FOR"];
 

boo

Well-known member
Registered
Joined
Aug 29, 2019
Messages
54
Points
28

Reputation:

You say it's fixed but is it? You have correctly setup how to restore the real IP if using cloudflare, but if you removed cloudlare it would probably show your server IP again, because your nginx isn't configured correctly.
 

outplayed

Moderator
Moderator
Collaborate
Registered
Joined
Oct 27, 2019
Messages
151
Points
63

Reputation:

Why do u said that, i have configure apache and nginx both
 

thomsa

Moderator
Staff member
Moderator
S.V.I.P Member
Collaborate
Registered
Joined
Jun 22, 2019
Messages
1,066
Points
173

Reputation:

yes, i think it. your isn't configured correctly.
 

thomsa

Moderator
Staff member
Moderator
S.V.I.P Member
Collaborate
Registered
Joined
Jun 22, 2019
Messages
1,066
Points
173

Reputation:

@outplayed work becouse it fix on apache not fix on nginx.
 

thomsa

Moderator
Staff member
Moderator
S.V.I.P Member
Collaborate
Registered
Joined
Jun 22, 2019
Messages
1,066
Points
173

Reputation:

mod_cloudflare for Apache
Copyright CloudFlare Inc. 2016
 

outplayed

Moderator
Moderator
Collaborate
Registered
Joined
Oct 27, 2019
Messages
151
Points
63

Reputation:

@thomsa APACHE get the info from nginx actually look
Capture.PNG
 

thomsa

Moderator
Staff member
Moderator
S.V.I.P Member
Collaborate
Registered
Joined
Jun 22, 2019
Messages
1,066
Points
173

Reputation:

@outplayed on this thread you add mod_cloudflare to apache and not use nginx.
test open url by nginx and apache
 

boo

Well-known member
Registered
Joined
Aug 29, 2019
Messages
54
Points
28

Reputation:

For start you don't need to add anything to your xf2 config for cloudlare.

If your server was setup correctly in the first place you wouldn't be getting the server IP for all users, it would have been cloudlares IP.

If your running nginx and apache all you need to add is

Code:
Add these IP, in this exactly location etc/nginx/nginx.conf

Code:
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 2400:cb00::/32;

set_real_ip_from 2606:4700::/32;

set_real_ip_from 2803:f800::/32;

set_real_ip_from 2405:b500::/32;

set_real_ip_from 2405:8100::/32;

set_real_ip_from 2c0f:f248::/32;

set_real_ip_from 2a06:98c0::/29;


real_ip_header CF-Connecting-IP;

#real_ip_header X-Forwarded-For;
 

outplayed

Moderator
Moderator
Collaborate
Registered
Joined
Oct 27, 2019
Messages
151
Points
63

Reputation:

Thx for being so damn pro mate, im sharing all i had to do to make it work, that doesnt mean this the 100% TRUSTED GUIDE TO DO IT CLEAR ?, dunno why u werent trying to fix it when i had the problem, and u are here right now trying to prove "something" i dont understand but anyways thx u for share all ur knowledge with simple human like us, this´s the prove it worked
123123312312312321.PNG
 
Last edited:

boo

Well-known member
Registered
Joined
Aug 29, 2019
Messages
54
Points
28

Reputation:

For anyone reading this thread I did it this way: (no cloudflare)

Apache needs log the original user's IP address in the access logs instead of the IP address of nginx (127.0.0.1).

We can modify the LogFormat line in /etc/apache2/apache2.conf and replace %h with %{X-Forwarded-For}i:
nano /etc/apache2/apache2.conf

[...]
#LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
 
Top