You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails7升级后Passenger+Devise出现Premature end of script headers错误

Rails 6.1升级到7后Devise认证页面异常的排查记录

问题现象

把Rails从6.1版本升级到7后,未受Devise认证控制的页面运行正常,但用户被重定向到认证页面或直接访问该页面时,会触发错误。

相关日志信息

Apache日志

[Wed Mar 22 15:29:36.670330 2023] [core:error] [pid 95707] [client 127.0.0.1:52600] Premature end of script headers: users
[Wed Mar 22 16:20:31.688989 2023] [core:error] [pid 95708] [client 127.0.0.1:65362] Premature end of script headers: users

Rails日志

Started GET "/users" for 127.0.0.1 at 2023-03-22 16:23:32 -0700
Processing by Lux::UsersController#index as HTML
Completed 401 Unauthorized in 11ms (Allocations: 2857)


Started GET "/users/sign_in" for 127.0.0.1 at 2023-03-22 16:23:32 -0700
Processing by Lux::SessionsController#new as HTML
  Rendering layout layouts/user.html.erb
  Rendering devise/sessions/new.html.erb within layouts/user
  Rendered devise/sessions/new.html.erb within layouts/user (Duration: 6.2ms | Allocations: 1492)
  Rendered layout layouts/user.html.erb (Duration: 625.5ms | Allocations: 555283)
Completed 200 OK in 631ms (Views: 626.4ms | Allocations: 558289)

相关代码

Lux::SessionsController实现代码:

class Lux::SessionsController < ::Devise::SessionsController
end

初步排查

从日志输出看应用运行流程正常,单元测试和集成测试也无异常,初步推测问题与Passenger相关。

问题定位与解决

更新1:临时回退配置版本

将config.load_defaults 7.0修改为config.load_defaults 5.1后,问题暂时解决。

更新2:定位具体触发配置项

最终定位到new_framework_defaults_6_1.rb中的以下配置:

# Generate a `Link` header that gives a hint to modern browsers about
# preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`.
# Rails.application.config.action_view.preload_links_header = true

当该设置被设为true或取消注释时,会触发模糊错误;设为false或保持注释状态时,应用运行恢复正常。


内容的提问来源于stack exchange,提问作者Romuloux

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 08:42:21