多cdn嵌套获取访客真实ip

源站甲骨文德国,国外走cloudflare,国内再套 CloudFront自选。
获取访客真实ip的配置是
real_ip_header CF-CONNECTING-IP; cloudflare的
real_ip_header CloudFront-Viewer-Address; 这个不用说了吧

这两个写一起会报错,只能选择一个,如何才能同时支持2个呢

首先主配置http下包含以下文件
include cf.conf
里面的内容为

real_ip_recursive on;
real_ip_header X-Forwarded-For;

设置Cloudflare的真实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头部字段
  set_real_ip_from 108.138.0.0/15;
  set_real_ip_from 108.156.0.0/14;
  set_real_ip_from 116.129.226.0/25;
  set_real_ip_from 116.129.226.128/26;
  set_real_ip_from 118.193.97.128/25;
  set_real_ip_from 118.193.97.64/26;
  set_real_ip_from 119.147.182.0/25;
  set_real_ip_from 119.147.182.128/26;
  set_real_ip_from 120.232.236.0/25;
  set_real_ip_from 120.232.236.128/26;
  set_real_ip_from 120.253.240.192/26;
  set_real_ip_from 120.253.241.160/27;
  set_real_ip_from 120.253.245.128/26;
  set_real_ip_from 120.253.245.192/27;
  set_real_ip_from 120.52.12.64/26;
  set_real_ip_from 120.52.153.192/26;
  set_real_ip_from 120.52.22.96/27;
  set_real_ip_from 120.52.39.128/27;
  set_real_ip_from 13.113.196.64/26;
  set_real_ip_from 13.113.203.0/24;
  set_real_ip_from 13.124.199.0/24;
  set_real_ip_from 13.210.67.128/26;
  set_real_ip_from 13.224.0.0/14;
  set_real_ip_from 13.228.69.0/24;
  set_real_ip_from 13.233.177.192/26;
  set_real_ip_from 13.249.0.0/16;
  set_real_ip_from 13.32.0.0/15;
  set_real_ip_from 13.35.0.0/16;
  set_real_ip_from 13.48.32.0/24;
  set_real_ip_from 13.54.63.128/26;
  set_real_ip_from 13.59.250.0/26;
  set_real_ip_from 130.176.0.0/17;
  set_real_ip_from 130.176.0.0/18;
  set_real_ip_from 130.176.128.0/18;
  set_real_ip_from 130.176.128.0/21;
  set_real_ip_from 130.176.136.0/23;
  set_real_ip_from 130.176.140.0/22;
  set_real_ip_from 130.176.144.0/20;
  set_real_ip_from 130.176.160.0/19;
  set_real_ip_from 130.176.192.0/19;
  set_real_ip_from 130.176.224.0/20;
  set_real_ip_from 130.176.64.0/21;
  set_real_ip_from 130.176.72.0/22;
  set_real_ip_from 130.176.76.0/24;
  set_real_ip_from 130.176.78.0/23;
  set_real_ip_from 130.176.80.0/22;
  set_real_ip_from 130.176.86.0/23;
  set_real_ip_from 130.176.88.0/21;
  set_real_ip_from 130.176.96.0/19;
  set_real_ip_from 143.204.0.0/16;
  set_real_ip_from 144.220.0.0/16;
  set_real_ip_from 15.158.0.0/16;
  set_real_ip_from 15.188.184.0/24;
  set_real_ip_from 15.207.13.128/25;
  set_real_ip_from 15.207.213.128/25;
  set_real_ip_from 18.154.0.0/15;
  set_real_ip_from 18.160.0.0/15;
  set_real_ip_from 18.164.0.0/15;
  set_real_ip_from 18.172.0.0/15;
  set_real_ip_from 18.192.142.0/23;
  set_real_ip_from 18.200.212.0/23;
  set_real_ip_from 18.216.170.128/25;
  set_real_ip_from 18.229.220.192/26;
  set_real_ip_from 18.238.0.0/15;
  set_real_ip_from 18.244.0.0/15;
  set_real_ip_from 18.64.0.0/14;
  set_real_ip_from 180.163.57.0/25;
  set_real_ip_from 180.163.57.128/26;
  set_real_ip_from 204.246.164.0/22;
  set_real_ip_from 204.246.166.0/24;
  set_real_ip_from 204.246.168.0/22;
  set_real_ip_from 204.246.172.0/24;
  set_real_ip_from 204.246.173.0/24;
  set_real_ip_from 204.246.174.0/23;
  set_real_ip_from 204.246.176.0/20;
  set_real_ip_from 205.251.200.0/21;
  set_real_ip_from 205.251.208.0/20;
  set_real_ip_from 205.251.218.0/24;
  set_real_ip_from 205.251.249.0/24;
  set_real_ip_from 205.251.250.0/23;
  set_real_ip_from 205.251.252.0/23;
  set_real_ip_from 205.251.254.0/24;
  set_real_ip_from 216.137.32.0/19;
  set_real_ip_from 223.71.11.0/27;
  set_real_ip_from 223.71.71.128/25;
  set_real_ip_from 223.71.71.96/27;
  set_real_ip_from 3.10.17.128/25;
  set_real_ip_from 3.101.158.0/23;
  set_real_ip_from 3.11.53.0/24;
  set_real_ip_from 3.128.93.0/24;
  set_real_ip_from 3.134.215.0/24;
  set_real_ip_from 3.231.2.0/25;
  set_real_ip_from 3.234.232.224/27;
  set_real_ip_from 3.236.169.192/26;
  set_real_ip_from 3.236.48.0/23;
  set_real_ip_from 3.35.130.128/25;
  set_real_ip_from 34.195.252.0/24;
  set_real_ip_from 34.216.51.0/25;
  set_real_ip_from 34.223.12.224/27;
  set_real_ip_from 34.223.80.192/26;
  set_real_ip_from 34.226.14.0/24;
  set_real_ip_from 35.158.136.0/24;
  set_real_ip_from 35.162.63.192/26;
  set_real_ip_from 35.167.191.128/26;
  set_real_ip_from 36.103.232.0/25;
  set_real_ip_from 36.103.232.128/26;
  set_real_ip_from 44.227.178.0/24;
  set_real_ip_from 44.234.108.128/25;
  set_real_ip_from 44.234.90.252/30;
  set_real_ip_from 52.124.128.0/17;
  set_real_ip_from 52.15.127.128/26;
  set_real_ip_from 52.199.127.192/26;
  set_real_ip_from 52.212.248.0/26;
  set_real_ip_from 52.220.191.0/26;
  set_real_ip_from 52.222.128.0/17;
  set_real_ip_from 52.46.0.0/18;
  set_real_ip_from 52.46.0.0/22;
  set_real_ip_from 52.46.16.0/20;
  set_real_ip_from 52.46.32.0/19;
  set_real_ip_from 52.46.4.0/23;
  set_real_ip_from 52.47.139.0/24;
  set_real_ip_from 52.52.191.128/26;
  set_real_ip_from 52.56.127.0/25;
  set_real_ip_from 52.57.254.0/24;
  set_real_ip_from 52.66.194.128/26;
  set_real_ip_from 52.78.247.128/26;
  set_real_ip_from 52.82.128.0/19;
  set_real_ip_from 52.82.128.0/23;
  set_real_ip_from 52.82.134.0/23;
  set_real_ip_from 52.84.0.0/15;
  set_real_ip_from 54.182.0.0/16;
  set_real_ip_from 54.182.128.0/20;
  set_real_ip_from 54.182.144.0/21;
  set_real_ip_from 54.182.154.0/23;
  set_real_ip_from 54.182.156.0/22;
  set_real_ip_from 54.182.160.0/21;
  set_real_ip_from 54.182.172.0/22;
  set_real_ip_from 54.182.176.0/21;
  set_real_ip_from 54.182.184.0/22;
  set_real_ip_from 54.182.188.0/23;
  set_real_ip_from 54.182.224.0/21;
  set_real_ip_from 54.182.240.0/21;
  set_real_ip_from 54.182.248.0/22;
  set_real_ip_from 54.192.0.0/16;
  set_real_ip_from 54.230.0.0/17;
  set_real_ip_from 54.230.128.0/18;
  set_real_ip_from 54.230.200.0/21;
  set_real_ip_from 54.230.208.0/20;
  set_real_ip_from 54.230.224.0/19;
  set_real_ip_from 54.233.255.128/26;
  set_real_ip_from 54.239.128.0/18;
  set_real_ip_from 54.239.134.0/23;
  set_real_ip_from 54.239.170.0/23;
  set_real_ip_from 54.239.192.0/19;
  set_real_ip_from 54.239.204.0/22;
  set_real_ip_from 54.239.208.0/21;
  set_real_ip_from 54.240.128.0/18;
  set_real_ip_from 58.254.138.0/25;
  set_real_ip_from 58.254.138.128/26;
  set_real_ip_from 64.252.128.0/18;
  set_real_ip_from 64.252.64.0/18;
  set_real_ip_from 65.8.0.0/16;
  set_real_ip_from 65.9.0.0/17;
  set_real_ip_from 65.9.128.0/18;
  set_real_ip_from 70.132.0.0/18;
  set_real_ip_from 71.152.0.0/17;
  set_real_ip_from 99.79.169.0/24;
  set_real_ip_from 99.84.0.0/16;
  set_real_ip_from 99.86.0.0/16;
  set_real_ip_from 2400:7fc0:500::/40;
  set_real_ip_from 2404:c2c0:500::/40;
  set_real_ip_from 2600:9000:1000::/36;
  set_real_ip_from 2600:9000:2000::/36;
  set_real_ip_from 2600:9000:3000::/36;
  set_real_ip_from 2600:9000:4000::/36;
  set_real_ip_from 2600:9000:5308::/45;
  set_real_ip_from 2600:9000:5310::/44;
  set_real_ip_from 2600:9000:5320::/43;
  set_real_ip_from 2600:9000:5340::/42;
  set_real_ip_from 2600:9000:5380::/41;
  set_real_ip_from 2600:9000:ddd::/48;
  set_real_ip_from 2600:9000:eee::/48;
  set_real_ip_from 2600:9000:f000::/38;
  set_real_ip_from 2600:9000:f400::/40;
  set_real_ip_from 2600:9000:f500::/43;
  set_real_ip_from 2600:9000:f520::/44;
  set_real_ip_from 2600:9000:f534::/46;
  set_real_ip_from 2600:9000:f538::/45;
  set_real_ip_from 2600:9000:f540::/42;
  set_real_ip_from 2600:9000:f580::/41;
  set_real_ip_from 2600:9000:f600::/39;
  set_real_ip_from 2600:9000:f800::/37;
  set_real_ip_from 2600:9000:fff::/48;
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地址传递给后端服务器。

https://hostloc.com/thread-1181753-1-1.html

(0)
jecksmith2024jecksmith2024
上一篇 2024 年 5 月 20 日
下一篇 2024 年 5 月 20 日

相关文章

  • 域名安全检测网站

    https://www.virustotal.com/

    未分类 2024 年 5 月 20 日
  • 推荐一个不错的右键破解插件【SuperCopy 超级复制】,csdn可用

    https://chrome.google.com/webstore/detail/supercopy-enable-copy/onepmapfbjohnegdmfhndpefjkppbjkm 找到一个阅读舒服些的小说网站,然后不能复制就很烦,生僻字,做笔记都不方便。 此站完整度高,笔趣阁漏段落就很烦,站长估计很佛系,背墙了也不管么! 然后就找到了这个插件,…

    未分类 2024 年 5 月 7 日
  • 个人常用chrome插件

    Proxy SwitchyOmega Open Multiple URLs Copy URL + Title 2.0 Fast Copy links1 Infinity 新标签页 7.3.14 JSONView 0.0.32.3 Keywords Everywhere – Keyword Tool LastPass: Free Password Manage…

    未分类 2024 年 5 月 20 日
  • opencart 修改后台订单的链接 展示图片

    'href' => HTTP_CATALOG . 'index.php?route=product/product'. '&product_id=' . $product['product_id'], // 'href' => $this-…

    未分类 2024 年 5 月 20 日
  • DMCA数据库lumendatabase.org

    Lumen,原称为寒蝉效应(Chilling Effects),是一个协作编辑的档案库,由几个法学研究机构和电子前哨基金会创立,旨在保护合法的网络活动免受法律威胁。人们在收到“停止并终止”权利通知书后,可以提交给它的网站[1](Chilling Effects Clearinghouse),并获得有关其法律权利和责任的信息。这个网站最初是由哈佛大学伯克曼互联…

    未分类 2024 年 5 月 20 日
  • WP 产品站常用插件名字

    订单导出插件 Advanced Order Export For WooCommerce 表单 Contact Form 7 支付 Direct checkout, WooCommerce Single page checkout , WooCommerce One page checkoutWooCommerce PayPal Checkout Gatew…

    未分类 2024 年 5 月 20 日