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

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

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

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

AWS(Amazon Web Services)

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

Capistrano

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

Q&A

解決済

1回答

938閲覧

Capistranoを導入して自動デプロイしたがURLでアクセスできない

amby

総合スコア40

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

AWS(Amazon Web Services)

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

Capistrano

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

0グッド

0クリップ

投稿2020/09/28 12:48

編集2020/09/29 23:25

起きていること

下記のサイトを参考にCapistranoの導入まで行いました。自動デプロイはエラーなく完了したのですがいざURL(http:// 3.115.231.1)でアクセスしてみると「このサイトにアクセスできません3.115.231.1 で接続が拒否されました。」と出てしまします。
何が原因なのでしょうか。
https://qiita.com/mylevel/items/b123ef229842d857ff39#capistrano%E3%81%AE%E5%B0%8E%E5%85%A5

config/deploy/production.rb

# server-based syntax # ====================== # Defines a single server with a list of roles and multiple properties. # You can define all roles on a single server, or split them: # server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value # server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value # server "db.example.com", user: "deploy", roles: %w{db} # role-based syntax # ================== # Defines a role with one or multiple servers. The primary server in each # group is considered to be the first unless any hosts have the primary # property set. Specify the username and a domain or IP for the server. # Don't use `:all`, it's a meta role. # role :app, %w{deploy@example.com}, my_property: :my_value # role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value # role :db, %w{deploy@example.com} # Configuration # ============= # You can set any configuration variable like in config/deploy.rb # These variables are then only loaded and set in this stage. # For available Capistrano configuration variables see the documentation page. # http://capistranorb.com/documentation/getting-started/configuration/ # Feel free to add new variables to customise your setup. # Custom SSH Options # ================== # You may pass any option but keep in mind that net/ssh understands a # limited set of options, consult the Net::SSH documentation. # http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start # # Global options # -------------- # set :ssh_options, { # keys: %w(/home/user_name/.ssh/id_rsa), # forward_agent: false, # auth_methods: %w(password) # } # # The server-based syntax can be used to override options: # ------------------------------------ # server "example.com", # user: "user_name", # roles: %w{web app}, # ssh_options: { # user: "user_name", # overrides user setting above # keys: %w(/home/user_name/.ssh/id_rsa), # forward_agent: false, # auth_methods: %w(publickey password) # # password: "please use keys" # } # サイトを参考にした記述 server '3.115.231.1', user: 'ec2-user', roles: %w{app db web}

config/environment/production.rb

Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. # config.assets.js_compressor = :uglifier # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = true # ここをfalseからtrueに修正 # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "portfolio_#{Rails.env}" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end

config/deploy.rb

# config valid for current version and patch releases of Capistrano lock "3.14.1" set :application, "portfolio" set :deploy_to, '/var/www/portfolio' set :repo_url, "git@github.com:Taishi-Ito/portfolio.git" # バージョンが変わっても共通で参照するディレクトリを指定 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.7.1' #カリキュラム通りに進めた場合、2.5.1か2.3.1です # どの公開鍵を利用してデプロイするか set :ssh_options, auth_methods: ['publickey'], keys: ['~/.ssh/chance-key.pem'] # プロセス番号を記載したファイルの場所 set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" } # Unicornの設定ファイルの場所 set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" } set :keep_releases, 5 # デプロイ処理が終わった後、Unicornを再起動するための記述 after 'deploy:publishing', 'deploy:restart' namespace :deploy do task :restart do invoke 'unicorn:restart' end end

環境情報

Mac
Ruby 2.7.1
Ruby on Rails 5.2.2
capistrano(自動デプロイ)
carrierwave、S3(画像アップロード)
unicorn 5.4.1
Nginx

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

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

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

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

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

yu_1985

2020/09/29 06:33 編集

環境についての情報を追記してください。 また、設定ファイルに合わせて各種ログを確認してください。 Rails、UnicornはもちろんWebサーバのログ(書いてないですがnginx?)等。 ログを見ればどこでエラーになったかが出ている可能性が高いため、まず確認すべきはエラー時に何が発生しているかです。
amby

2020/09/29 23:28

ありがとうございます。Nginx使っております。 ただNginxのアクセスログを確認すると下記のように出てきてします状況です。 [ec2-user@ip-172-31-35-175 portfolio]$ tail -f /var/log/nginx/access.log tail: `/var/log/nginx/access.log' を 読み込み用に開くことが出来ません: 許可がありません tail: ファイルが全く残っていません 参考サイトでCapistrano導入する直前まではサイトにアクセスできたので、Capistranoの導入時に何か原因ができてしまったのではと思っております。
yu_1985

2020/09/30 07:33

権限不足と思われるので sudo 〜 でコマンド実行するか、access.logの権限を変更してください
yu_1985

2020/09/30 07:34

また、nginxのログ「だけではなく」Rails,Unicornのログも確認してください。
amby

2020/10/01 23:17

ありがとうございます。Rails,Nginxのログは確認方法わからずまだなのですが、Unicornは確認できましたので貼り付けます。長かったのでエラーが出てそうな箇所だけ抜粋しました。 E, [2020-09-22T10:41:22.100582 #884] ERROR -- : worker=0 PID:928 timeout (61s > 60s), killing E, [2020-09-22T10:41:22.104346 #884] ERROR -- : reaped #<Process::Status: pid 928 SIGKILL (signal 9)> worker=0 I, [2020-09-22T10:41:22.106930 #930] INFO -- : worker=0 ready /home/ec2-user/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:205:in `pid=': Already running on PID:884 (or pid=/var/www/portfolio/tmp/pids/unicorn.pid is stale) (ArgumentError) from /home/ec2-user/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:137:in `start' from /home/ec2-user/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>' from /home/ec2-user/.rbenv/versions/2.7.1/bin/unicorn_rails:23:in `load' from /home/ec2-user/.rbenv/versions/2.7.1/bin/unicorn_rails:23:in `<main>' I, [2020-09-22T11:55:54.717624 #884] INFO -- : reaped #<Process::Status: pid 930 exit 0> worker=0 I, [2020-09-22T11:55:54.717815 #884] INFO -- : master complete I, [2020-09-22T11:56:04.292608 #1468] INFO -- : Refreshing Gem list
guest

回答1

0

自己解決

結局この記事を参考にコードを書き直したらデプロイできるようになりました。
https://qiita.com/naoki_mochizuki/items/657aca7531b8948d267b

投稿2020/10/07 22:59

amby

総合スコア40

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問