概要
作成したRailsアプリを本番環境にのせたいので、AWS EC2(Linux2)を使って環境構築をしています。
EC2への接続は完了して、unicorn設定、Ngix設定、PostgreSQL設定を行いunicornの起動をしようと
していますが、起動ができずに悩んでいます。よろしくお願いいたします。
設定ファイル
unicorn version 5.4.1
#myapp/config/unicorn.conf.rb worker_processes 3 timeout 1200 listen File.expand_path 'tmp/sockets/unicorn.sock', '/var/www/rails/myapp' pid File.expand_path 'tmp/pids/unicorn.pid', '/var/www/rails/myapp' stderr_path File.expand_path('unicorn.log', File.dirname(__FILE__) + '/../log') stdout_path File.expand_path('unicorn.log', File.dirname(__FILE__) + '/../log') preload_app true working_directory '/var/www/rails/myapp' # 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
#cd /etc/nginx/nginx.conf user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; upstream unicorn { server unix:/var/www/rails/myapp/tmp/sockets/unicorn.sock; } server { listen 80; server_name IP; root /var/www/rails/myapp/public; try_files $uri/index.html $uri @unicorn; proxy_buffer_size 32k; proxy_buffers 50 32k; proxy_busy_buffers_size 32k; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /500.html { root /var/www/rails/myapp/public; } location @unicorn { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
エラーログ
$ unicorn_rails -c /var/www/rails/appname/config/unicorn.conf.rb -D -E production master failed to start, check stderr log for details $ sudo tail /var/www/rails/appname/log/unicorn.log from config.ru:1:in `new' from config.ru:1:in `<main>' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn.rb:56:in `eval' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn.rb:56:in `block in builder' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:139:in `block in rails_builder' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:795:in `build_app!' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:139:in `start' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>' from /home/myname/.rbenv/versions/2.6.3/bin/unicorn_rails:23:in `load' from /home/myname/.rbenv/versions/2.6.3/bin/unicorn_rails:23:in `<main>'
やったこと
- unicornのバージョンが5.5.1だったので、5.4.1に落としました
- ソケットファイルが.unicorn.sockだったので、unicorn.sockに修正しました
追記
$ unicorn_rails -c /var/www/rails/myapp/config/unicorn.conf.rb -D -E production
を流しながら出したログです
I, [2019-11-16T14:15:45.889685 #14254] INFO -- : Refreshing Gem list /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/fog-core-2.1.2/lib/fog/core/service.rb:244:in `validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError) from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/fog-core-2.1.2/lib/fog/core/service.rb:268:in `handle_settings' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/fog-core-2.1.2/lib/fog/core/service.rb:98:in `new' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/fog-core-2.1.2/lib/fog/core/services_mixin.rb:16:in `new' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/carrierwave-2.0.2/lib/carrierwave/storage/fog.rb:68:in `eager_load' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/carrierwave-2.0.2/lib/carrierwave.rb:77:in `block in <class:Railtie>' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:51:in `each' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/application/finisher.rb:118:in `block in <module:Finisher>' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:32:in `instance_exec' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:32:in `run' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:61:in `block in run_initializers' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:60:in `run_initializers' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/application.rb:363:in `initialize!' from /var/www/rails/appname/config/environment.rb:5:in `<top (required)>' from config.ru:4:in `require_relative' from config.ru:4:in `block in <main>' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize' from config.ru:1:in `new' from config.ru:1:in `<main>' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn.rb:56:in `eval' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn.rb:56:in `block in builder' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:139:in `block in rails_builder' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:795:in `build_app!' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:139:in `start' from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>' from /home/myname/.rbenv/versions/2.6.3/bin/unicorn_rails:23:in `load' from /home/myname/.rbenv/versions/2.6.3/bin/unicorn_rails:23:in `<main>'
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/11/16 14:25
2019/11/18 09:03