Page 1 of 1

Showing the real client ip (behind nat) - HELP!

Posted: Thu Oct 15, 2015 1:01 pm
by abdullakh
Hello,

I am having a server which is behind nat (mikortik router) the client ip in the apache and nginx showing the mikortik router which is 192.168.0.254 rather than the client IP.
<?php
echo $_SERVER['REMOTE_ADDR'];
?>

I have installed many modules in the apache such as remote-ip... but no lucky.

I have forwarded the domain via cloudflare and I can take the real visitor ip, and it is shows via $_SERVER['HTTP_CF_CONNECTING_IP']

The question now how $_SERVER['HTTP_CF_CONNECTING_IP'] is working? I want to make something like this without using cloudflare.

May you help?

Re: Showing the real client ip (behind nat) - HELP!

Posted: Fri Oct 16, 2015 5:11 am
by andrex
That's because you are using NGINX as proxy, so Apache sees any petition with the server's IP.

To find the "real" client IP you have to use

Code: Select all

<?php echo $_SERVER['HTTP_X_REAL_IP']; ?>
in PHP.

Hope this helps.

Regards.

Re: Showing the real client ip (behind nat) - HELP!

Posted: Wed Oct 28, 2015 11:52 am
by mike08
Additionaly, I have tried another config on my Debian 7, you can modify the file:

Code: Select all

/etc/apache2/mods-enabled/rpaf.conf
And replace it with this conf

Code: Select all

<IfModule rpaf_module>
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 192.168.1.150 192.168.1.151 192.168.1.152
RPAFheader X-Forwarded-For
</IfModule>
Modify the ips for the one you use on your server as proxy.
Then restart apache from within VestaCP admin area this should show clients real IP instead of the nginx proxy.

Re: Showing the real client ip (behind nat) - HELP!

Posted: Thu Nov 12, 2015 9:52 pm
by rnbmafia
nginx.conf



# Proxy settings
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header Set-Cookie;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;

Re: Showing the real client ip (behind nat) - HELP!

Posted: Wed Jan 27, 2016 9:28 pm
by xandehenrique
Someone managed to solve this problem of IP visitors?

Re: Showing the real client ip (behind nat) - HELP!

Posted: Wed Jan 27, 2016 9:33 pm
by xandehenrique
andrex wrote:That's because you are using NGINX as proxy, so Apache sees any petition with the server's IP.

To find the "real" client IP you have to use

Code: Select all

<?php echo $_SERVER['HTTP_X_REAL_IP']; ?>
in PHP.

Hope this helps.

Regards.

Hello friend, in which file I see this setting?