14
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Rails】Unicornで動かす時の手順メモ

Posted at

Gemを追記する

gem 'unicorn'

Install

bundle install

config/unicorn.rbを追加

touch config/unicorn.rb
config/unicorn.rb
# -*- coding: utf-8 -*-
worker_processes Integer(ENV['WEB_CONCURRENCY'] || 1)
timeout 150
preload_app true

# listen 8080
listen '/tmp/unicorn.sock'
pid '/tmp/unicorn.pid'

一旦portでListenして確認する

config/unicorn.rb
listen 8080
# listen '/tmp/unicorn.sock' => コメントアウト
# pid '/tmp/unicorn.pid' => コメントアウト
bundle exec unicorn_rails -c config/unicorn.rb -E development

動くか確認する

動いたらngnxを設定する

upstream unicorn {
  server unix:/tmp/unicorn.sock;
}

server {
  listen 80;
  server_name sample.com;

  access_log /var/log/nginx/sample_access.log;
  error_log /var/log/nginx/sample_error.log;

  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://unicorn;
  }
}
config/unicorn.rb
# listen 8080 => コメントアウト
listen '/tmp/unicorn.sock' 
pid '/tmp/unicorn.pid'

nginxをリスタートする

sudo nginx -t
sudo service nginx reload
sudo service nginx restart
14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?