質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Q&A

0回答

629閲覧

unicornが起動できない rails+nginx+unicorn

退会済みユーザー

退会済みユーザー

総合スコア0

unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

0グッド

0クリップ

投稿2019/07/19 02:20

編集2019/07/19 02:26

背景

EC2にてRailsアプリケーションをデプロイを行っている最中です。
以下のサイトを参考に進めていました。
(デプロイ編②)世界一丁寧なAWS解説。EC2を利用して、RailsアプリをAWSにあげるまで

いざ自分のアプリケーションにアクセスしたところ404 Not Found Errorが表示されました。
ps -ef | grep unicorn | grep -v grepでunicornが起動されていないことが分かったのでこれが原因と考えました。

問題

unicornを立ち上げるためbundle exec unicorn_rails -c /var/www/rails/calosee/config/unicorn.conf.rb -D -E productionを実行したところ以下のようなエラーが出ました。

bundler: failed to load command: unicorn_rails (/home/seiya/.rbenv/versions/2.5.3/bin/unicorn_rails) Errno::ENOENT: No such file or directory @ rb_sysopen - /var/www/rails/calosee/config/unicorn.conf.rb /home/seiya/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:84:in `read' /home/seiya/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:84:in `reload' /home/seiya/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:77:in `initialize' /home/seiya/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:77:in `new' /home/seiya/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:77:in `initialize' /home/seiya/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `new' /home/seiya/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>' /home/seiya/.rbenv/versions/2.5.3/bin/unicorn_rails:23:in `load' /home/seiya/.rbenv/versions/2.5.3/bin/unicorn_rails:23:in `<top (required)>' master failed to start, check stderr log for details

したいこと

unicornの起動

関係部分のコード

/var/www/rails/calosee/config/unicorn.conf.rb

set lets $worker = 2 $timeout = 30 $app_dir = "/var/www/rails/calosee" $listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir $std_log = File.expand_path 'log/unicorn.log', $app_dir # set config worker_processes $worker working_directory $app_dir stderr_path $std_log stdout_path $std_log timeout $timeout listen $listen pid $pid # loading booster preload_app true # before starting processes before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{server.config[:pid]}.oldbin" if old_pid != server.pid begin Process.kill "QUIT", File.read(old_pid).to_i rescue Errno::ENOENT, Errno::ESRCH end end end # after finishing processes after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end

/etc/nginx/conf.d/calosee.conf

#log directory error_log /home/seiya/var/www/rails/calosee/log/nginx.error.log; access_log /home/seiya/var/www/rails/calosee/log/nginx.access.log; # max body size client_max_body_size 2G; upstream app_server { # for UNIX domain socket setups server unix:/home/seiya/var/www/rails/calosee/tmp/sockets/.unicorn.sock fail_timeout=0; } server { listen 80; server_name 18.221.254.208; # nginx so increasing this is generally safe... keepalive_timeout 5; # path for static files root /home/seiya/var/www/rails/calosee; # page cache loading try_files $uri/index.html $uri.html $uri @app; location @app { # HTTP headers proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_server; } # Rails error pages error_page 500 502 503 504 /500.html; location = /500.html { root /home/seiya/var/www/rails/calosee; } }

試したこと

  • /home/seiya/.rbenv/versions/2.5.3/bin/unicorn_railsが存在するか確認したが存在する。
  • unicorn 5.4.1バージョンで固定すると解消されるという記事を参考にunicornのバージョンを落としてインストールし直したがエラー内容に変化なし。
  • 一応nginxでエラーが出ていないか確認したが問題はなさそうに見えた。

sudo service nginx status

● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since 木 2019-07-18 05:46:07 UTC; 20h ago Process: 12313 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 12310 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 12309 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 12316 (nginx) CGroup: /system.slice/nginx.service ├─12316 nginx: master process /usr/sbin/nginx └─12318 nginx: worker process 7月 18 05:46:06 ip-10-0-0-134.us-east-2.compute.internal systemd[1]: Starting The nginx HTTP and reverse prox..... 7月 18 05:46:06 ip-10-0-0-134.us-east-2.compute.internal nginx[12310]: nginx: the configuration file /etc/ngi...ok 7月 18 05:46:06 ip-10-0-0-134.us-east-2.compute.internal nginx[12310]: nginx: configuration file /etc/nginx/n...ul 7月 18 05:46:06 ip-10-0-0-134.us-east-2.compute.internal systemd[1]: Failed to read PID from file /run/nginx....nt 7月 18 05:46:07 ip-10-0-0-134.us-east-2.compute.internal systemd[1]: Started The nginx HTTP and reverse proxy...r. Hint: Some lines were ellipsized, use -l to show in full.

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ryochin

2019/07/20 01:40

log/unicorn.stderr.log の内容を提示願います。
退会済みユーザー

退会済みユーザー

2019/07/20 13:49

回答有り難うございます。 log/unicorn.stderr.logなのですがアプリケーションフォルダ内にはありませんでした。 findで検索したところアプリケーション内にあるunicornを含むファイルはunicorn.conf.rbのみでした。 うまくgem unicornがインストールされていないのではないかと思い、再インストール中しました。しかしやはりファイルは作られないようです。 nicorn.conf.rb内にはlog/unicorn.logを作るよう書いてあるはずなのですが
ryochin

2019/07/21 01:52

あとは、/var/www/rails/calosee/config/unicorn.conf.rb が読めないとあるので、パーミッションを確認する等でしょうか。
退会済みユーザー

退会済みユーザー

2019/07/21 06:58

一応調べてみましたが -rw-rw-r-- 1 seiya seiya 942 7月 20 13:45 config/unicorn.conf.rb となっておりchown ユーザー名 config/unicorn.conf.rbを実行しましたがエラー文共々特に変化はありませんでした。 仕方がなさそうなので一からデプロイし直そうかと検討しています。
siruku6

2019/08/13 09:11

解決策になるかどうかはわかりませんが、unicorn.conf.rbというファイル名が不自然です(ドットが2回使われているせい)ので、unicorn.rbに直してみてはいかがでしょう。  railsは結構規約が厳しくて、ファイル命名規則に従っていないだけでいうことを聞いてくれないこともありますので、やってみる価値はあるかなと思いました。  ちなみにこの場合、起動コマンドの対応する箇所の修正ももちろん必要ですのでお忘れなく。  もう解決しているかもしれませんが参考まで。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問