Rails5で作成したアプリケーションを、VPSにデプロイして公開しようとしています。
Capistranoを利用して、なんとかデプロイは出来たものの、正しくNginxとUnicornの設定が出来ていないようです。
アプリケーションは【/home/user_name/app_name】にCapistranoを利用してデプロイしており、
app_name
|-current
|-log
|-releases
|-repo
|-revisions.log
|-shared
といったファイル構成になっています。
app_name/current 内で
「bundle exec unicorn_rails -c config/unicorn/production.rb -D -E production」
「sudo systemctl start nginx」
をそれぞれ実行すると起動しますが、その後ドメインにアクセスしても「404 NOT Found」となり、アプリケーションが起動しません。
設定ファイルをどのように修正すればいいでしょうか。
どなたかご教示お願いいたします。
★config/unicorn/production.rb
ruby
1# config/unicorn/production.rb 2 3@app_path = '/home/user_name/app_name' 4working_directory @app_path + "/current" 5 6worker_processes 2 7preload_app true 8timeout 30 9 10listen "/tmp/unicorn.sock" 11pid "/tmp/unicorn.pid" 12 13stderr_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT']) 14stdout_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT']) 15 16before_fork do |server, worker| 17 ENV['BUNDLE_GEMFILE'] = @app_path + '/current/Gemfile' 18end 19 20before_fork do |server, worker| 21 if defined?(ActiveRecord::Base) 22 ActiveRecord::Base.connection.disconnect! 23 end 24 25 old_pid = "#{server.config[:pid]}.oldbin" 26 if File.exists?(old_pid) && server.pid != old_pid 27 begin 28 Process.kill("QUIT", File.read(old_pid).to_i) 29 rescue Errno::ENOENT, Errno::ESRCH 30 end 31 end 32end 33 34after_fork do |server, worker| 35 if defined?(ActiveRecord::Base) 36 ActiveRecord::Base.establish_connection 37 end 38end
★/etc/nginx/nginx.conf
# /etc/nginx/nginx.conf user user_name; worker_processes 1; error_log /home/user_name/app_name/log/nginx_error.log; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; 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; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
★/etc/nginx/conf.d/rails.conf
#/etc/nginx/conf.d/rails.conf upstream unicorn { server unix:/home/user_name/app_name/tmp/unicorn.sock; } server { listen 80; server_name <VPSサーバーのipアドレス>; access_log /home/user_name/app_name/log/nginx_access.log; error_log /home/user_name/app_name/log/nginx_error.log; root /home/user_name/app_name/current; client_max_body_size 100m; error_page 404 /404.html; error_page 500 502 503 504 /500.html; 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; } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。