各位大佬,
我这边的结构是这样的:
前面挂了 Cloudflare 橙云
后面一台 Debian,上面跑:
Nginx
哪吒面板(dashboard):监听 127.0.0.1:8008
另一个管理面板:监听 127.0.0.1:35624
域名举例:
status.example.com → 哪吒面板 + gRPC
panel.example.com → 管理面板,路径 /rX9pQe7T/
整条链路就是:客户端 / Agent → CF → Nginx → 本机服务
ipcf 部分(Cloudflare 的 IP)
/etc/nginx/conf.d/ipcf.conf 里面我已经把 CF 的网段都写进去了,用的是官方那堆 IP:
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
……后面一堆 CF IPv4 / IPv6
在 server 里这样用:
underscores_in_headers on;
include /etc/nginx/conf.d/ipcf.conf;
real_ip_header CF-Connecting-IP;
real_ip_recursive on;
也就是说:real_ip 这块我自认为是按 CF 教程配好的。
管理面板这边
panel.example.com 这个域名里,只有面板路径 /rX9pQe7T/ 这个 location 里加了 IP 白名单:
location /rX9pQe7T/ {
proxy_pass http://127.0.0.1:35624;include /etc/nginx/conf.d/ruleip.conf; # 这里有 allow 某个服务器 IP,最后 deny all}
所以这一块 403,我能理解:没在白名单里的 IP,本来就不让访问,这块问题不大。
哪吒这边(status.example.com)
哪吒的配置大概这样:
upstream nezha_dashboard {
server 127.0.0.1:8008;keepalive 512;}
server {
listen 443 ssl http2;server_name status.example.com;underscores_in_headers on;include /etc/nginx/conf.d/ipcf.conf;real_ip_header CF-Connecting-IP;real_ip_recursive on;# Agent 用的 gRPClocation ^~ /proto.NezhaService/ { grpc_set_header Host $host; grpc_set_header nz-realip $remote_addr; # 也试过 $http_cf_connecting_ip grpc_pass grpc://nezha_dashboard;}# 网页访问location / { proxy_set_header Host $host; proxy_set_header nz-realip $remote_addr; proxy_pass http://nezha_dashboard;}}
grep -R "ruleip.conf" -n /etc/nginx 只在 /rX9pQe7T/ 这个管理面板用到了,
哪吒这边没有再 include ruleip.conf。
现在奇怪的点
- 只有同机房/某个服务器节点的 IP 能正常访问,
换成家宽 / 其它中国 IP 很容易直接 403。
- 之前 error.log 里出现过这种日志:
access forbidden by rule, request: "POST /proto.NezhaService/ReportSystemInfo2 HTTP/2.0"
- 哪吒进程和端口都是正常的:
ss -tulpn | grep 8008
tcp LISTEN 0 1024000 127.0.0.1:8008 ...
- 家里路由器上跑的哪吒 Agent(国内 IP),连 status.example.com 经常连不上;
同机房的 VPS 用同样的参数连就没问题。
想问大家的是:
- 在 CF → Nginx 这种场景下,ipcf + real_ip_header 这样用是不是有啥坑?
会不会导致 IP 判断有问题,结果只剩一个 IP 能访问,其它都被当成“非法”给 403 掉了?
- gRPC 那里:
grpc_set_header nz-realip $remote_addr;
在已经 real_ip_header CF-Connecting-IP 的前提下,
大家是习惯用 $remote_addr,还是直接 $http_cf_connecting_ip?
- 只在 /rX9pQe7T/ 里用 ruleip.conf 的情况下,
有没有可能还有什么全局配置(geo/map/其它 include)
会影响到 status.example.com 这个域名,导致「只有同机房节点能连,别的 IP 都 403」这种情况?
目前就是卡在这里,有点怀疑自己把 CF + real_ip 这一块搞乱了,
麻烦熟悉 CF + Nginx + 哪吒的大佬帮忙看一眼,感谢
评论 (0)