使用安全宝、加速乐后apache、Nginx无法获取访客真实IP的解决方法
在使用安全宝、加速乐等CDN服务以后,在APACHE和NGINX中获取的地址就变成了CDN节点的IP地址而不是访客的真实IP了。要想恢复wordpress的IP记录功能,请按下边的实例操作:
apache:
打开apache配置文件(默认路径:/etc/httpd/conf/httpd.conf)
找到 LogFormat,将LogFormat设置中%h全部改为%{X-Forwarded-For}i
改为如下
LogFormat "%{X-Forwarded-For}i %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t "%r" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
LogFormat "%{X-Forwarded-For}i %l %u %t "%r" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
Nginx:
类似apache,将日志设置改为:
'$http_x_forwarded_for - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" ';
你也许会感兴趣:
使用安全宝、加速乐后wordpress无法获取访客真实IP的解决方法