[英]deploying rails 3.1 apps to Amazon Ec2
I've googled a lot, but still can't find a way to deploy my site to ec2. 我已经google了很多,但仍然找不到将我的网站部署到ec2的方法。 can anyone explain more about ec2 to me?
谁能向我解释更多关于ec2的内容? I'm using Ubuntu11.04 for developement.
我正在使用Ubuntu11.04进行开发。 I would like to use passenger + nginx to deploy, thanks
我想使用passenger + nginx进行部署,谢谢
I'm using capistrano to deploy a Rails 3.1 app to an EC2 micro instance. 我正在使用capistrano将Rails 3.1应用程序部署到EC2微实例。 I've also setup Ruby on my EC2 using rvm.
我还使用rvm在我的EC2上设置了Ruby。 I've been using thin, but this weekend I switched to Unicorn to test it out.
我一直在使用薄,但本周末我转而使用Unicorn进行测试。 I'll share what I'm doing, and maybe you can figure out how to change it accordingly to use Passenger (or someone else can comment on that).
我将分享我正在做的事情,也许你可以弄清楚如何相应地改变它以使用Passenger(或其他人可以对此发表评论)。 I'd also welcome any comments if people have some suggestions for any of this, as I'm in no way an expert.
如果人们对此有任何建议,我也欢迎任何评论,因为我不是专家。 :)
:)
I would like to point out that I still have a problem during the "rake assets:precompile" stage of my deploy. 我想指出在部署的“rake assets:precompile”阶段我仍然遇到问题。 It gets to the third stage, assets:precompile:nodigest, and fails with no exit code.
它进入第三阶段,资产:预编译:nodigest,并且没有退出代码而失败。 I think it might be running out of memory.
我想它可能会耗尽内存。 It's not rolling back the deploy.
它没有回滚部署。 If I run "rake assets:precompile:nodigest" then it finishes just find and everything is good to go.
如果我运行“rake assets:precompile:nodigest”,那么它就会完成查找,一切都很好。 This doesn't happen when I deploy to my VM for testing, only when I deploy to my EC2 micro instance (which makes me think it could be an OOM error since EC2 micro is tiny and I've seen OOM errors in the past).
当我部署到我的VM进行测试时,这种情况不会发生,只有当我部署到我的EC2微实例时(这让我觉得它可能是一个OOM错误,因为EC2 micro很小而且我以前看过OOM错误) 。
Despite that, here's what I've got. 尽管如此,这就是我所拥有的。 Maybe it'll help you get up and running.
也许它会帮助你起床和跑步。
Some relevant things from my Gemfile: 我的Gemfile中的一些相关内容:
gem 'rails', '3.1.1'
group :assets do
gem 'jquery-rails',
gem 'sass-rails', "~> 3.1.4"
gem 'coffee-rails', "~> 3.1.1"
gem 'uglifier', ">= 1.0.3"
gem 'compass', :git => 'git://github.com/chriseppstein/compass.git', :branch => 'master'
end
group :production do
gem 'therubyracer'
end
gem 'unicorn'
Capfile: Capfile:
load 'deploy' if respond_to?(:namespace)
load 'deploy/assets'
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'
config/deploy.rb: 配置/ deploy.rb:
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
require "bundler/capistrano"
role :app, "your-ec2-domain"
role :db, "your-ec2-domain", :primary => true
set :user, "your-login-username"
set :application, "your-app-name"
set :scm, :git
set :repository, "."
set :branch, "deploy" # or whatever git branch you deploy from
set :deploy_via, :copy
set :deploy_to, "/home/#{user}/rails/#{application}"
set :use_sudo, false
set :rails_env, "production"
set :rvm_ruby_string, "ruby-1.9.2-p290"
set :rvm_type, :user
set :unicorn_pid do
"#{shared_path}/pids/unicorn.pid"
end
before "deploy:assets:precompile", "bundle:install"
namespace :deploy do
task :start do
top.unicorn.start
end
task :stop do
top.unicorn.stop
end
task :restart do
top.unicorn.reload
end
end
namespace :unicorn do
desc "start unicorn server"
task :start, :roles => :app do
run "cd #{current_path} && bundle exec unicorn -E #{rails_env} -D -P #{unicorn_pid}"
end
desc "stop unicorn server"
task :stop do
run "kill -s QUIT `cat #{unicorn_pid}`"
end
desc "restart unicorn"
task :restart do
top.unicorn.stop
top.unicorn.start
end
desc "reload unicorn (gracefully restart workers)"
task :reload do
run "kill -s USR2 `cat #{unicorn_pid}`"
end
desc "reconfigure unicorn (reload config and gracefully restart workers)"
task :reconfigure, :roles => :app do
run "kill -s HUP `cat #{unicorn_pid}`"
end
end
My nginx.conf: 我的nginx.conf:
user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 768;
accept_mutex off;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log combined;
error_log /var/log/nginx/error.log;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay off;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Then under /etc/nginx/sites-available you should create a file for your site. 然后在/ etc / nginx / sites-available下,您应该为您的站点创建一个文件。 We'll call it foobar.conf:
我们称之为foobar.conf:
upstream rails {
server unix:/tmp/.sock fail_timeout=0;
server 127.0.0.1:8080 fail_timeout=0;
}
server {
listen 80 default deferred;
server_name foobar.com
access_log /var/log/nginx/rails.access.log main;
# foobar is your project. current is a symlink setup by capistrano
root /home/username/rails/foobar/current/public;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://rails;
}
location ~ ^/assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
error_page 500 502 503 504 /500.html
location = /500.html
root /home/username/rails/foobar/current/public;
}
}
Then you should create a symlink from the file you just created in /etc/nginx/sites-available and make the symlink point to a /etc/nginx/sites-enabled/foobar 然后你应该从你刚刚在/ etc / nginx / sites-available中创建的文件中创建一个符号链接,并使符号链接指向/ etc / nginx / sites-enabled / foobar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.