具有CDN和real_ip的Nginx IPV6

问题描述 投票:0回答:1

我正在将CDN用于我的网站,并希望获得客户的真实IP。我的配置如下:

set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
real_ip_header    X-Forwarded-For;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent"';

过去该配置运行良好,但是由于我的CDN支持IPV6,所以出现了以下问题。

我被迫使用IPV6访问我的网站,然后应我的要求:

remote_addr: 117.34.13.18
http_x_forwarded_for: 2409:890c:530:a849:84b5:3a3b:d0ce:4e5b
realip_remote_addr: 117.34.13.18
proxy_add_x_forwarded_for: 2409:890c:530:a849:84b5:3a3b:d0ce:4e5b, 117.34.13.18

[当nginx获得IPV6地址时,nginx似乎将CDN IP用作remote_addr。

然后,如果用户使用的是IPV6,我将无法获得他们的RealIp。

我检查了nginx文件,据说realip支持IPV6。有什么方法可以获取客户的IPV6 realIP吗?

我知道我可以将$ http_x_forwarded_for用作客户端的IP,但是如果客户端直接连接到我的服务器,则将没有$ http_x_forwarded_for。

nginx cdn ipv6 real-ip
1个回答
0
投票

我有完全相同的问题,直到现在我都找不到解决方法。

就我而言,我在后端使用远程地址,因此我考虑从x_forwarded_for(第一个元素)中提取真实IP。

© www.soinside.com 2019 - 2024. All rights reserved.