We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
Showing the real client ip (behind nat) - HELP!
Showing the real client ip (behind nat) - HELP!
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?
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!
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 in PHP.
Hope this helps.
Regards.
To find the "real" client IP you have to use
Code: Select all
<?php echo $_SERVER['HTTP_X_REAL_IP']; ?>
Hope this helps.
Regards.
Re: Showing the real client ip (behind nat) - HELP!
Additionaly, I have tried another config on my Debian 7, you can modify the file:
And replace it with this conf
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.
Code: Select all
/etc/apache2/mods-enabled/rpaf.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>
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!
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;
# 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;
-
- Posts: 26
- Joined: Mon Jan 04, 2016 3:09 pm
Re: Showing the real client ip (behind nat) - HELP!
Someone managed to solve this problem of IP visitors?
-
- Posts: 26
- Joined: Mon Jan 04, 2016 3:09 pm
Re: Showing the real client ip (behind nat) - HELP!
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 usein PHP.Code: Select all
<?php echo $_SERVER['HTTP_X_REAL_IP']; ?>
Hope this helps.
Regards.
Hello friend, in which file I see this setting?