11
10

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.

Nginx + Unicorn + RailsでWebアプリを構築する

Last updated at Posted at 2016-01-24

Nginx

/etc/nginx/conf.d/nginx.conf
upstream unicorn {
    server unix:/opt/app/tmp/sockets/unicorn.sock;
}
server {
    listen 80;
    server_name  localhost;
    root /opt/app/public;
    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;
    }

    error_page 500 502 503 504 /500.html;
    error_page 404 /404.html;
}

Unicorn

/opt/app/config/unicorn.rb
# -*- coding: utf-8 -*
application = "app"
working_directory = "/opt/app/"

worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true

listen "/opt/app/tmp/sockets/unicorn.sock"
pid "/opt/app/tmp/sockets/unicorn.pid"

# ログの出力
stderr_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])
stdout_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])

今回、問題となったのはuniconのsockファイルを/tmp直下に配置していました。てアクセスすると502エラーとなります。原因は以下で言及されています。
http://blog.tnantoka.com/posts/49/versions/current

CentOS7では、NginxとUnicorn間で/tmpに配置したファイルを共有できないようです。ファイルのパスを変更したら、問題なく動作しました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?