来自用户的REMOTE_ADDR IP,而不是来自Nginx反向代理服务器的IP [英] REMOTE_ADDR IP from user instead off Nginx reverse proxy server
问题描述
我已经阅读了很多有关此主题的文章,并尝试了几种解决方案,但没有找到有效的分割槽.
我在Apache服务器之前设置了Nginx反向代理.当我的PHP应用程序使用 REMOTE_ADDR 函数时,它将获取Nginx服务器的IP,而不是用户.
我正在使用 Apache 2.4.10 ,因此应安装module_remoteip.c.但是它没有被加载.
因此,我安装了rpaf_module.看来此模块已正确安装,并且phpinfo()mod_rpaf-2与已加载的模块一起显示.我用以下内容修改了/etc/apache2/mods-available/rpaf.conf 文件:
<IfModule rpaf_module>
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 172.19.0.5 # ip of Nginx server
RPAFheader X-Forwarded-For
</IfModule>
我的Nginx配置如下:
location / {
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass 172.19.0.4;
}
感谢您的帮助?
访问者的IP地址应使用
访问$_SERVER['HTTP_X_REAL_IP'];
代替
$_SERVER['REMOTE_ADDR'];
如果要替换REMOTE_ADDR
标头,请在NGINX配置中尝试以下操作:(并且不要忘记重新加载/重新启动NGINX服务器)
location / {
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_pass 172.19.0.4;
}
I already read a lot of posts about this topic and tried several solutions but did not find a working slotion.
I have setup an Nginx reverse proxy in front of my Apache server. When my php application uses the REMOTE_ADDR function it gets the IP of the Nginx server instead off the user.
I'm using Apache 2.4.10, so module_remoteip.c should be installed. But it is not loaded.
Therefore I installed rpaf_module. It looks like this module is installed correctly, with phpinfo() mod_rpaf-2 is shown with the loaded modules. The I modified the /etc/apache2/mods-available/rpaf.conf file with the following content:
<IfModule rpaf_module>
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 172.19.0.5 # ip of Nginx server
RPAFheader X-Forwarded-For
</IfModule>
My Nginx configuration look like this:
location / {
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass 172.19.0.4;
}
Help is appreciated?
The IP address of your visitor should be accessible using
$_SERVER['HTTP_X_REAL_IP'];
instead of
$_SERVER['REMOTE_ADDR'];
If you want to replace the REMOTE_ADDR
header, try this in your NGINX configuration: (And don't forget to reload/restart your NGINX-server)
location / {
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_pass 172.19.0.4;
}
这篇关于来自用户的REMOTE_ADDR IP,而不是来自Nginx反向代理服务器的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!