CloudFlare 和 真实IP

我一直在尝试让 Discourse 显示真实 IP 地址,但效果不佳。我已经将 cloudflare yml 添加到我的设置中,并验证了容器中的 discourse.conf 包含正确的行:

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;
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 2a06:98c0::/29;
set_real_ip_from 2c0f:f248::/32;
real_ip_header CF-Connecting-IP;

我还验证了日志中的 $http_cf_connecting_ip 具有正确的 IP,但出于某种原因 $remote_addr 未正确设置。有人遇到过这个问题吗?

也许可以使用 Cloudflare 模板?

  - "templates/cloudflare.template.yml"

添加到您的 app.yml 中,与其他模板放在一起。

1 个赞

感谢您的回复!我正在使用 Cloudflare 模板。经过进一步排查,发现它不起作用是因为进入 Nginx 的所有 remote_addr 都是 Docker 地址。我正在尝试诊断原因。

您是否也使用了本地反向代理服务器?如果是,您需要将该地址添加到您的 set_real_ip 配置中(也许反向代理会处理 Cloudflare 的相关事宜?)

我并非有意运行反向代理,但在我的 app.yml 中指定了用于公开端口的特定 IP 地址。

expose:
  - "xxx.xxx.xxx.xxx:80:80"    # http
  - "xxx.xxx.xxx.xxx:443:443"  # https

我不知道。也许你需要包含一些 Docker IP?

Discourse 显示的 IP 是 Docker IP 吗?

2 个赞

您是否遵循了标准安装流程?使用模板通常可以开箱即用。

2 个赞

感谢你们两位的帮助!结果发现我们 VPS 上的 Immunify360 将自己作为代理注入到容器之前。将 Docker IP 添加到 set_real_ip_from 暂时解决了这个问题,同时我将着手禁用 Immunify。

1 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.