pfaffman
(Jay Pfaffman)
2023 年3 月 7 日 14:27
1
我有一个相当典型的子文件夹/反向代理设置,其中 Apache 作为反向代理。
起初存在不安全资源的问题,所以我强制在 ENV 中使用 force_https。现在,在检索类似 stylesheets/color_definitions_light_7_1_6cfae4de9c47a1b8ed3d5748018236d10ea9107e.css?__ws=site.com 的资源时
也许我做错了什么,但我得到了这个:
ArgumentError (comparison of Time with String failed)
app/controllers/stylesheets_controller.rb:66:in `<='
app/controllers/stylesheets_controller.rb:66:in `show_resource'
app/controllers/stylesheets_controller.rb:19:in `show'
app/controllers/application_controller.rb:414:in `block in with_resolved_locale'
app/controllers/application_controller.rb:414:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:74:in `call'
lib/middleware/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:369:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/request_tracker.rb:228:in `call'
1 个赞
pfaffman
(Jay Pfaffman)
2023 年3 月 7 日 14:40
2
嗯,看看
end
# Security note, safe due to route constraint
underscore_digest = digest ? "_" + digest : ""
cache_path = Stylesheet::Manager.cache_fullpath
location = "#{cache_path}/#{target}#{underscore_digest}#{extension}"
stylesheet_time = query.pick(:created_at)
handle_missing_cache(location, target, digest) if !stylesheet_time
if cache_time.present? && stylesheet_time && stylesheet_time <= cache_time
return head :not_modified
end
unless File.exist?(location)
if current = query.pick(source_map ? :source_map : :content)
FileUtils.mkdir_p(cache_path)
Discourse::Utils.atomic_write_file(location, current)
else
看起来 stylesheet_time 是一个字符串,所以将该行更改为
if cache_time && stylesheet_time && stylesheet_time.to_date <= cache_time
可以解决问题。我不明白现在是怎么发生的,因为我没有看到任何最近影响此问题的提交。
所以这是它的设置方式:
stylesheet_time = query.pick(:created_at)
看起来 :created_at 应该是一个合适的日期。会不会是某个底层 gem 发生了变化?这又是如何没有在测试中被发现的?
1 个赞
pfaffman
(Jay Pfaffman)
2023 年3 月 7 日 15:04
3
这似乎解决了问题:
if !cache_time.to_date.nil? && !stylesheet_time.to_date.nil?
if (stylesheet_time.to_date <= cache_time.to_date)
return render body: nil, status: 304
end
end
看起来 to_date 有可能将真值转换为 nil 日期。
不。那也行不通。我最后用 begin/rescue/end 包裹了该部分。
我非常困惑这怎么只会影响这个子文件夹/反向代理站点。
也许这与
cache_time = request.env["HTTP_IF_MODIFIED_SINCE"]
有关,也许 Apache 没有传递它,或者传入了一个无效的日期字符串。
以前那里有一个 rescue nil,但那已经是 5 年前的事了。
而且我认为这很难调试,因为它是一个缓存,所以要调试我需要刷新缓存来测试它是否工作。
1 个赞
我遇到了同样的问题(在使用子文件夹设置时也遇到了)。在通过将 force_https 设置为 true 来修复一个无关的混合内容警告后,问题就消失了……
2 个赞
pfaffman
(Jay Pfaffman)
2023 年3 月 24 日 15:59
5
糟糕。我希望这能帮到我,但我已经在 yml 中设置了 DISCOURSE_FORCE_HTTPS: true。
现在我更困惑了,为什么只有这个站点有问题。
我已经在管理员界面 中更改了“强制 https”设置,但这可能与您说的是同一件事。
1 个赞
Jay Pfaffman:
也许那不是从Apache传递过来的
您好!
我遇到了完全相同的问题,使用的是 NGINX 而不是 Apache 作为反向代理。
您找到解决方案了吗?
顺便说一句,这只在桌面版本上失败了,移动版本没有任何问题。
我通过禁用反向代理上的缓冲来绕过它。
1 个赞
@pfaffman 我只是从 3.1.0.beta3 降级到 3.1.0.beta2,一切都很顺利,现在工作正常。
我对 Discourse 的经验不足,无法检查出问题所在或提交 bug,尤其是在一个不受支持的安装上。
但如果我能帮上忙,我很乐意!