達成したい事
railsで作ったアプリをAWSでデプロイしたい。
起きている問題
unicorn、nginx、mysql全て立ち上がっているのに、サイトに何も表示されない。
それぞれのエラーログを確認したところnginxに出ている
*595 connect() to unix:/var/www/rails/tempo/tmp/sockets/.unicorn.sock failed (111: Connection refused) while connecting to upstream
が原因かと思われる。
エラー文
2021/04/25 02:10:35 [error] 20882#0: *550 open() "/usr/share/nginx/html/GponForm/diag_Form" failed (2: No such file or directory), client: 65.100.24.78, server: _, request: "POST /GponForm/diag_Form?images/ HTTP/1.1", host: "127.0.0.1:80" 2021/04/25 03:53:47 [error] 20882#0: *557 open() "/usr/share/nginx/html/robots.txt" failed (2: No such file or directory), client: 77.88.5.126, server: _, request: "GET /robots.txt HTTP/1.1", host: "staging.coinhack.jp" 2021/04/25 09:43:47 [error] 20882#0: *594 open() "/usr/share/nginx/html/robots.txt" failed (2: No such file or directory), client: 66.249.71.91, server: _, request: "GET /robots.txt HTTP/1.1", host: "staging.coinhack.jp" 2021/04/25 09:47:50 [error] 20882#0: *595 connect() to unix:/var/www/rails/tempo/tmp/sockets/.unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 184.105.247.252, server: 13.231.15.201, request: "GET / HTTP/1.1", upstream: "http://unix:/var/www/rails/tempo/tmp/sockets/.unicorn.sock:/", host: "xx.xx.xx.xxx(伏せてます)"
考えられる原因
- ソケットのパスが間違えている
- nginx.cnfの記述が何かしらおかしい
- インスタンスのユーザー指定が間違えている?
→アクセスキーIDとシークレットアクセスキーIDはインスタンスを立ち上げたユーザとは別ユーザーだから?ただ、アクセスキーIDとシークレットアクセスキーIDを使用したIAMにはAmazonRoute53FullAccessやAmazonEC2FullAccess、AmazonS3FullAccessの権限をつけている
[/etc/nginx/conf.d/tempo(アプリ名).conf]
# log directory error_log /var/www/rails/tempo/log/nginx.error.log; access_log /var/www/rails/tempo/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/tempo/tmp/sockets/.unicorn.sock fail_timeout=0; } server { listen 80; server_name xx.xxx.xx.xxx(伏せています); # nginx so increasing this is generally safe... keepalive_timeout 5; # path for static files root /var/www/rails/tempo/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/tempo/public; } }
unicorn.conf.rb
# set lets $worker = 2 $timeout = 30 $app_dir = "/var/www/rails/tempo" #自分のアプリケーション名 $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
あなたの回答
tips
プレビュー