三二互联专业提供速度最快最稳定的美国服务器、香港服务器。中美直连,亚洲优化![ 代理登陆 ] [ 付款方式 ] [ 找回密码 ][ 电子协议责任书 ]
硬件资源保障

采用高配品牌服务器

主流强悍CPU配置

确保服务高速稳定运行

中美直连线路

中美直连亚洲优化

采用中国CN2骨干网络

保证速度飞快稳定高效

如何配置宝塔Nginx的CF‑Connecting‑IP?

美国、香港服务器

如何配置宝塔Nginx的CF‑Connecting‑IP?

10-14   来源:

 ## 式一:自动拉取 CF 官方网段(推荐,自动更新,避免手动复制网段过期)

 
SSH 执行下面脚本,自动下载 Cloudflare IPv4+IPv6 网段,生成独立配置文件`/www/server/nginx/conf/cloudflare-realip.conf`
 
#下载ipv4
curl -fsS https://www.cloudflare.com/ips-v4 -o /tmp/cf_v4.txt
awk "!seen[$0]++ {print "set_real_ip_from " $1 ";"}" /tmp/cf_v4.txt > /www/server/nginx/conf/cloudflare-realip.conf
 
#下载ipv6并追加
curl -fsS https://www.cloudflare.com/ips-v6 -o /tmp/cf_v6.txt
awk "!seen[$0]++ {print "set_real_ip_from " $1 ";"}" /tmp/cf_v6.txt >> /www/server/nginx/conf/cloudflare-realip.conf
 
#追加核心realip指令
cat >> /www/server/nginx/conf/cloudflare-realip.conf <<"EOF"
real_ip_header CF-Connecting-IP;
real_ip_recursive on;
EOF
 
打开宝塔面板 →【软件商店】→Nginx→【配置修改】
找到最外层 `http {` 大括号,在内部加入一行引入配置文件:
 
include /www/server/nginx/conf/cloudflare-realip.conf;
写在`http{}`全局,**不要写在单个 server {} 内**,保证所有站点、宝塔 Nginx 防火墙全部生效宝塔面板。
 
保存,先校验语法,再重载 Nginx
 
nginx -t
nginx -s reload
方式二:手动写入网段(临时测试,不建议长期,CF 网段会新增)
 
Nginx 配置修改,`http{}`内粘贴
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/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
 
real_ip_header CF-Connecting-IP;
real_ip_recursive on;
严禁写 `set_real_ip_from 0.0.0.0/0;`,攻击者可以伪造`CF‑Connecting‑IP`篡改访客 IP,高危漏洞宝塔面板。
 
 

三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快

上一篇:如何在Nginx配置文件中使用CF‑Connecting‑IP? 下一篇:如何设置宝塔 Nginx 防火墙?

美国GIA服务器三二互联版权所有 WWW.250.cc 2008-2015 All Rights Reserved
三二互联 - 专业的美国C3服务器、香港vps、抗DOOS流量清洗、云备份系统、网站加速系统、美国GIA服务器和香港云服务器产品提供商
三二互联24小时在线工单系统为您提供全面、专业、周到的技术支持与服务
咨询热线:400-679-9994(免长话费)