背景
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.
あなたの回答
tips
プレビュー