全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1983|回复: 14
打印 上一主题 下一主题

关于多cdn嵌套获取访客真实ip

[复制链接]
1#
发表于 2023-6-23 23:55:02 | 显示全部楼层
要同时支持两个真实IP头部字段,您可以使用Nginx的real_ip_header和set_real_ip_from指令来配置。以下是一个示例配置:

  1. http {
  2.     # 设置Cloudflare的真实IP头部字段
  3.     real_ip_header CF-CONNECTING-IP;
  4.     set_real_ip_from 103.21.244.0/22;
  5.     set_real_ip_from 103.22.200.0/22;
  6.     set_real_ip_from 103.31.4.0/22;
  7.     set_real_ip_from 104.16.0.0/12;
  8.     set_real_ip_from 108.162.192.0/18;
  9.     set_real_ip_from 131.0.72.0/22;
  10.     set_real_ip_from 141.101.64.0/18;
  11.     set_real_ip_from 162.158.0.0/15;
  12.     set_real_ip_from 172.64.0.0/13;
  13.     set_real_ip_from 173.245.48.0/20;
  14.     set_real_ip_from 188.114.96.0/20;
  15.     set_real_ip_from 190.93.240.0/20;
  16.     set_real_ip_from 197.234.240.0/22;
  17.     set_real_ip_from 198.41.128.0/17;
  18.     set_real_ip_from 199.27.128.0/21;
  19.     set_real_ip_from 2400:cb00::/32;
  20.     set_real_ip_from 2606:4700::/32;
  21.     set_real_ip_from 2803:f800::/32;
  22.     set_real_ip_from 2405:b500::/32;
  23.     set_real_ip_from 2405:8100::/32;
  24.     set_real_ip_from 2c0f:f248::/32;
  25.     set_real_ip_from 2a06:98c0::/29;

  26.     # 设置CloudFront的真实IP头部字段
  27.     real_ip_header CloudFront-Viewer-Address;
  28.     set_real_ip_from 0.0.0.0/0;

  29.     # 其他Nginx配置...
  30. }
复制代码



在上面的示例中,我们使用set_real_ip_from指令指定了Cloudflare和CloudFront的IP地址范围。您可以根据需要添加或修改这些IP地址范围。

请确保在Nginx配置中的正确位置添加这些指令,并重新加载Nginx配置以使其生效。这样,Nginx将同时支持两个真实IP头部字段,并将访客的真实IP地址传递给后端服务器。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-5-11 04:47 , Processed in 0.052261 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表