Ruby/rails/unicorn
提供: 初心者エンジニアの簡易メモ
目次
[非表示]unicornとは
rubyのアプリサーバー
unicornインストール
gem install unicorn
プロジェクトにunicorn設定追加
新規追加
config/unicorn.rb
rails_root = File.expand_path('../../', __FILE__) worker_processes 2 working_directory rails_root listen "#{rails_root}/tmp/unicorn.sock" pid "#{rails_root}/tmp/unicorn.pid" stderr_path "#{rails_root}/log/unicorn_error.log" stdout_path "#{rails_root}/log/unicorn.log" listen 8080
unicorn起動
$ unicorn_rails -c config/unicorn.rb -D
環境変数はdevelopment(開発用)となる
unicorn停止
$ kill -QUIT `cat tmp/unicorn.pid`
unicorn-nginx連携
upstream unicorn_server { server unix:/home/linux/helloworld/tmp/unicorn.sock; } server { listen 80; server_name localhost; root /home/linux/helloworld/public; access_log /var/log/nginx/ruby_helloworld_access.log; error_log /var/log/nginx/ruby_helloworld_error.log; client_max_body_size 100m; error_page 500 502 503 504 /500.html; try_files $uri/index.html $uri @unicorn; location @unicorn { 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://unicorn_server; } }
nginxでPermissionエラーが出る時
connect() to unix:/~/tmp/unicorn.sock failed (13: Permission denied) while connecting to upstream, client:
nginxをrootに変えればとりあえず、うまくいく。
$ sudo vi /etc/nginx/nginx.conf # user nginx; user root;