EC2上にRailsアプリのデプロイを試みています。
ブラウザからアクセスすると、「このサイトにアクセスできません」と表示されて解決できずにいます。
ご助言をいただけると幸いです。
起きている問題
EC2にRailsアプリをデプロイ後、ブラウザから対象ドメインにアクセスしてもnginx => pumaの接続に失敗する。
前提事項
開発環境
・macOS Monterey v12.1
・ruby v3.0.3
・Rails v6.1.4.4
・MySQL 8.0.28
・puma 5.5.2
・nginx 1.20.0
インフラ構成図
関連するコード
ruby
1# src/config/puma.rb 2 3workers Integer(ENV['WEB_CONCURRENCY'] || 2) 4max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 5min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 6threads min_threads_count, max_threads_count 7 8preload_app! 9rails_env = ENV.fetch("RAILS_ENV") { "development" } 10environment rails_env 11case rails_env 12 when "development" 13 port ENV.fetch("PORT") { 3000 } 14 when "production" 15 bind "unix:///var/www/my_app/src/tmp/sockets/puma.sock" 16end 17 18pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 19plugin :tmp_restart 20 21on_worker_boot do 22 # Worker specific setup for Rails 4.1+ 23 # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot 24 ActiveRecord::Base.establish_connection 25end
# /etc/nginx/conf.d/my_app.conf upstream puma { server unix:///var/www/my_app/src/tmp/sockets/puma.sock; } server { listen 80; server_name my_app.com; keepalive_timeout 0; access_log /var/log/nginx/my_app.access.log main; client_max_body_size 4G; root /var/www/my_app/src/public; location ~ .*\.(swf|SWF|ico|ICO|jar|txt|gz|js) { root /var/www/my_app/src/public; expires 15m; break; } location ~ ^\/fonts\/* { root /var/www/my_app/src/public; expires 15m; break; } location ~ ^\/assets\/* { root /var/www/my_app/src/public; break; } location ~ ^\/favicon\/* { root /var/www/my_app/src/public; break; }
確認したこと
pumaが起動していることを確認
ブラウザの更新ボタンを押してもログが出ないため、Nginx => Pumaの接続ができていないと考えています。
bash
1$ rails s 2=> Booting Puma 3=> Rails 6.1.4.4 application starting in production 4=> Run `bin/rails server --help` for more startup options 5[25055] Puma starting in cluster mode... 6[25055] * Puma version: 5.5.2 (ruby 3.0.3-p157) ("Zawgyi") 7[25055] * Min threads: 5 8[25055] * Max threads: 5 9[25055] * Environment: production 10[25055] * Master PID: 25055 11[25055] * Workers: 2 12[25055] * Restarts: (✔) hot (✖) phased 13[25055] * Preloading application 14[25055] * Listening on unix:///var/www/my_app/src/tmp/sockets/puma.sock 15[25055] Use Ctrl-C to stop 16[25055] - Worker 0 (PID: 25091) booted in 0.0s, phase: 0 17[25055] - Worker 1 (PID: 25092) booted in 0.0s, phase: 0
nginxが起動していることを確認
bash
1$ ps aux | grep nginx 2root 25163 0.0 0.1 39992 1016 ? Ss 13:06 0:00 nginx: master process nginx 3nginx 25164 0.0 0.3 40376 3080 ? S 13:06 0:00 nginx: worker process 4my_username 25166 0.0 0.0 119440 980 pts/0 S+ 13:06 0:00 grep --color=auto nginx
RailsのSSL受付設定をOFFに(まだSSL化をしていないため)
ruby
1# src/config/environments/production.rb 2... 3config.force_ssl = false 4...
ローカル、EC2上共に$curl http://IPアドレス/
で下記が返ってくる
bash
1$ curl http://IPアドレス/ 2 3---------------------------------------------- 4 5<!DOCTYPE html> 6<html> 7<head> 8 <title>We're sorry, but something went wrong (500)</title> 9 <meta name="viewport" content="width=device-width,initial-scale=1"> 10 <style> 11 .rails-default-error-page { 12 background-color: #EFEFEF; 13 color: #2E2F30; 14 ... 15 </style> 16</head> 17 18<body class="rails-default-error-page"> 19 <!-- This file lives in public/500.html --> 20 <div class="dialog"> 21 <div> 22 <h1>We're sorry, but something went wrong.</h1> 23 </div> 24 <p>If you are the application owner check the logs for more information.</p> 25 </div> 26</body> 27</html>
nginxのアクセスログを確認
アクセスはできている。
bash
1$ cat my_app.access.log 2 3... 4185.180.143.7 - - [05/May/2022:13:09:13 +0000] "GET / HTTP/1.1" 500 1635 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36" "-" 53.115.120.160 - - [05/May/2022:13:10:13 +0000] "GET / HTTP/1.1" 500 1635 "-" "curl/7.79.1" "-" 6210.170.174.207 - - [05/May/2022:13:10:55 +0000] "GET / HTTP/1.1" 500 1635 "-" "curl/7.77.0" "-" 795.214.235.205 - - [05/May/2022:13:13:55 +0000] "GET /.env HTTP/1.1" 404 746 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36" "-" 895.214.235.205 - - [05/May/2022:13:13:56 +0000] "POST / HTTP/1.1" 404 746 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36" "-"
※対応するエラーログは無し
お手数ですが、解決へのヒントをいただけないでしょうか。
よろしくお願いします。
追記1
Railsaのエラーログが出ていました。
application.html.erb
をrenderするときに 500エラー が出ていました。Nginx => Puma の接続はうまくいっているということでしょうか。
ログを見ると、多分tailwindが悪さをしています。そしてなぜかwordpressのページにアクセスしているが、wordpress使ったことない...
bash
1# src/log/production.log 2 3I, [2022-05-06T04:16:31.459570 #25092] INFO -- : [0327e*********78e81] Started GET "/" for 172.***.***.*** at 2022-05-06 04:16:31 +0000 4I, [2022-05-06T04:16:31.465913 #25092] INFO -- : [0327e*********78e81] Processing by Users::SessionsController#new as HTML 5I, [2022-05-06T04:16:31.468518 #25092] INFO -- : [0327e*********78e81] Rendered users/sessions/new.html.erb within layouts/application (Duration: 1.3ms | Allocations: 622) 6I, [2022-05-06T04:16:31.470831 #25092] INFO -- : [0327e*********78e81] Rendered layout layouts/application.html.erb (Duration: 3.7ms | Allocations: 3792) 7I, [2022-05-06T04:16:31.470987 #25092] INFO -- : [0327e*********78e81] Completed 500 Internal Server Error in 5ms (Allocations: 4395) 8F, [2022-05-06T04:16:31.471712 #25092] FATAL -- : [0327e*********78e81] 9[0327e*********78e81] ActionView::Template::Error (The asset "tailwind.css" is not present in the asset pipeline. 10): 11[0327e*********78e81] 6: <meta name="viewport" content="width=device-width,initial-scale=1"> 12[0327e*********78e81] 7: <%= csrf_meta_tags %> 13[0327e*********78e81] 8: <%= csp_meta_tag %> 14[0327e*********78e81] 9: <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %> 15[0327e*********78e81] 10: 16[0327e*********78e81] 11: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 17[0327e*********78e81] 12: <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> 18[0327e*********78e81] 19[0327e*********78e81] app/views/layouts/application.html.erb:9 20I, [2022-05-06T04:16:31.616662 #25092] INFO -- : [101c3*********80f92] Started GET "/blog/wp-includes/wlwmanifest.xml" for 172.***.***.*** at 2022-05-06 04:16:31 +0000 21F, [2022-05-06T04:16:31.622688 #25092] FATAL -- : [101c3*********80f92] 22[101c3*********80f92] ActionController::RoutingError (No route matches [GET] "/blog/wp-includes/wlwmanifest.xml"): 23[101c3*********80f92] 24I, [2022-05-06T04:16:31.774667 #25092] INFO -- : [5d3d9*********78aee] Started GET "/web/wp-includes/wlwmanifest.xml" for 172.***.***.*** at 2022-05-06 04:16:31 +0000 25F, [2022-05-06T04:16:31.780607 #25092] FATAL -- : [5d3d9*********78aee] 26[5d3d9*********78aee] ActionController::RoutingError (No route matches [GET] "/web/wp-includes/wlwmanifest.xml"): 27[5d3d9*********78aee] 28I, [2022-05-06T04:16:31.924361 #25092] INFO -- : [16742*********3549d] Started GET "/wordpress/wp-includes/wlwmanifest.xml" for 172.***.***.*** at 2022-05-06 04:16:31 +0000
追記2
nginxとrails、同アクセスのログを取り直しました。
app/views/layouts/application.html.erb:9
でエラーが出ていました。
bash
1$ cat access.log 2 3210.170.174.207 - - [06/May/2022:11:22:43 +0000] "GET / HTTP/1.1" 500 1635 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36" "-" 4210.170.174.207 - - [06/May/2022:11:22:43 +0000] "GET /favicon.ico HTTP/1.1" 304 0 "http://my_app.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36" "-" 5 6$ cat error.log 7<なし> 8 9$ cat /var/www/my_app/src/log/production.log 10 11I, [2022-05-06T11:22:43.539910 #589] INFO -- : [f23eb******1b072] Started GET "/" for 210.***.***.207 at 2022-05-06 11:22:43 +0000 12I, [2022-05-06T11:22:43.546294 #589] INFO -- : [f23eb******1b072] Processing by Users::SessionsController#new as HTML 13I, [2022-05-06T11:22:43.548823 #589] INFO -- : [f23eb******1b072] Rendered users/sessions/new.html.erb within layouts/application (Duration: 1.2ms | Allocations: 622) 14I, [2022-05-06T11:22:43.551109 #589] INFO -- : [f23eb******1b072] Rendered layout layouts/application.html.erb (Duration: 3.5ms | Allocations: 3793) 15I, [2022-05-06T11:22:43.551258 #589] INFO -- : [f23eb******1b072] Completed 500 Internal Server Error in 5ms (Allocations: 4409) 16F, [2022-05-06T11:22:43.551993 #589] FATAL -- : [f23eb******1b072] 17[f23eb******1b072] ActionView::Template::Error (The asset "tailwind.css" is not present in the asset pipeline. 18): 19[f23eb******1b072] 6: <meta name="viewport" content="width=device-width,initial-scale=1"> 20[f23eb******1b072] 7: <%= csrf_meta_tags %> 21[f23eb******1b072] 8: <%= csp_meta_tag %> 22[f23eb******1b072] 9: <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %> 23[f23eb******1b072] 10: 24[f23eb******1b072] 11: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 25[f23eb******1b072] 12: <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> 26[f23eb******1b072] 27[f23eb******1b072] app/views/layouts/application.html.erb:9
また、ブラウザからアクセスした時の表示が「We're sorry, but something went wrong.」に変わりました。
回答1件
あなたの回答
tips
プレビュー