- AWSのEC2上でRails+Unicorn+Nginxを実現する
- OSはAmazon Linux AMIを使用する
sudo yum -y install gcc
sudo yum -y install make
sudo yum -y install gcc-c++
sudo yum -y install zlib-devel
sudo yum -y install httpd-devel
sudo yum -y install openssl-devel
sudo yum -y install curl-devel
sudo yum -y install sqlite-devel
sudo yum install git
git clone git://github.com/sstephenson/ruby-build.git
cd ruby-build
sudo ./install.sh
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bashrc
exec $SHELL -l
ebenv install -l
rbenv install 1.9.3-p392;rbenv rehash
rbenv global 1.9.3-p392;rbenv rehash
gem install bundler;rbenv rehash
gem install rdoc
gem install rails
rbenv rehash
rails -v
gem install sqlite3;rbenv rehash
rails new myapp
cd myapp
vi Gemfile
gem 'therubyracer', :platforms => :rubyをコメントイン
bundle install
vi Gemfile
gem 'unicorn'をコメントイン
bundle install
rails server
curl -I localhost:3000
gem install unicorn;rbenv rehash
cd myapp
vi config/unicorn.conf
中身
worker_processes 2
listen '/tmp/unicorn.sock'
stderr_path File.expand_path('unicorn.log', File.dirname(__FILE__) + '/../log')
stdout_path File.expand_path('unicorn.log', File.dirname(__FILE__) + '/../log')
preload_app true
sudo yum -y install nginx
sudo /etc/init.d/nginx start
http://xxx.compute.amazonaws.com/
Welcome to nginx on the Amazon Linux AMI!と出れば成功
sudo /etc/init.d/nginx stop
公開パス /usr/share/ngin/html/
sudo vi /etc/nginx/nginx.conf
中身
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream unicornapp {
server unix:/tmp/unicorn.sock;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://unicornapp;
}
}
}
sudo /etc/init.d/nginx start
cd myapp
unicorn -c config/unicorn.conf -D
※ unicorn_railsの方がいいけどうまくいかなかったのでunicornを使う
http://xxx.compute.amazonaws.com/
Railsのトップが表示されればOK
sudo /etc/init.d/nginx stop
ps ax|grep unicorn|grep -v grep
これで表示されるmasterのプロセスをkillする
sudo /etc/init.d/nginx restart