你好,你可以 登入 weibo, github, 或 注册 成为我们的会员,来为大家分享.

解决 Discourse 套用 CDN 之后无法获取用户真实 IP 的问题 (0)

进入 Discourse 目录

cd /var/discourse

新建一个 template,这里我叫 realip.template.yml

vi templates/realip.template.yml

输入 i,使用 vi 的 insert 模式,为文件加入如下内容:

run:
  - replace:
     filename: "/etc/nginx/conf.d/discourse.conf"
     from: "sendfile on;"
     to: |
      sendfile on;
      set_real_ip_from 0.0.0.0/0;
      real_ip_header X-Forwarded-For;
      real_ip_recursive on;
     global: true

输入 wq 保存,编辑你需要部署的 Discourse 实例的配置文件:

vi containers/app.yml

在 templates 这个部分里加入刚刚创建的 template(示例见最后一行):

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
  - "templates/web.ssl.template.yml"
  - "templates/realip.template.yml"

输入 wq 保存,重新 build 你的 Discourse 实例即可:

./launcher rebuild app

这个功能还有待验证实际的效果,参考了 cloudflare 和 fastly 的 template 模版,总觉得这里使用 set_real_ip_from 0.0.0.0/0; 有点太简单粗暴了。

REF https://discuss.tf.wiki/t/topic/24

分享人 admin @ 2020-04-19 23:19:01

我也说两句:

登录以分享