環境
Amazon linux
Rails 6.0.2.1
Ruby 2.6.3
nginx
unicorn
mysql
実現したいこと
現在、以下の記事を参考に、EC2を用いてRailsアプリをAWSにデプロイしています。
https://qiita.com/naoki_mochizuki/items/5a1757d222806cbe0cd1
現在はnginx、unicornの設定と起動まで行いました。
手順通りであれば、ブラウザにアプリが表示される段階です。
発生しているエラー
ブラウザで当該IPにアクセスしても接続が拒否されてしまい、表示されません。
解決法をご存知の方がいればご教授いただきたく思います。
設定
unicorn
# set lets
$worker = 2
$timeout = 30
$app_dir = "/var/www/rails/portgram"
$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
nginx
# log directory
error_log /var/www/rails/portgram/log/nginx.error.log;
access_log /var/www/rails/portgram/log/nginx.access.log;
# max body size
client_max_body_size 2G;
upstream app_server {
# for UNIX domain socket setups
server unix:/var/www/rails/portgram/tmp/sockets/.unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name 18.181.56.156;
# nginx so increasing this is generally safe...
keepalive_timeout 5;
# path for static files
root /var/www/rails/portgram/public;
# 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 /var/www/rails/portgram/public;
また、(自分のアプリ名)/log/nginx.error.log及び(自分のアプリ名)/log/unicorn.logと(自分のアプリ名)/log/production.logも確認しましたが、エラーは出ていませんでした。
試したこと
下記の記事を参考にしましたが、改善されませんでした。
https://qiita.com/sakaimo/items/dd138b39c7480fb2ebff
https://qiita.com/shinyashikis@github/items/ace49154f0c71c65b2c9
上記以外には、config/environments/production.rbの
config.assets.compile = trueの部分をfalseに変更も試しました。
他にも引き続きエラーの解消に向けて調査を続けていますがいまだに手がかりをつかめません。
加えて、エラー文が見つけられないのでさらに原因の特定に時間がかかってしまっています。
どんな情報でもいいのでアドバイスいただければと思っています。
よろしくお願いします。