Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby on Rails | Unicorn + Nginx環境の疎通(Ubuntu 1204)

概要

Unicorn + Nginx環境の疎通(Ubuntu 1204)

前提

Rails環境(Ruby2.0.0-p247 + Rails4.0.0)は構築済み。
・gemにunicornを指定してインストール済み。
・apt-getでnginxをインストール済み。
Railsのプロジェクト名は「greedents」

手順

/etc/nginx/conf.d/greedents.confを作成
$ sudo cat <<EOS>greedents.conf
upstream greedents {
        server unix:/tmp/greedents.sock;
}

server {
        listen          80;
        server_name     greedents;

        location / {
                proxy_pass http://greedents/;
        }

        location = /robots.txt  { access_log off; log_not_found off; }
        location = /favicon.ico { access_log off; log_not_found off; }

}
EOS
nginxを再起動
sudo service nginx restart

config/unicorn.rbを設定

listen '/tmp/greedents.sock'
pid '/tmp/greedents.pid'

stdout_path '/path_to_rails_app/log/unicorn.stdout.log'
stderr_path '/path_to_rails_app/log/unicorn.stderr.log'

unicornの起動

bundle exec unicorn_rails -E development -c config/unicorn.rb -D

unicornの終了

kill -QUIT `cat /tmp/greedents.pid`

まずは動くところまで確認完了。
細かい設定は改めて。