关于多CDN嵌套获取访客真实IP

43次阅读

共计 1346 个字符,预计需要花费 4 分钟才能阅读完成。

源站甲骨文德国,国外走 Cloudflare,国内再套 CloudFront 自选。获取访客真实 IP 的配置是 real_ip_header CF-CONNECTING-IP; cloudflare 的 real_ip_header CloudFront-Viewer-Address; 这个不用说了吧这两个写一起会报错,只能选择一个,如何才能同时支持 2 个呢 兔子淘 2023-06-23 23:55 2 要同时支持两个真实 IP 头部字段,您可以使用 Nginx 的 real_ip_header 和 set_real_ip_from 指令来配置。以下是一个示例配置:nginx| 复制代码 http {    # 设置 Cloudflare 的真实 IP 头部字段     real_ip_header CF-CONNECTING-IP;    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 104.16.0.0/12;    set_real_ip_from 108.162.192.0/18;    set_real_ip_from 131.0.72.0/22;    set_real_ip_from 141.101.64.0/18;    set_real_ip_from 162.158.0.0/15;    set_real_ip_from 172.64.0.0/13;    set_real_ip_from 173.245.48.0/20;    set_real_ip_from 188.114.96.0/20;    set_real_ip_from 190.93.240.0/20;    set_real_ip_from 197.234.240.0/22;    set_real_ip_from 198.41.128.0/17;    set_real_ip_from 199.27.128.0/21;    set_real_ip_from 2400:cb00::/32;    set_real_ip_from 2606:4700::/32;    set_real_ip_from 2803:f800::/32;    set_real_ip_from 2405:b500::/32;    set_real_ip_from 2405:8100::/32;    set_real_ip_from 2c0f:f248::/32;    set_real_ip_from 2a06:98c0::/29;    # 设置 CloudFront 的真实 IP 头部字段     real_ip_header CloudFront-Viewer-Address;    set_real_ip_from 0.0.0.0/0;    # 其他 Nginx 配置 …} 在上面的示例中,我们使用 set_real_ip_from 指令指定了 Cloudflare 和 CloudFront 的 IP 地址范围。您可以根据需要添加或修改这些 IP 地址范围。请确保在 Nginx 配置中的正确位置添加这些指令,并重新加载 Nginx 配置以使其生效。这样,Nginx 将同时支持两个真实 IP 头部字段,并将访客的真实 IP 地址传递给后端服务器。

正文完
 0