如何在使用CDN情况下查看访问者的真实IP地址

首页 / 技术杂烩 / 正文

条件

当前教程当且仅支持NGINX内核的网站

步骤

打开NGINX配置,找到http模块,填写如下内容:

set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;

1882884153.png

如果不行,用同样的方法,修改为如下内容:

map $http_x_forwarded_for  $clientRealIp {
    ""    $remote_addr;
    ~^(?P<firstAddr>[0-9\.]+),?.*$    $firstAddr;
}
评论区
头像