我在Rails应用中使用Paperclip来处理图片上传。但是,出于某种原因,每次我尝试创建具有附加图像的模型实例时,我都会收到Rails 500错误。
奇怪的是,重新启动应用程序(通过Upstart)然后重新提交表单允许我成功上传图片,但它似乎并没有"采取":任何后续上传仍然给我一个500错误。
生产日志无益,甚至无法显示创建实例的POST请求。
我的Upstart配置文件:
description 'site.com'
author 'Daniel J. <>'
start on [2345]
stop on runlevel [016]
env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
env RAILS_ENV=production
env SECRET_KEY_BASE=''
env DEVISE_SECRET_KEY=''
env POSTGRESQL_PASSWORD=''
setuid www-data
setgid www-data
chdir /var/www/site/current
pre-start exec bundle exec unicorn_rails -D -c /var/www/site/current/config/unicorn.rb --env production
post-stop exec kill `cat /var/www/site/current/tmp/pids/unicorn.pid`
我的nginx文件:
upstream app {
server 127.0.0.1:3000;
}
server {
listen 80 default;
server_name site.com;
charset utf-8;
client_max_body_size 75M;
root /var/www/site/current/public;
location ~ ^/(assets)/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location / {
try_files $uri/index.html $uri @app;
error_page 404 /404.html;
error_page 403 /403.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
}
location = /favicon.ico {
expires max;
add_header Cache-Control public;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
}
我的Unicorn配置文件:
listen 3000
worker_processes Integer(ENV['WEB_CONCURRENCY'] || 3)
timeout 30
preload_app true
working_directory '/var/www/site/current'
stderr_path 'log/unicorn-error.log'
stdout_path 'log/unicorn-access.log'
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT.'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
答案 0 :(得分:0)
我发现盒子里的内存不足就是这么做的。一旦我添加了交换文件(使用此处的说明:https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04),我就能够成功上传文件。