Amazon ec2 将rails 3.1应用程序部署到Amazon Ec2

Amazon ec2 将rails 3.1应用程序部署到Amazon Ec2,amazon-ec2,nginx,ruby-on-rails-3.1,amazon-web-services,web-deployment,Amazon Ec2,Nginx,Ruby On Rails 3.1,Amazon Web Services,Web Deployment,我在谷歌上搜索了很多,但仍然找不到将我的站点部署到ec2的方法。 有人能给我解释更多关于ec2的事情吗?我正在使用Ubuntu11.04进行开发。 我想使用passenger+nginx进行部署,谢谢我正在使用capistrano将Rails 3.1应用程序部署到EC2微实例。我还使用rvm在我的EC2上安装了Ruby。我一直在使用thin,但这个周末我改用Unicorn来测试它。我将分享我正在做的事情,也许你们可以想出如何相应地更改它以使用Passenger(或者其他人可以对此发表评论)。如果

我在谷歌上搜索了很多,但仍然找不到将我的站点部署到ec2的方法。 有人能给我解释更多关于ec2的事情吗?我正在使用Ubuntu11.04进行开发。
我想使用passenger+nginx进行部署,谢谢

我正在使用capistrano将Rails 3.1应用程序部署到EC2微实例。我还使用rvm在我的EC2上安装了Ruby。我一直在使用thin,但这个周末我改用Unicorn来测试它。我将分享我正在做的事情,也许你们可以想出如何相应地更改它以使用Passenger(或者其他人可以对此发表评论)。如果人们对此有任何建议,我也欢迎大家发表意见,因为我绝不是专家。:)

我想指出,在部署的“rake资产:预编译”阶段,我仍然存在一个问题。它进入第三个阶段,assets:precompile:nodigest,失败时没有退出代码。我想可能是内存不足了。它不会回滚部署。如果我运行“rakeassets:precompile:nodigest”,那么它就完成了find,一切都很好。当我部署到虚拟机进行测试时,这种情况不会发生,只有当我部署到EC2微实例时才会发生(这让我认为这可能是一个OOM错误,因为EC2微很小,我在过去见过OOM错误)

尽管如此,这是我得到的。也许它会帮助你站起来跑步

我的GEM文件中的一些相关内容:

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:

load 'deploy' if respond_to?(:namespace)
load 'deploy/assets'

Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }

load 'config/deploy'
config/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:

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/*;
}
然后在/etc/nginx/sites available下,您应该为您的站点创建一个文件。我们将其命名为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;
  }
}

然后,您应该从刚刚在/etc/nginx/sites中创建的文件中创建一个符号链接,并使该符号链接指向a/etc/nginx/sites enabled/foobar

部署到ec2,但使用heroku的中间件进行高级部署。他们确实有一个免费层和很多有用的服务自从我试图利用AWS的免费层使用以来,heroku暂时不是我的选择…将rails部署到AWS很难吗?感谢部署到EC2就像部署到任何其他服务器。我已经创建了一个aws帐户并启动了一个实例,但我不知道下一步要做什么来部署…我在Ubuntu11.04中,谢谢