Ruby on rails 升级ruby/rails并从mongrel移动到unicorn时的路由
我有一个升级ruby-1.8.7-p72/rails 2.3.2/mongrel应用程序的项目。我要做的第一步是升级到ruby-1.9.3-p484、rails 2.3.18和unicorn 我现在已经能够通过unicorn(通过capistrano-rvm capistrano和capistrano unicorn部署)在开发服务器上运行应用程序了。但是,它无法提供任何资产(图像、样式表等) 我在unicorn日志中看到如下错误:Ruby on rails 升级ruby/rails并从mongrel移动到unicorn时的路由,ruby-on-rails,unicorn,mongrel,Ruby On Rails,Unicorn,Mongrel,我有一个升级ruby-1.8.7-p72/rails 2.3.2/mongrel应用程序的项目。我要做的第一步是升级到ruby-1.9.3-p484、rails 2.3.18和unicorn 我现在已经能够通过unicorn(通过capistrano-rvm capistrano和capistrano unicorn部署)在开发服务器上运行应用程序了。但是,它无法提供任何资产(图像、样式表等) 我在unicorn日志中看到如下错误: ActionController::RoutingError
ActionController::RoutingError (No route matches "/images/pp.jpg" with {:method=>:get}):
<internal:prelude>:10:in `synchronize'
unicorn (4.8.2) lib/unicorn/http_server.rb:572:in `process_client'
unicorn (4.8.2) lib/unicorn/http_server.rb:666:in `worker_loop'
unicorn (4.8.2) lib/unicorn/http_server.rb:521:in `spawn_missing_workers'
unicorn (4.8.2) lib/unicorn/http_server.rb:140:in `start'
unicorn (4.8.2) bin/unicorn_rails:209:in `<top (required)>'
/Users/ruby/.rvm/gems/ruby-1.9.3-p484/bin/unicorn_rails:19:in `load'
/Users/ruby/.rvm/gems/ruby-1.9.3-p484/bin/unicorn_rails:19:in `<main>'
/Users/ruby/.rvm/gems/ruby-1.9.3-p484/bin/ruby_executable_hooks:15:in `eval'
/Users/ruby/.rvm/gems/ruby-1.9.3-p484/bin/ruby_executable_hooks:15:in `<main>'
ActionController::RoutingError(没有与“/images/pp.jpg”匹配的路由,带有{:method=>:get}):
:10:在“同步”中
unicorn(4.8.2)lib/unicorn/http_server.rb:572:in'process_client'
unicorn(4.8.2)lib/unicorn/http_server.rb:666:in'worker_loop'
unicorn(4.8.2)lib/unicorn/http_server.rb:521:in'spawn_missing_workers'
unicorn(4.8.2)lib/unicorn/http_server.rb:140:in'start'
独角兽(4.8.2)箱子/独角兽轨道:209:in`'
/Users/ruby/.rvm/gems/ruby-1.9.3-p484/bin/unicorn\u rails:19:in'load'
/Users/ruby/.rvm/gems/ruby-1.9.3-p484/bin/unicorn\u rails:19:in`'
/Users/ruby/.rvm/gems/ruby-1.9.3-p484/bin/ruby\u executable\u hooks:15:in'eval'
/Users/ruby/.rvm/gems/ruby-1.9.3-p484/bin/ruby\u executable\u hooks:15:in`'
无论是直接与unicorn端口通信还是通过apache(mod_rewrite-与unicorn端口通信),我都会看到同样的错误
我是否需要更改资产的位置?目前,它们处于公开状态。它们在ruby-1.8.7-p72/rails 2.3.2/mongrel下运行良好,但在ruby-1.9.3-p484/rails 2.3.18/unicorn下不起作用。或者我是否可以在cap文件中放置一个配置项来设置资产的位置?我在独角兽文件里什么也没找到
还有谁知道答案?我将继续努力,但任何提示都将不胜感激。我终于让它起作用了。。。。多痛苦啊。我很高兴我只需要做一次。事实上,我只在我的开发服务器上运行它。我认为在我转到rails 3之前,不可能在我的开发计算机上使用unicorn,因为缺少serve_static_assets配置值 我的unicorn配置文件如下所示:
# config/unicorn/development-mini-2.rb
#
# this is launched from capistrano. see config/deploy/dev2.rb.
#
puts "reading development-mini-2.rb"
rails_env = ENV['RAILS_ENV'] || 'development'
timeout 30
worker_processes 4
listen 8031
root = '/Users/ruby/apps/app'
working_directory "#{root}/current"
pid "#{root}/shared/pids/unicorn.app.pid"
stderr_path "#{root}/shared/log/unicorn.log"
stdout_path "#{root}/shared/log/unicorn.log"
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
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
#
# deployment for the dev mini server instance 2
# app.example.com
# deploy with
#
#
require 'rvm/capistrano'
set :application, "app"
set :rvm_ruby_string, 'ruby-1.9.3-p484'
set :rails_env, 'development'
server 'app.example.com', :app, :web, :db, :primary => true
set :user, "ruby"
set :group, "ruby"
set :deploy_to, "/Users/ruby/apps/#{application}"
set :copy_remote_dir, '/Users/ruby/tmp'
namespace :deploy do
desc "Start unicorn"
task :start, :except => { :no_release => true } do
run "cd #{deploy_to}/current ; unicorn_rails -c config/unicorn/development-mini-2.rb -D"
run "ps aux | grep unicorn_rails | head -n 1 | awk '{print $2}' > #{deploy_to}/shared/pids/unicorn.app.pid"
end
desc "Stop unicorn"
task :stop, :except => { :no_release => true } do
run "kill -s QUIT `cat #{deploy_to}/shared/pids/unicorn.app.pid`"
end
desc "Restart Unicorn"
task :restart, :except => { :no_release => true } do
run "kill -s USR2 `cat #{deploy_to}/shared/pids/unicorn.app.pid`"
end
end
<VirtualHost *:443>
ServerName app.example.com
DocumentRoot /Users/ruby/apps/app/current/public
RewriteEngine On
#RewriteLog "/var/log/apache2/rewrite.log"
#RewriteLogLevel 3
<Proxy "balancer://unicornservers2">
Order deny,allow
Allow from any
BalancerMember http://localhost:8031
</Proxy>
# Redirect all non-static requests to unicorn
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers2%{REQUEST_URI} [P,QSA,L]
RequestHeader set X-Forwarded-Proto "https"
CustomLog /var/log/apache2/access_log "%h %l %u %t \"%r\" %>s %b"
<IfModule mod_ssl.c>
SSLEngine On
SSLCipherSuite "ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM"
SSLProtocol -ALL +SSLv3 +TLSv1
SSLCertificateFile "/etc/certificates/example.com.0CB3DB818A24F638D4D4A5664865B68ACB924FF1.cert.pem"
SSLCertificateKeyFile "/etc/certificates/example.com.0CB3DB818A24F638D4D4A5664865B68ACB924FF1.key.pem"
SSLCertificateChainFile "/etc/certificates/example.com.0CB3DB818A24F638D4D4A5664865B68ACB924FF1.chain.pem"
SSLProxyProtocol -ALL +SSLv3 +TLSv1
</IfModule>
</VirtualHost>
我的cap部署看起来像:
# config/unicorn/development-mini-2.rb
#
# this is launched from capistrano. see config/deploy/dev2.rb.
#
puts "reading development-mini-2.rb"
rails_env = ENV['RAILS_ENV'] || 'development'
timeout 30
worker_processes 4
listen 8031
root = '/Users/ruby/apps/app'
working_directory "#{root}/current"
pid "#{root}/shared/pids/unicorn.app.pid"
stderr_path "#{root}/shared/log/unicorn.log"
stdout_path "#{root}/shared/log/unicorn.log"
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
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
#
# deployment for the dev mini server instance 2
# app.example.com
# deploy with
#
#
require 'rvm/capistrano'
set :application, "app"
set :rvm_ruby_string, 'ruby-1.9.3-p484'
set :rails_env, 'development'
server 'app.example.com', :app, :web, :db, :primary => true
set :user, "ruby"
set :group, "ruby"
set :deploy_to, "/Users/ruby/apps/#{application}"
set :copy_remote_dir, '/Users/ruby/tmp'
namespace :deploy do
desc "Start unicorn"
task :start, :except => { :no_release => true } do
run "cd #{deploy_to}/current ; unicorn_rails -c config/unicorn/development-mini-2.rb -D"
run "ps aux | grep unicorn_rails | head -n 1 | awk '{print $2}' > #{deploy_to}/shared/pids/unicorn.app.pid"
end
desc "Stop unicorn"
task :stop, :except => { :no_release => true } do
run "kill -s QUIT `cat #{deploy_to}/shared/pids/unicorn.app.pid`"
end
desc "Restart Unicorn"
task :restart, :except => { :no_release => true } do
run "kill -s USR2 `cat #{deploy_to}/shared/pids/unicorn.app.pid`"
end
end
<VirtualHost *:443>
ServerName app.example.com
DocumentRoot /Users/ruby/apps/app/current/public
RewriteEngine On
#RewriteLog "/var/log/apache2/rewrite.log"
#RewriteLogLevel 3
<Proxy "balancer://unicornservers2">
Order deny,allow
Allow from any
BalancerMember http://localhost:8031
</Proxy>
# Redirect all non-static requests to unicorn
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers2%{REQUEST_URI} [P,QSA,L]
RequestHeader set X-Forwarded-Proto "https"
CustomLog /var/log/apache2/access_log "%h %l %u %t \"%r\" %>s %b"
<IfModule mod_ssl.c>
SSLEngine On
SSLCipherSuite "ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM"
SSLProtocol -ALL +SSLv3 +TLSv1
SSLCertificateFile "/etc/certificates/example.com.0CB3DB818A24F638D4D4A5664865B68ACB924FF1.cert.pem"
SSLCertificateKeyFile "/etc/certificates/example.com.0CB3DB818A24F638D4D4A5664865B68ACB924FF1.key.pem"
SSLCertificateChainFile "/etc/certificates/example.com.0CB3DB818A24F638D4D4A5664865B68ACB924FF1.chain.pem"
SSLProxyProtocol -ALL +SSLv3 +TLSv1
</IfModule>
</VirtualHost>
我的apache配置看起来像:
# config/unicorn/development-mini-2.rb
#
# this is launched from capistrano. see config/deploy/dev2.rb.
#
puts "reading development-mini-2.rb"
rails_env = ENV['RAILS_ENV'] || 'development'
timeout 30
worker_processes 4
listen 8031
root = '/Users/ruby/apps/app'
working_directory "#{root}/current"
pid "#{root}/shared/pids/unicorn.app.pid"
stderr_path "#{root}/shared/log/unicorn.log"
stdout_path "#{root}/shared/log/unicorn.log"
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
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
#
# deployment for the dev mini server instance 2
# app.example.com
# deploy with
#
#
require 'rvm/capistrano'
set :application, "app"
set :rvm_ruby_string, 'ruby-1.9.3-p484'
set :rails_env, 'development'
server 'app.example.com', :app, :web, :db, :primary => true
set :user, "ruby"
set :group, "ruby"
set :deploy_to, "/Users/ruby/apps/#{application}"
set :copy_remote_dir, '/Users/ruby/tmp'
namespace :deploy do
desc "Start unicorn"
task :start, :except => { :no_release => true } do
run "cd #{deploy_to}/current ; unicorn_rails -c config/unicorn/development-mini-2.rb -D"
run "ps aux | grep unicorn_rails | head -n 1 | awk '{print $2}' > #{deploy_to}/shared/pids/unicorn.app.pid"
end
desc "Stop unicorn"
task :stop, :except => { :no_release => true } do
run "kill -s QUIT `cat #{deploy_to}/shared/pids/unicorn.app.pid`"
end
desc "Restart Unicorn"
task :restart, :except => { :no_release => true } do
run "kill -s USR2 `cat #{deploy_to}/shared/pids/unicorn.app.pid`"
end
end
<VirtualHost *:443>
ServerName app.example.com
DocumentRoot /Users/ruby/apps/app/current/public
RewriteEngine On
#RewriteLog "/var/log/apache2/rewrite.log"
#RewriteLogLevel 3
<Proxy "balancer://unicornservers2">
Order deny,allow
Allow from any
BalancerMember http://localhost:8031
</Proxy>
# Redirect all non-static requests to unicorn
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers2%{REQUEST_URI} [P,QSA,L]
RequestHeader set X-Forwarded-Proto "https"
CustomLog /var/log/apache2/access_log "%h %l %u %t \"%r\" %>s %b"
<IfModule mod_ssl.c>
SSLEngine On
SSLCipherSuite "ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM"
SSLProtocol -ALL +SSLv3 +TLSv1
SSLCertificateFile "/etc/certificates/example.com.0CB3DB818A24F638D4D4A5664865B68ACB924FF1.cert.pem"
SSLCertificateKeyFile "/etc/certificates/example.com.0CB3DB818A24F638D4D4A5664865B68ACB924FF1.key.pem"
SSLCertificateChainFile "/etc/certificates/example.com.0CB3DB818A24F638D4D4A5664865B68ACB924FF1.chain.pem"
SSLProxyProtocol -ALL +SSLv3 +TLSv1
</IfModule>
</VirtualHost>
ServerName app.example.com
DocumentRoot/Users/ruby/apps/app/current/public
重新启动发动机
#RewriteLog“/var/log/apache2/rewrite.log”
#重写日志级别3
命令拒绝,允许
允许任何
平衡员http://localhost:8031
#将所有非静态请求重定向到unicorn
重写cond%{DOCUMENT\u ROOT}/%{REQUEST\u FILENAME}-F
重写规则^/(.*)$balancer://unicornservers2%{REQUEST_URI}[P,QSA,L]
RequestHeader集合X-Forwarded-Proto“https”
自定义日志/var/log/apache2/access_日志“%h%l%u%t\%r\”%>s%b
斯伦金安
SSLCipherSuite“全部:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:!所有:
SSLProtocol-全部+SSLv3+TLSv1
SSLCertificateFile“/etc/certificates/example.com.0cb3db818a24f638d4d4a566465b68acb924ff1.cert.pem”
SSLCertificateKeyFile“/etc/certificates/example.com.0cb3db818a24f638d4d4a566465b68acb924ff1.key.pem”
SSLCertificateChainFile“/etc/certificates/example.com.0cb3db818a24f638d4d4a566465b68acb924ff1.chain.pem”
SSLProxyProtocol-全部+SSLv3+TLSv1
我认为这是因为我的实例没有以开发模式启动,所以它试图通过apache为资产提供服务。作为修复这一问题的一部分,我现在意识到我还必须扩展我的unicorn配置文件,所以现在正在处理这一问题……现在我以开发模式启动并读取正确的配置文件,我仍然有问题。因为我仍然在rails2上,所以无法使用config.service\u static\u assets=true。韦布里克很好地为这些资产服务,但我仍然没有找到让独角兽为它们服务的方法。