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

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

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

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

Ruby on Rails 5

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

nginx

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

Amazon EC2

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

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

解決済

1回答

1861閲覧

capistranoの自動デプロイに失敗

mizo777

総合スコア28

unicorn

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

Ruby on Rails 5

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

nginx

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

Amazon EC2

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

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

0クリップ

投稿2019/06/06 12:22

前提・実現したいこと

現在、ec2,nginx,unicorn,capistranoを使用してchatアプリの自動デプロイに取り組んでいます。
デプロイには成功しますが、ec2インスタンスのアドレスで接続すると、nginxのトップページが表示されます。
スクールで学習中の初心者です。よろしくお願いします。

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

自動デプロイし、ipアドレスに接続するとnginxのトップページが表示

該当のソースコード

Gemfile

1source 'https://rubygems.org' 2 3git_source(:github) do |repo_name| 4 repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 5 "https://github.com/#{repo_name}.git" 6end 7 8 9# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 10gem 'rails', '~> 5.0.7', '>= 5.0.7.2' 11# Use mysql as the database for Active Record 12gem 'mysql2', '>= 0.3.18', '< 0.6.0' 13# Use Puma as the app server 14gem 'puma', '~> 3.0' 15# Use SCSS for stylesheets 16gem 'sass-rails', '~> 5.0' 17# Use Uglifier as compressor for JavaScript assets 18gem 'uglifier', '>= 1.3.0' 19# Use CoffeeScript for .coffee assets and views 20gem 'coffee-rails', '~> 4.2' 21# See https://github.com/rails/execjs#readme for more supported runtimes 22# gem 'therubyracer', platforms: :ruby 23 24# Use jquery as the JavaScript library 25gem 'jquery-rails' 26# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 27gem 'turbolinks', '~> 5' 28gem 'jquery-turbolinks' 29 30# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 31gem 'jbuilder', '~> 2.5' 32# Use Redis adapter to run Action Cable in production 33# gem 'redis', '~> 3.0' 34# Use ActiveModel has_secure_password 35# gem 'bcrypt', '~> 3.1.7' 36 37# Use Capistrano for deployment 38# gem 'capistrano-rails', group: :development 39 40group :development, :test do 41 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 42 gem 'byebug', platform: :mri 43 gem 'rspec-rails' 44 gem 'factory_bot_rails' 45 gem 'rails-controller-testing' 46 gem 'pry-rails' 47 gem 'faker' 48 gem 'capistrano' 49 gem 'capistrano-rbenv' 50 gem 'capistrano-bundler' 51 gem 'capistrano-rails' 52 gem 'capistrano3-unicorn' 53end 54 55group :development do 56 # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. 57 gem 'web-console', '~> 2.0' 58 gem 'listen', '~> 3.0.5' 59 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 60 gem 'spring' 61 gem 'spring-watcher-listen', '~> 2.0.0' 62end 63 64# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 65gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 66gem 'haml-rails' 67gem 'erb2haml' 68gem "font-awesome-rails" 69gem 'devise' 70gem 'rails-i18n' 71gem 'carrierwave' 72gem 'mini_magick' 73gem 'fog-aws' 74 75group :production do 76 gem 'unicorn', '5.4.1' 77end 78 79

config/unicorn.rb

ruby:unicornrb

1 2app_path = File.expand_path('../../../', __FILE__) 3 4worker_processes 1 5 6working_directory "#{app_path}/current" 7listen "#{app_path}/shared/tmp/sockets/unicorn.sock" 8pid "#{app_path}/shared/tmp/pids/unicorn.pid" 9stderr_path "#{app_path}/shared/log/unicorn.stderr.log" 10stdout_path "#{app_path}/shared/log/unicorn.stdout.log" 11 12listen 3000 13timeout 60 14 15preload_app true 16GC.respond_to?(:copy_on_write_friendly=) && GC.copy_on_write_friendly = true 17 18check_client_connection false 19 20run_once = true 21 22before_fork do |server, worker| 23 defined?(ActiveRecord::Base) && 24 ActiveRecord::Base.connection.disconnect! 25 26 if run_once 27 run_once = false # prevent from firing again 28 end 29 30 old_pid = "#{server.config[:pid]}.oldbin" 31 if File.exist?(old_pid) && server.pid != old_pid 32 begin 33 sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU 34 Process.kill(sig, File.read(old_pid).to_i) 35 rescue Errno::ENOENT, Errno::ESRCH => e 36 logger.error e 37 end 38 end 39end 40 41after_fork do |_server, _worker| 42 defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection 43end 44

rails.conf

upstream app_server { server unix:/var/www/chat-space/shared/tmp/sockets/unicorn.sock; } server { listen 80; server_name 54.64.87.152; root /var/www/chat-space/current/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; root /var/www/chat-space/current/public; } try_files $uri/index.html $uri @unicorn; try_files $uri/index.html $uri @unicorn; location @unicorn { 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; } error_page 500 502 503 504 /500.html; }

Capfile

1# Load DSL and set up stages 2require "capistrano/setup" 3 4# Include default deployment tasks 5require "capistrano/deploy" 6 7# Load the SCM plugin appropriate to your project: 8# 9# require "capistrano/scm/hg" 10# install_plugin Capistrano::SCM::Hg 11# or 12# require "capistrano/scm/svn" 13# install_plugin Capistrano::SCM::Svn 14# or 15require "capistrano/scm/git" 16install_plugin Capistrano::SCM::Git 17 18# Include tasks from other gems included in your Gemfile 19# 20# For documentation on these, see for example: 21# 22# https://github.com/capistrano/rvm 23# https://github.com/capistrano/rbenv 24# https://github.com/capistrano/chruby 25# https://github.com/capistrano/bundler 26# https://github.com/capistrano/rails 27# https://github.com/capistrano/passenger 28# 29# require "capistrano/rvm" 30require "capistrano/rbenv" 31# require "capistrano/chruby" 32require "capistrano/bundler" 33require "capistrano/rails/assets" 34require "capistrano/rails/migrations" 35# require "capistrano/passenger" 36require 'capistrano3/unicorn' 37 38 39# Load custom tasks from `lib/capistrano/tasks` if you have any defined 40Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } 41

config/deproy.rb

# config valid for current version and patch releases of Capistrano lock "~> 3.11.0" set :application, "chat-space" set :repo_url, 'git@github.com:mizo777/chat-space.git' set :linked_files, %w{ config/secrets.yml } set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads') set :rbenv_type, :user set :rbenv_ruby, '2.5.1' #カリキュラム通りに進めた場合、2.5.1か2.3.1です set :ssh_options, auth_methods: ['publickey'], keys: ['~/.ssh/aws_miniseven.pem'] set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" } set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" } set :keep_releases, 5 after 'deploy:publishing', 'deploy:restart' namespace :deploy do task :restart do invoke 'unicorn:restart' end desc 'upload secrets.yml' task :upload do on roles(:app) do |host| if test "[ ! -d #{shared_path}/config ]" execute "mkdir -p #{shared_path}/config" end upload!('config/secrets.yml', "#{shared_path}/config/secrets.yml") end end before :starting, 'deploy:upload' after :finishing, 'deploy:cleanup' end set :default_env, { rbenv_root: "/usr/local/rbenv", path: "/usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH", AWS_ACCESS_KEY_ID: ENV["AWS_ACCESS_KEY_ID"], AWS_SECRET_ACCESS_KEY: ENV["AWS_SECRET_ACCESS_KEY"] } # Default branch is :master # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp # Default deploy_to directory is /var/www/my_app_name # set :deploy_to, "/var/www/my_app_name" # Default value for :format is :airbrussh. # set :format, :airbrussh # You can configure the Airbrussh format using :format_options. # These are the defaults. # set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto # Default value for :pty is false # set :pty, true # Default value for :linked_files is [] # append :linked_files, "config/database.yml" # Default value for linked_dirs is [] # append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system" # Default value for default_env is {} # set :default_env, { path: "/opt/ruby/bin:$PATH" } # Default value for local_user is ENV['USER'] # set :local_user, -> { `git config user.name`.chomp } # Default value for keep_releases is 5 # set :keep_releases, 5 # Uncomment the following to require manually verifying the host key before first deploy. # set :ssh_options, verify_host_key: :secure

試したこと

以下の順番で取り組み、capistranoでつまずきました。
unicornで手動デプロイ→ 成功
nginxを導入しての接続→ 成功
capistaranoを導入してのデプロイ→ 失敗
ーーーーーーーーーーーーーーーーーーーーーーーーー
・nginxのログを確認しましたが起動していないようです。(手動でnginxを起動しても✖︎)
・unicornは起動している
・ec2インスタンスの再作成

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

・ec2インスタンスの再作成しました。
・ruby2.5.1
・Rails 5.0.7.2

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

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

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

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

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

guest

回答1

0

自己解決

原因は不明ですが、だいぶ前の正常に動いていた時期のブランチから作り直すことで解決しました。
gitの扱いにも慣れておらず、色々いじっている間に必要なファイルや記述を消してしまったのではないかと思います。

投稿2019/06/15 15:31

mizo777

総合スコア28

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問