apache2.4.16 显示真实ip


修改nginx的配置文件


编辑/usr/local/nginx/conf/nginx.conf


加入以下文本


1 proxy_set_header        Host $host;


2 proxy_set_header        X-Real-IP $remote_addr;


3 proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;


保存配置文件,重启nginx


让apache2.4.16日志记录正确的访客IP


在LogFormat中加入 %{X-Forwarded-For}i 例如:


1 LogFormat "%{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"];


 }


 ?>


你可能感兴趣的:(apache2.4.16)