修改nginx的配置文件
编辑/usr/local/nginx/conf/nginx.conf
加入以下文本
1proxy_set_header Host $host;
2proxy_set_header X-Real-IP $remote_addr;
3proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
保存配置文件,重启nginx
让apache2.4.16日志记录正确的访客IP
在LogFormat中加入 %{X-Forwarded-For}i 例如:
1LogFormat "%{X-Forwarded-For}i %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" vrnishcombined
#CustomLog logs/access_log combined
#CustomLog "|/usr/sbin/rotatelogs/var/log/httpd/access_log.%Y%m%d 7200 480" combined(apapche默认)
CustomLog "|/usr/sbin/cronolog /var/log/httpd/access_log.%Y%m%d" combined
php程序获取正确访客IP
if ($_SERVER["HTTP_X_FORWARDED_FOR"]=="") {
$user_ip=$_SERVER["REMOTE_ADDR"];
} else {
$user_ip=$_SERVER["HTTP_X_FORWARDED_FOR"];
}
?>
本文出自 “让我men共同成长” 博客,请务必保留此出处http://wujingfeng.blog.51cto.com/5725921/1720431
原文:http://wujingfeng.blog.51cto.com/5725921/1720431
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!