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

Ruby on Rails部署至Railway报错:页面异常但日志无有效信息

Rails部署到Railway后显示"Something went wrong",是否由Rack::Handler弃用导致?

问题现象

  • 访问部署URL时页面提示:

We're sorry, but something went wrong.
If you are the application owner check the logs for more information.

  • 应用启动日志内容:
Rack::Handler is deprecated and replaced by Rackup::Handler
=> Booting Puma
=> Rails 7.1.3.4 application starting in production
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 6.0.2 (ruby 3.2.2-p53) ("Sunflower")
*  Min threads: 5
*  Max threads: 5
*  Environment: production
*          PID: 7
* Listening on http://0.0.0.0:7256
Use Ctrl-C to stop

疑问

应用运行异常是否真的由Rack::Handler弃用问题导致?

配置信息

环境变量设置

环境变量设置

production.rb配置代码

require "active_support/core_ext/integer/time"

Rails.application.configure do
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local = false
  config.action_controller.perform_caching = true
  config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
  config.assets.compile = false
  config.active_storage.service = :local
  config.log_level = :info
  config.log_tags = [:request_id]
  config.action_mailer.perform_caching = false
  config.i18n.fallbacks = true
  config.active_support.report_deprecations = false
  config.log_formatter = ::Logger::Formatter.new

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger = ActiveSupport::TaggedLogging.new(logger)
  end

  config.active_record.dump_schema_after_migration = false

  config.action_mailer.delivery_method = :smtp
  ActionMailer::Base.smtp_settings = {
    user_name: "apikey",
    password: ENV['SENDGRID_API_KEY'],
    domain: "XXXXXXX-production.up.railway.app",
    address: "smtp.sendgrid.net",
    port: 587,
    authentication: :plain,
    enable_starttls_auto: true
  }
  config.action_mailer.default_url_options = { host: 'XXXXXXX-production.up.railway.app', protocol: 'https' }

  config.action_mailer.perform_deliveries = true
  config.hosts << "XXXXXXX-production.up.railway.app"
end

解答

Rack::Handler的弃用警告不会导致应用崩溃,这只是一条兼容性提示,并非错误。从日志看Puma已正常启动并监听端口,服务本身启动流程无异常,页面500错误由其他原因导致,建议按以下步骤排查:

  • 开启详细错误日志:临时修改production.rb,设置config.consider_all_requests_local = true和config.log_level = :debug,重新部署后访问页面,即可看到具体错误堆栈,这是定位问题最直接的方式。
  • 检查数据库连接:确认Railway环境中DATABASE_URL变量配置正确,Rails生产环境首次请求会尝试连接数据库,连接失败是引发500错误的常见原因。
  • 验证静态文件服务:确认RAILS_SERVE_STATIC_FILES环境变量已设为true,否则静态文件访问失败可能引发错误。
  • 确认资产预编译状态:因config.assets.compile = false,需确保部署前已执行rails assets:precompile命令,未预编译资产可能导致页面资源加载失败。
  • 核对主机白名单:确认config.hosts添加的域名与实际访问的部署URL完全一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 21:03:28