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

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

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

Cloud9は、クラウドからのプログラミングが可能になるWebサービス。IDEとしての機能が搭載されており、GitHubやHerokuなど他ツールとの連携も可能です。ブラウザ上で動くため、デバイスに関係なく開発環境を準備できます。

unicorn

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

nginx

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

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

AWS(Amazon Web Services)

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

Q&A

解決済

1回答

742閲覧

Ruby on rails AWS上のEC2をデプロイしたい

arita

総合スコア11

Cloud9

Cloud9は、クラウドからのプログラミングが可能になるWebサービス。IDEとしての機能が搭載されており、GitHubやHerokuなど他ツールとの連携も可能です。ブラウザ上で動くため、デバイスに関係なく開発環境を準備できます。

unicorn

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

nginx

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

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

AWS(Amazon Web Services)

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

0グッド

0クリップ

投稿2022/06/10 03:04

前提・実現したいこと

AWS上のcloud9で開発しているruby on railsのページをEC2のパブリックIPでhttp経由でブラウザ上に表示したいです。

現在、NginsとUniconeを利用してデプロイしようとしているのですが、Nginxとunicornの起動時に以下のエラーが発生しております。
利用中の環境
ruby 2.6.3
rails 5.2.3

Nginxの設定 エラー

APP名(test_app)
Nginxの設定内容(etc/nginx/nginx.conf

pid "/var/run/nginx.pid"; events { worker_connections 2048; } http { upstream unicorn { server unix:/home/ec2-user/environment/test-app/tmp/sockets/.unicorn.sock; } server { listen 80; server_name (publicIP); root /home/ec2-user/environment/test-app/; error_log /home/ec2-user/environment/test-app/log/nginx.log; include /etc/nginx/mime.types; location / { if (-f $request_filename) { break; } proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  proxy_set_header Host $http_host;   proxy_pass http://unicorn;   } } }

エラー内容

systemctl start nginx Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: [emerg] open() "/home/ec2-user/environment/test-app/log/nginx.log" failed (2: No such file or directory) nginx: configuration file /etc/nginx/nginx.conf test failed

Unicornの設定 エラー

unicornの設定

config/unicorn.rb # unicorn.rb # set lets $worker = 2 $timeout = 30 $app_dir = "/home/ec2-user/environment/test-app/" #アプリの場所 $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

unicornのエラー

bundle exec unicorn_rails -E production -c config/unicorn.rb -D Traceback (most recent call last): 12: from /home/ec2-user/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `<main>' 11: from /home/ec2-user/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval' 10: from /home/ec2-user/.rvm/gems/ruby-2.6.3/bin/unicorn_rails:23:in `<main>' 9: from /home/ec2-user/.rvm/gems/ruby-2.6.3/bin/unicorn_rails:23:in `load' 8: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>' 7: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `new' 6: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:77:in `initialize' 5: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:77:in `new' 4: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:77:in `initialize' 3: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:84:in `reload' 2: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:84:in `instance_eval' 1: from config/unicorn.rb:12:in `reload' /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:592:in `working_directory': config_file=config/unicorn.rb would not be accessible in working_directory=/home/ec2-user/environment/test-app (ArgumentError) master failed to start, check stderr log for details

色々と検索したり、コードも複数試したのですが毎回エラーになってしまいどうしようもない状況です。
宜しくお願いいたします。

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

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

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

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

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

guest

回答1

0

ベストアンサー

nginx -tに失敗しているのでnginxの設定に問題があることがわかります。

nginx: [emerg] open() "/home/ec2-user/environment/test-app/log/nginx.log" failed (2: No such file or directory)

ホームディレクトリにログを吐こうとして権限が足りてない可能性がありますね。

ホームディレクトリはデフォルトではそのディレクトリの所有者しか読み書きできないです。
なので基本的にホームディレクトリに外部から参照させるためのソースを置いたり、ログを吐き出させたりするのはやめて別の場所を指定してください。
だからと言ってホームディレクトリの権限を変えると、ミスったらSSHできなくなるので触らないほうが賢明です。
そこまでしてホームディレクトリにものを置く理由もないですし。
https://teratail.com/questions/36969

投稿2022/06/10 05:15

yu_1985

総合スコア7443

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

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

arita

2022/06/10 05:56

コメントありがとうございます。 ディレクトリ変更して対応させていただきました。 "/home/ec2-user/environment/test-app/log/nginx.log" ↓ "/var/log/nginx/app_error.log"
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問