不建议使用多层CDN嵌套,这不会带来明显的好处。如需要真实IP读取,你可以在最上层的CDN设置header重写/自定义,将连接IP(忽略上层DLIP)的值填入connect-ip中,并添加规则删除客户端传来的connet-ip/X-real-ip/X-forward-for等可能包含IP地址的header,CDN有删除功能最好启用一下。
接下来在nginx设置
#设置真实IP
map $http_connect_ip $custom_x_forwarded_for {
default $proxy_add_x_forwarded_for;
"~^(\d+\.\d+\.\d+\.\d+)$" $1;
"~^([0-9A-Fa-f:]+)$" $1;
}
map $http_connect_ip $custom_x_real_ip {
default $remote_addr;
"~^(\d+\.\d+\.\d+\.\d+)$" $1;
"~^([0-9A-Fa-f:]+)$" $1;
}