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"
unicorn起動
$ unicorn_rails -c config/unicorn.rb -E development -D
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 ruby.cloudcore2; 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; } }