The*_*ner 3 nginx amazon-ec2 web-deployment amazon-web-services ruby-on-rails-3.1
我已经google了很多,但仍然找不到将我的网站部署到ec2的方法.谁能向我解释更多关于ec2的内容?我正在使用Ubuntu11.04进行开发.我想使用passenger + nginx进行部署,谢谢
我正在使用capistrano将Rails 3.1应用程序部署到EC2微实例.我还使用rvm在我的EC2上设置了Ruby.我一直在使用瘦身,但本周末我转而使用Unicorn进行测试.我将分享我正在做的事情,也许你可以弄清楚如何相应地改变它以使用Passenger(或其他人可以对此发表评论).如果人们对此有任何建议,我也欢迎任何评论,因为我不是专家.:)
我想指出在部署的"rake assets:precompile"阶段我仍然遇到问题.它进入第三阶段,资产:预编译:nodigest,并且没有退出代码而失败.我想它可能会耗尽内存.它没有回滚部署.如果我运行"rake assets:precompile:nodigest",那么它就会完成查找,一切都很好.当我部署到我的VM进行测试时,这种情况不会发生,只有当我部署到我的EC2微实例时(这让我觉得它可能是一个OOM错误,因为EC2 micro很小而且我以前看过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'
Run Code Online (Sandbox Code Playgroud)
Capfile:
load 'deploy' if respond_to?(:namespace)
load 'deploy/assets'
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'
Run Code Online (Sandbox Code Playgroud)
配置/ 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
Run Code Online (Sandbox Code Playgroud)
我的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/*;
}
Run Code Online (Sandbox Code Playgroud)
然后在/ 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;
}
}
Run Code Online (Sandbox Code Playgroud)
然后你应该从你刚刚在/ etc/nginx/sites-available中创建的文件中创建一个符号链接,并使符号链接指向/ etc/nginx/sites-enabled/foobar
| 归档时间: |
|
| 查看次数: |
3152 次 |
| 最近记录: |