From 76196348d6d9d7a15c231724aa5f9bc0cfe73f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A6=86=E6=9C=A8?= <43062104+yumusb@users.noreply.github.com> Date: Tue, 3 Dec 2024 03:42:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9C=9F=E5=AE=9EIP=E8=AF=B7=E6=B1=82=E5=A4=B4?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=86=85=E5=AE=B9=20(#114)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加V1反向代理配置 增加V1反向代理配置 * 真实IP请求头相关内容 真实IP请求头相关内容 * Update q2.md * Update q12.md * Update config.mts --------- Co-authored-by: Kris <116849421+cantoblanco@users.noreply.github.com> --- docs/.vitepress/config.mts | 3 ++- docs/guide/q12.md | 40 ++++++++++++++++++++++++++++++++++++++ docs/guide/q2.md | 3 ++- docs/guide/q3.md | 16 ++++++++++++--- 4 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 docs/guide/q12.md diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 26c6fef26..14c09887a 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -189,7 +189,8 @@ function getGuideSidebarZhCN() { { text: '面板数据迁移、备份和恢复', link: '/guide/q5.html' }, { text: '设置每月重置流量统计', link: '/guide/q6.html' }, { text: '自定义 Agent 监控项目', link: '/guide/q7.html' }, - { text: '启用 GPU 监控', link: '/guide/q9.html' } + { text: '启用 GPU 监控', link: '/guide/q9.html' }, + { text: '真实 IP 请求头', link: '/guide/q12.html' } ] }, { diff --git a/docs/guide/q12.md b/docs/guide/q12.md new file mode 100644 index 000000000..3b641cb00 --- /dev/null +++ b/docs/guide/q12.md @@ -0,0 +1,40 @@ +# 真实 IP 请求头 + +由于 V1 版本引入了本地账户机制,为防止外界暴力破解登录接口(Web 应用防火墙功能),程序需要准确获取客户端的真实 IP 地址。 +此功能可通过路径 **`/dashboard/settings/waf`** 进行管理配置。 + +--- + +## 配置场景 + +根据服务部署方式的不同,有以下两种配置场景: + +### 1. 直接将面板服务映射至公网 + +- 勾选 **`使用直连 IP`** 即可,无需额外配置。 + +--- + +### 2. 使用 Web 容器反向代理或 CDN + +- 参考 [反向代理配置](/guide/q3.html) 文档。 +- 在示例配置中,使用了 `nz-realip` 请求头,您可以沿用或修改为其他自定义值。 +- 确保代理服务器正确设置请求头,并将客户端 IP 地址通过自定义头部传递给 Dashboard。 + +--- + +## 常见问题 + +### Q1: 配置错误导致无法访问面板或探针掉线,如何恢复? + +1. 修改面板配置文件: + 文件路径为 `/data/config.yaml`,找到以下配置项: + ```yaml + realipheader: "" + ``` + 将 `realipheader` 设置为空值(`""`),保存并退出。 + +2. 重启面板服务。 + +3. 重新访问面板并验证连接是否恢复正常。 + diff --git a/docs/guide/q2.md b/docs/guide/q2.md index 67c818d8f..ac3193d96 100644 --- a/docs/guide/q2.md +++ b/docs/guide/q2.md @@ -1,3 +1,4 @@ # Agent 启动/上线 问题自检流程 1. `nc -v 域名/IP 通讯端口` 或者 `telnet 域名/IP 通讯端口` 来检验是否是网络问题,检查本机与面板服务器的出入站防火墙,如果无法判断问题可借助 提供的端口检查工具进行检测。 -2. 如果上面步骤检测正常,Agent 依然没有正常上线,请尝试关闭 SELinux,[如何关闭 SELinux?](https://www.google.com/search?q=%E5%85%B3%E9%97%ADSELINUX) \ No newline at end of file +2. 如果上面步骤检测正常,Agent 依然没有正常上线,请尝试关闭 SELinux,[如何关闭 SELinux?](https://www.google.com/search?q=%E5%85%B3%E9%97%ADSELINUX) +3. 使用 `systemctl status nezha-agent-*` 查看 Agent 运行日志,以进一步排查. diff --git a/docs/guide/q3.md b/docs/guide/q3.md index 53e16e622..22a8eb5ea 100644 --- a/docs/guide/q3.md +++ b/docs/guide/q3.md @@ -25,10 +25,13 @@ server { 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; + 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; @@ -40,6 +43,7 @@ server { 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"; @@ -51,6 +55,7 @@ server { 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; @@ -82,6 +87,7 @@ dashboard.example.com { reverse_proxy @grpcProto { header_up Host {host} header_up nz-realip {http.CF-Connecting-IP} # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认 + # header_up nz-realip {remote_host} # 如果你使用caddy作为最外层,就把上面一行注释掉,启用此行 transport http { versions h2c read_buffer 4096 @@ -93,6 +99,7 @@ dashboard.example.com { header_up Host {host} header_up Origin https://{host} header_up nz-realip {http.CF-Connecting-IP} # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认 + # header_up nz-realip {remote_host} # 如果你使用caddy作为最外层,就把上面一行注释掉,启用此行 header_up Upgrade {http.upgrade} header_up Connection "upgrade" transport http { @@ -100,8 +107,11 @@ dashboard.example.com { } to localhost:8008 } -} -``` + upstream dashboard { + server localhost:8008; + keepalive 512; + } + ``` ---