本帖最后由 冰戈→/回头 于 2020-12-14 14:58 编辑
如题,DZ3.4使用百度云cdn,登录IP老是提示cdn的IP,请问DX3.4该如何修改代码呢?
==========================
环境:CentOS 8.2.2004(Py3.7.8) php7.4 apache2.4 mysql8.0
CDN:百度云加速免费版
目前通过修改,已经可以正常识别到用户的真实IP了
1、修改apache配置文件
<IfModule log_config_module>
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
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
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
2、修改discuz 3.4中文件/source/class/discuz/discuz_application.php
private function _get_client_ip() {
$ip = $_SERVER['REMOTE_ADDR'];
if (!$this->config['security']['onlyremoteaddr']) {
if (isset($_SERVER['X-Forwarded-For']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['X-Forwarded-For'])) {
$ip = $_SERVER['X-Forwarded-For'];
} elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
foreach ($matches[0] AS $xip) {
if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
$ip = $xip;
break;
}
}
}
}
return $ip == '::1' ? '127.0.0.1' : $ip;
}
如有错误请各位大佬指正。
|