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

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

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

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

nginx

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

Amazon EC2

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

Q&A

0回答

477閲覧

RailsアプリをEC2でnginxとunicornを使ってデプロイしたいが「応答時間が長すぎます」と表記されてしまう

ysec

総合スコア5

unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

nginx

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

Amazon EC2

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

0グッド

0クリップ

投稿2020/02/04 02:17

編集2020/02/04 02:23

現状:

デプロイしてアプリを表示したいです。

エラーログには特に記述もありません。
セキュリティグループもHTTPタイプの接続を解放してあります。

mysql、nginx、unicornは起動確認済みです。

おそらくnginxとunicornが上手く連動していないことが考えられますが
手詰まりになりました。

(デプロイ編②)世界一丁寧なAWS解説。EC2を利用して、RailsアプリをAWSにあげるまで
を参考にしました。


諸条件

node v12.14.1
npm 6.13.4
unicorn v5.5.2
nginx version: nginx/1.16.1
ruby 2.3.1p112
Rails 5.1.6


ユニコーンの設定
$ /var/www/rails/アプリ名/config/unicorn.conf.rb

# set lets $worker = 2 $timeout = 30 $app_dir = "/var/www/rails/アプリ名" $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の設定
$ /etc/nginx/conf.d/アプリ名.conf

#log directory error_log /var/www/rails/アプリ名/log/nginx.error.log; access_log /var/www/rails/アプリ名/log/nginx.access.log; # max body size client_max_body_size 2G; upstream unicorn { # for UNIX domain socket setups server unix:/var/www/rails/アプリ名/tmp/sockets/.unicorn.sock fail_timeout=0; } server { listen 80; server_name ~~.~~~.~~~.~~ ; #(Elastic IP address) # nginx so increasing this is generally safe... keepalive_timeout 5; # path for static files # Location of our static files root /var/www/rails/アプリ名/public; location ~ ^/assets/ { root /var/www/rails/アプリ名/public; allow all; } # 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; if (!-f $request_filename) { proxy_pass http://unicorn; break; } } # Rails error pages error_page 500 502 503 504 /500.html; location = /500.html { root /var/www/rails/アプリ名/public; } }

以上、よろしくお願いします。

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

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

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

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

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

yu_1985

2020/02/04 02:26

「エラーログには特に記述がない」とのことですが、Unicorn、Rails、nginxいずれにも何も出力されていない、ということでしょうか?
ysec

2020/02/04 02:38

ただいま確認したところ以下のようになっておりました。 nginx $ /var/www/rails/アプリ名/log/nginx.error.log 記述なし Unicorn $ /var/www/rails/アプリ名/log/unicorn.log I, [2020-02-04T01:33:53.105280 #4971] INFO -- : Refreshing Gem list I, [2020-02-04T01:33:56.382316 #4971] INFO -- : unlinking existing socket=/var/www/rails/test/tmp/sockets/.unicorn.sock I, [2020-02-04T01:33:56.382997 #4971] INFO -- : listening on addr=/var/www/rails/test/tmp/sockets/.unicorn.sock fd=11 I, [2020-02-04T01:33:56.399023 #4971] INFO -- : master process ready I, [2020-02-04T01:33:56.405872 #4976] INFO -- : worker=0 ready I, [2020-02-04T01:33:56.407288 #4978] INFO -- : worker=1 ready Production $ /var/www/rails/アプリ名/log/production.log D, [2020-02-04T01:33:56.395576 #4971] DEBUG -- : ^[[1m^[[35m (6.3ms)^[[0m ^[[1m^[[35mSET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483^[[0m "production.log" 72L, 10004C
yu_1985

2020/02/04 02:48

nginxはaccess.logのほうはどうでしょうか?
ysec

2020/02/04 02:58

nginxのaccess.logは以下の通りでした。 $ /var/www/rails/アプリ名/log/nginx.access.log 171.67.70.88 - - [04/Feb/2020:02:18:26 +0000] "" 400 0 "-" "-"
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問