负载均衡情况下获取真实ip的方法


1、打开文件:/etc/httpd/conf/httd.conf。 2、在文件中查找:”CustomLog”,找到如下配置块: 查看到当前使用的LogFormat为”combined” (如果实际启用的为其他日志格式,替换相应的格式定义即可)。
#
# For a single logfile with access, agent, and referer information
# (Combined Logfile Format), use the following directive:
#
CustomLog  logs/access_log combined
3、在文件中查找:”LogFormat”,找到如下配置块(combined格式定义): LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 将其修改为: LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{X-Forwarded-For}i\" " combined  4、保存并关闭文件/etc/httpd/conf/httd.conf。 5、重启Apache服务。   需要注意的是在第三条中用大括号包含的变量要与服务器对应,如果不知道可以在phpinfo或类似信息中获取到!    

相关内容