DiscourseConnect 即使在强制启用 force_https 也会生成 HTTP 重定向

对我来说最简单的方法是在 Discourse 的 app.yml 中设置一个额外的标签,让我的 Traefik 添加一个 X-Forwarded-Proto: https 头部,但随后 nginx 会用它自己的版本覆盖该参数。

而且 Discourse 的 nginx 配置在这里起到了作用:

在这里,Discourse 试图从原始请求(在我的设置中,由于 Traefik 发送的是纯文本,所以总是纯文本)猜测协议。然后用它来设置 X-Forwarded-Proto 多次。

最后,我编辑了我的 containers/app.yml 来硬编码这些头部为 https:

run:
  - exec: echo "Beginning of custom commands"
  ## If you want to set the 'From' email address for your first registration, uncomment and change:
  ## After getting the first signup email, re-comment the line. It only needs to run once.
  # - exec: rails r "SiteSetting.notification_email='no-reply@forum.cabana.network'"
  - replace:
     filename: "/etc/nginx/conf.d/discourse.conf"
     from: /# attempt to preserve the proto, must be in http context\nmap \$http_x_forwarded_proto \$thescheme {\n  default \$scheme;\n  "~https$" https;\n}/\n
     to: |
       # force https scheme so Discourse generates HTTPs links and redirects (ie, `/login`)
  - replace:
     filename: "/etc/nginx/conf.d/discourse.conf"
     from: "$thescheme"
     global: "true"
     to: "https"
  - exec: echo "End of custom commands"

再次,我认为如果有一个 force_https 设置,Discourse-the-rails-app 应该尊重它,而不管反向代理或其他方如何处理。