質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

2021閲覧

Nginxのconnection refusedエラーが直せない

mayok

総合スコア12

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2020/08/01 12:22

前提・実現したいこと

EC2でrailsのアプリケーションをデプロイするのをゴールとしています。

今の段階としては、サーバー構築とDB設定、puma、nginxの設定まで終えて、
IPアドレスで接続を試みています。

発生している問題・エラーメッセージ

① sudo systemctl restart nginx ② rails s -e production ③ IPアドレスで接続

とすると反応が遅くtime outになりログを見ると以下が出力されます。

(log/nginx.error.log) [error] 3976#0: *1 connect() to unix:/var/www/rails/Contrail/tmp/sockets/puma.sock failed (111: Connection refused) while connecting to upstream, client: ~~.~~~.~.~~~, server: ~~.~~~.~.~~~, request: "GET / HTTP/1.1", upstream: "http://unix:/var/www/rails/Contrail/tmp/sockets/puma.sock:/", host: "~~.~~~.~.~~~"

該当のソースコード

(nginx/conf.d/contrail.conf) # log directory error_log /var/www/rails/Contrail/log/nginx.error.log; access_log /var/www/rails/Contrail/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/Contrail/tmp/sockets/puma.sock fail_timeout=0; } server { listen 80; server_name ~~.~~~.~.~~~;(実際はパブリックIPを入力しています) # nginx so increasing this is generally safe... keepalive_timeout 5; # path for static files root /var/www/rails/Contrail/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/Contrail/public; } }
(config/puma.rb) # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # #port ENV.fetch("PORT") { 3000 } bind "unix://#{Rails.root}/tmp/sockets/puma.sock" # Specifies the `environment` that Puma will run in. # environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the `pidfile` that Puma will use. pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. # Workers do not work on JRuby or Windows (both of which do not support # processes). # # workers ENV.fetch("WEB_CONCURRENCY") { 2 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write # process behavior so workers use less memory. # # preload_app! # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart

試したこと

  • nginx/conf.d/contrail.conf内のsever nameの見直し、upstreamをapp_serverからpumaに変更して試しましたがconnection refusedは変わらず表示されます。
  • 調べた際ポート番号を指定した際などに出るとありコマンドの再確認をしました。
  • $ curl -i IPアドレス で反応を見た際はWe're sorry. Something went wrongと表示されました。

ローカルからHerokuにデプロイはできていること、production.logからはアプリ側のエラーが読み取れなかったことからpumaかNginxの設定が違っているのかと考えています。
(production.logを載せると文字数エラーになるため載せておりません。)

追加情報がありましたら加筆修正します。
お手数おかけしますがよろしくお願い致します。

補足情報(FW/ツールのバージョンなど)

  • mac OS catalina 10.15.6
  • amazon linuz2(AMI)
  • nginx 1.18.0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

解決いたしました。
config/environments/production.rb内、config.force_ssl = true
の部分を" config.force_ssl = false "に指定し直すことでデプロイが成功しました。

こちらの質問にたどり着いた方にも参考になると嬉しいです。

投稿2020/08/01 12:42

mayok

総合スコア12

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問