LoginSignup
11
11

More than 5 years have passed since last update.

Rails5.0.0 + puma3.6 + nginx1.10.1連携

Last updated at Posted at 2016-10-08

Rubyから少し離れていると標準が大きく変わっていました。
備忘録も兼ねて、メモ。

今回はRails5を使ってWEBアプリを構築してみたいと存じます。
これまではunicornを利用してたのですが、5からpumaが
より標準に近い形になっていくように見受けられました。

SWのバージョン
さくらのクラウド(CentOS7.2)を利用します。

version
$ uname -a 
Linux lightnote-ap 3.10.0-327.22.2.el7.x86_64 #1 SMP Thu Jun 23 17:05:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

$ rails -v
Rails 5.0.0.1

$ puma -v
* Version 3.6.0

$ nginx -v
nginx version: nginx/1.10.1

pumaの設定

puma.rb
# project_home /opt/rails/rightnotes
$ pwd
/opt/rails/rightnotes

$ cat config/puma.rb 
_proj_path = "/opt/rails/rightnotes"
_proj_name = "rightnotes" 
_home = "/opt/rails/rightnotes"
pidfile "#{_home}/run/#{_proj_name}.pid"
bind "unix://#{_home}/run/#{_proj_name}.sock"
directory _proj_path

#以下省略

nginxの設定

default.conf
# cat /etc/nginx/conf.d/default.conf
upstream rightnotes {
    server unix:/opt/rails/rightnotes/run/rightnotes.sock fail_timeout=0;
} 
server {
    listen       80;
    server_name  localhost;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/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://rightnotes;
    }

    root /opt/rails/rightnotes/public;
    client_max_body_size 10m;
    error_page 404 /404.html;
    error_page 500 502 503 504 /500.html;
    try_files $uri/index.html $uri @rightnotes;
}

nginx、puma start

start
$ systemctl start nginx.service
$ cd /opt/rails/rightnotes
$ puma -w 2

ブラウザでアクセスする
スクリーンショット 2016-10-08 22.38.17.png

取り急ぎ、連携と動作を確認できました。
Rails5、pumaどちらも、きちんと勉強しなおす必要がありますね。

11
11
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
11
11