哪吒面板配合CloudFlare隐藏源服务器ip教程

通过cloudflare实现隐藏哪吒面板ip简单教程

参考资料:哪吒面板官方wiki

首先需要准备好docker环境,本教程采用docker完成哪吒面板部署,安装教程可以参考docker官方文档

完成docker安装后,需要配置nginx用于反向代理,直接通过apt源安装即可

sudo apt install nginx -y

完成安装后,在/etc/nginx目录下可以对nginx进行配置,在/etc/nginx/conf.d目录下新建nezha.conf配置文件,根据实际需要参考哪吒面板官方文档配置以下内容,本教材采用CF作为前端,所以只需要修改 server_name dashboard.example.comssl_certificatessl_certificate_key这三项即可,其中域名证书可以直接使用CF申请的源服务器证书

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    # http2 on; # Nginx > 1.25.1,请注释上面两行,启用此行

    server_name dashboard.example.com; # 替换为你的域名
    ssl_certificate          /data/letsencrypt/fullchain.pem; # 域名证书路径
    ssl_certificate_key      /data/letsencrypt/key.pem;       # 域名私钥路径
    ssl_stapling on;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:10m; # 如果与其他配置冲突,请注释此项
    ssl_protocols TLSv1.2 TLSv1.3;

    underscores_in_headers on;
    set_real_ip_from 0.0.0.0/0; # 替换为你的 CDN 回源 IP 地址段
    real_ip_header CF-Connecting-IP; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
    # 如果你使用nginx作为最外层,把上面两行注释掉

    # grpc 相关    
    location ^~ /proto.NezhaService/ {
        grpc_set_header Host $host;
        grpc_set_header nz-realip $http_CF_Connecting_IP; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
        # grpc_set_header nz-realip $remote_addr; # 如果你使用nginx作为最外层,就把上面一行注释掉,启用此行
        grpc_read_timeout 600s;
        grpc_send_timeout 600s;
        grpc_socket_keepalive on;
        client_max_body_size 10m;
        grpc_buffer_size 4m;
        grpc_pass grpc://dashboard;
    }
    # websocket 相关
    location ~* ^/api/v1/ws/(server|terminal|file)(.*)$ {
        proxy_set_header Host $host;
        proxy_set_header nz-realip $http_cf_connecting_ip; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
        # proxy_set_header nz-realip $remote_addr; # 如果你使用nginx作为最外层,就把上面一行注释掉,启用此行
        proxy_set_header Origin https://$host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 3600s;
        proxy_send_timeout 3600s;
        proxy_pass http://127.0.0.1:8008;
    }
    # web
    location / {
        proxy_set_header Host $host;
        proxy_set_header nz-realip $http_cf_connecting_ip; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
        # proxy_set_header nz-realip $remote_addr; # 如果你使用nginx作为最外层,就把上面一行注释掉,启用此行
        proxy_read_timeout 3600s;
        proxy_send_timeout 3600s;
        proxy_buffer_size 128k;
        proxy_buffers 4 256k;
        proxy_busy_buffers_size 256k;
        proxy_max_temp_file_size 0;
        # proxy_set_header X-Forwarded-Proto $scheme; # 如果你使用nginx作为最外层,就启用此行避免无法正确读取访问的协议
        proxy_pass http://127.0.0.1:8008;
    }
}

upstream dashboard {
    server 127.0.0.1:8008;
    keepalive 512;
}

完成配置后,重载nginx配置文件

sudo systemctl reload nginx.service

下一步,通过官方提供的一键脚本部署哪吒面板

#通过官方提供的一键脚本进行部署
curl -L https://raw.githubusercontent.com/nezhahq/scripts/refs/heads/main/install.sh -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh

选择第一项

按提示输入以下信息:

  • 请输入站点标题: - 自定义站点标题。

  • 请输入暴露端口: - 公开访问端口,选择443端口(例如demo.com:443)。

  • 请指定后台语言: - 选择语言偏好。

完成安装后,在CF控制台-网络页面中启用gRPC和WebSockets支持

最后,通过域名直接访问即可进入面板进行配置(别忘了开启域名后面的黄色云朵),默认账号密码均为admin

可能会遇到的问题:

如果设置有WAF,可能会被CF拦截质询,导致面板机无法接收被控机agent回传的信息,建议关闭WAF或自行检查策略组。

LICENSED UNDER CC BY-NC-SA 4.0
Comment