Discuz!x3,4 阿里云DCDN配置获取客户端ip
需求:阿里云的全站加速下支持获取客户端ip解决:
1.修改文件: source\class\discuz\discuz_application.php
搜索:
private function _get_client_ip() {函数
替换为:
private function _get_client_ip() {
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['X-Forwarded-For']) && preg_match('/^({1,3}\.){3}{1,3}$/', $_SERVER['X-Forwarded-For'])) {
$ip = $_SERVER['X-Forwarded-For'];
}elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^({1,3}\.){3}{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif (isset($_SERVER['HTTP_ALI_CDN_REAL_IP']) && preg_match('/^({1,3}\.){3}{1,3}$/', $_SERVER['HTTP_ALI_CDN_REAL_IP'])) {
$ip = $_SERVER['HTTP_ALI_CDN_REAL_IP'];
} 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 AS $xip) {
if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
$ip = $xip;
break;
}
}
}
return $ip == '::1' ? '127.0.0.1' : $ip;
}
2.修改 DCND缓存规则里面的自定义http
3.nginx设置
server部分 添加:
add_header http_Ali_Cdn_Real_Ip $http_Ali_Cdn_Real_Ip;
4.完成
页:
[1]