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

Capistrano部署Rails应用后缺失production.log问题求助

Troubleshooting Missing Production.log & 500 Error in Rails Deployment

Hey there, let's work through this problem together. That generic "We're sorry but something went wrong" message is frustrating, especially when you don't have a production.log to tell you what's actually broken. Let's break down the most likely fixes step by step:

1. Verify Your Production Log Configuration

First, let's check your config/production.rb to make sure Rails is set up to write to a production log file. Look for these key settings:

Rails.application.configure do
  # Make sure log level isn't disabled or set to an invalid value
  config.log_level = :info # Valid options: :debug, :info, :warn, :error, :fatal, :unknown

  # Ensure Rails is configured to write to the production.log file
  config.logger = ActiveSupport::Logger.new(Rails.root.join('log', 'production.log'))
  config.logger.formatter = ::Logger::Formatter.new

  # Critical for production: make sure eager loading is enabled (this catches load-time errors)
  config.eager_load = true

  # ... rest of your config
end

If any of these lines are missing or commented out, add/uncomment them, redeploy, and check if the log file appears.

2. Fix Log Directory Permissions

Rails needs write access to the log directories to create and update production.log. Log into your server and run these commands to check and correct permissions:

# Check ownership and permissions of your log directories
ls -ld myapp/current/log myapp/shared/log
ls -l myapp/current/log

# If the directories are owned by the wrong user (e.g., root instead of your deploy user), fix it
# Replace "deploy" with your actual Rails process user (could be www-data, ubuntu, etc.)
chown -R deploy:deploy myapp/shared/log myapp/current/log

# Ensure the directories have proper write permissions
chmod -R 755 myapp/shared/log myapp/current/log

If you're using Capistrano or a similar deployment tool, make sure it's linking the shared/log directory to current/log so logs persist across deployments. In your deploy.rb, look for this line:

append :linked_dirs, 'log'

If it's missing, add it, redeploy, and the shared/log directory will be linked to your current deployment's log folder—this ensures permissions stay consistent and logs don't get wiped on each deploy.

4. Check System & Web Server Logs

If Rails still isn't generating production.log, the error might be getting logged elsewhere. Check these places:

  • Web Server Logs: For Nginx, look at /var/log/nginx/error.log; for Apache, check /var/log/apache2/error.log. These often catch errors like failed proxy passes to your Rails server (Puma/Unicorn).
  • System Logs: On Ubuntu/Debian, check /var/log/syslog; on CentOS/RHEL, look at /var/log/messages. These might show Rails process crashes or missing dependencies.

Run this to tail the Nginx error log in real-time while you reload the problematic page:

tail -f /var/log/nginx/error.log

5. Test the Production Rails Console

One of the quickest ways to catch load-time errors is to fire up the production Rails console. From your server:

cd myapp/current
RAILS_ENV=production rails c

If there's an issue (like a missing gem, invalid database config, or missing environment variable), the console will throw an error immediately—this is often the fastest way to pinpoint the root cause.

6. Validate Production Environment Variables

Rails production relies on critical environment variables like SECRET_KEY_BASE and database credentials. If these are missing or incorrect, Rails might fail silently (without writing to logs). Check if they're set:

# Check for SECRET_KEY_BASE
echo $SECRET_KEY_BASE

# If using a dotenv file, verify it's loaded in production (make sure gem 'dotenv-rails' is in the production group)
cat myapp/current/.env.production

Once you fix the underlying issue (whether it's permissions, config, or missing variables), your production.log should start generating, and you'll be able to debug that 500 error properly.


内容的提问来源于stack exchange,提问作者Léo Coletta

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:50:10