3

나는 많이 봤지만 여전히 ec2에 내 사이트를 배포 할 방법을 찾을 수 없습니다. 누구나 ec2에 대해 더 자세히 설명해 줄 수 있습니까? 개발을 위해 Ubuntu11.04를 사용하고 있습니다. 승객 + nginx를 사용하여 배포하고 싶습니다.아마존 Ec2에 레일 3.1 앱 배포

+0

http://www.heroku.com/ ec2로 배포하지만 heroku의 미들웨어를 프리미엄으로 사용합니다. 그들은 무료 티어와 많은 유용한 서비스를 가지고 있습니다. – Hortinstein

+0

AWS의 무료 티어 사용법을 사용하고 있기 때문에, heroku는 당분간 제 선택 사항이 아닙니다 ... AWS에 레일을 배포하는 것이 매우 어렵습니까? 덕분에 –

+0

EC2에 배포하는 것은 다른 서버에 배포하는 것과 같습니다. – NARKOZ

답변

7

저는 capistrano를 사용하여 Rails 3.1 앱을 EC2 마이크로 인스턴스에 배포하고 있습니다. 또한 rvm을 사용하여 EC2에서 Ruby를 설정했습니다. 나는 얇은 것을 사용 해왔다. 그러나 이번 주말 나는 그것을 시험하기 위해 유니콘으로 바꿨다. 내가하고있는 일을 나눌 것이며, 아마도 Passenger를 사용하기 위해 그에 맞게 변경하는 방법을 알아낼 수있을 것입니다. 나는 어떤 식 으로든 전문가가 아니기 때문에 사람들이 이것에 대한 제안을한다면 어떤 의견이라도 환영 할 것입니다. :)

나는 배치의 "rake assets : precompile"단계에서 여전히 문제가 있음을 지적하고 싶습니다. 세 번째 단계 인 자산 : 사전 컴파일 : nodigest로 종료 코드없이 실패합니다. I 생각하면 메모리가 부족할 수 있습니다. 배포를 롤백하지 않습니다. "rake assets : precompile : nodigest"를 실행하면 찾기가 완료되고 모든 것이 잘됩니다. 이것은 테스트 용으로 VM에 배포 할 때만 발생합니다. EC2 마이크로 인스턴스에 배포 할 때만 발생합니다 (EC2 마이크로가 작고 OOM 오류가 과거에 발생했기 때문에 OOM 오류 일 수 있다고 생각하게 만듭니다) .

그럼에도 불구하고 여기에 내가 가진 것이있다. 어쩌면 당신이 일어나 일어나서 도울 수 있습니다. 내 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 :

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

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

load 'config/deploy' 

설정/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 

내 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에서 사이트에 사용할 파일을 만들어야합니다./등 /의 nginx/사이트를

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를/사이트 이용 가능한에서 만든 파일에서 심볼릭 링크를 생성해야하며에 심볼릭 링크 점을 우리는 그것을 foobar.conf 전화 할게 -enabled/foobar