将站点移至代理后,favicon 和 header 不再使用 https

I’ve since moved my Discourse instance between servers, and is now running behind a reverse proxy with SSL termination.

However, the header image and favicon are not being requested over HTTPS and getting blocked. I tried setting “force https” to on, but this hasn’t helped.

1 个赞

Is your proxy supplying an X-Forwarded-Proto header? (It should).

3 个赞

Is your proxy supplying an X-Forwarded-Proto header? (It should).

Yes it is.

1 个赞

I had the same issue. I have a Discourse instance behind HAProxy with SSL termination. The fix is pretty simple, but not obvious:

  1. First make sure that “force https” is enabled in the settings (go to Settings and filter by “force https”).
  2. Go to Settings > Branding > and just re-upload your logos.
  3. Everything should use HTTPS now (be sure to hit your browser refresh button).

(I think this may be a bug in Discourse)

3 个赞

您好,
我想再次讨论这个问题。实际上,我遇到了同样的问题,由于无法登录(登录时出现未知错误),我无法将 force_https 设置为 true。
我们该如何强制以 HTTPS 请求引用 logo,而不是 HTTP?
这难道不应该很简单吗?
非常感谢您的反馈(我这边已经花费了非常多的时间来修复此问题)。

您需要通过 SSH 登录服务器并进入 Ruby 命令行,翻转 force_https 站点设置。有关操作方法的指南主题可在此处查看。

感谢您的回复。我之前的消息确实表述不清。实际上,我可以通过 Rails 命令成功修改 force_https 设置,这没有问题。所以,为了更清楚地说明:

在我几天前执行的上一次升级(需要重建 Docker 容器)之前,我拥有一个完全正常的解决方案:将 force_https 设置为 true,并在 nginx 配置文件的 server 部分应用以下补丁,即可实现正常登录:

  if ($http_x_forwarded_proto = 'http'){
    return 301 https://$host$request_uri;
  }

该方案当时运行正常。然而,升级之后,同样的补丁已无法让我再次登录,系统返回了众所周知的“未知错误”(Unknown error)。

我从生产日志中获得了以下追踪信息:

 Started POST "/session" for 193.134.222.4 at 2020-05-14 19:24:40 +0000
 Processing by SessionController#create as */*
 Parameters: {"login"=>"rossierd", "password"=>"[FILTERED]", "second_factor_method"=>"1", "timezone"=>"Europe/Zurich"}
 Can't verify CSRF token authenticity.
 Rendering text template
 Rendered text template (Duration: 0.0ms | Allocations: 1)
 Filter chain halted as :verify_authenticity_token rendered or redirected
 Completed 403 Forbidden in 2ms (Views: 0.7ms | ActiveRecord: 0.0ms | Allocations: 1101)

需要说明的是,我们的 Discourse 容器运行在一台可通过 HTTPS 访问的虚拟机中。

您是否对升级前后行为变化的原因有任何想法?

目前,我已将 force_https 设置为 false,系统运行基本正常,只是左上角的标志(品牌 Logo)无法正确显示,因为它仍通过 http:// 请求引用。

顺便一提,我们网站的 URL 是:https://discourse.heig-vd.ch

此外,我还发现了以下站点设置中包含该可疑 URL:
SiteSetting.site_favicon_url(另一个是 SiteSetting.site_apple_touch_icon),其值为 “http://…jpeg”。
然而,似乎不像对 force_https 那样,可以通过一个简单的 Rails 命令来轻松修改该值。

请问,关于这个话题有人能帮忙吗?

这些是通过设置向导设置的。请重新运行设置向导并重新上传图片。

1 个赞

我就是这样设置图片的。我重新启动了向导,但结果还是一样::pensive_face:
我觉得上传图片不会影响它们的引用方式;这更多是与网页生成相关的问题。

好吧,在经历了多次不成功的尝试后,我终于找到了在 force_https=true 的情况下实现有效登录的方法。

在 Docker 环境中,我对 /etc/nginx/conf.d/discourse.conf 进行了如下修补:


location @discourse {
limit_conn connperip 20;
limit_req zone=flood burst=12 nodelay;
limit_req zone=bot burst=100 nodelay;
proxy_set_header Host $http_host;
proxy_set_header X-Request-Start “t=${msec}”;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https; # $thescheme; ← 我修改的地方
proxy_pass http://discourse;
}

至少在我的环境中,只有在这一部分生效。

现在运行得非常顺利!

1 个赞