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

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

新規登録して質問してみよう
ただいま回答率
85.46%
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の基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Amazon EC2

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

Capistrano

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

Q&A

0回答

541閲覧

Railsで作成したアプリが本番環境(AWS)でのみルーティングエラーを出す

gannbaritai

総合スコア2

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の基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Amazon EC2

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

Capistrano

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

0グッド

0クリップ

投稿2021/02/10 10:42

前提・実現したいこと

本番環境(AWS EC2上にてアプリを動かしたい)

###質問したいこと
AWSに登録をしてEC2を利用しアプリケーションを公開しようと作業したのですが、サイトを開くと

We're sorry, but something went wrong.

となってしまい長い時間解決ができなかったこちらで質問させていただこうと思いました。

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

We're sorry, but something went wrong. If you are the application owner check the logs for more information.

###確認したログ

[afcabde1-e77a-4423-a6ca-c8df795845f6] ActionController::RoutingError (No route matches [GET] "/v2/all/markets"): [afcabde1-e77a-4423-a6ca-c8df795845f6] [afcabde1-e77a-4423-a6ca-c8df795845f6] actionpack (6.0.3.4) lib/action_dispatch/middleware/debug_exceptions.rb:36:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] actionpack (6.0.3.4) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] railties (6.0.3.4) lib/rails/rack/logger.rb:37:in `call_app' [afcabde1-e77a-4423-a6ca-c8df795845f6] railties (6.0.3.4) lib/rails/rack/logger.rb:26:in `block in call' [afcabde1-e77a-4423-a6ca-c8df795845f6] activesupport (6.0.3.4) lib/active_support/tagged_logging.rb:80:in `block in tagged' [afcabde1-e77a-4423-a6ca-c8df795845f6] activesupport (6.0.3.4) lib/active_support/tagged_logging.rb:28:in `tagged' [afcabde1-e77a-4423-a6ca-c8df795845f6] activesupport (6.0.3.4) lib/active_support/tagged_logging.rb:80:in `tagged' [afcabde1-e77a-4423-a6ca-c8df795845f6] railties (6.0.3.4) lib/rails/rack/logger.rb:26:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] actionpack (6.0.3.4) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] actionpack (6.0.3.4) lib/action_dispatch/middleware/request_id.rb:27:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] rack (2.2.3) lib/rack/method_override.rb:24:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] rack (2.2.3) lib/rack/runtime.rb:22:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] activesupport (6.0.3.4) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] actionpack (6.0.3.4) lib/action_dispatch/middleware/executor.rb:14:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] actionpack (6.0.3.4) lib/action_dispatch/middleware/static.rb:126:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] rack (2.2.3) lib/rack/sendfile.rb:110:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] actionpack (6.0.3.4) lib/action_dispatch/middleware/host_authorization.rb:76:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] railties (6.0.3.4) lib/rails/engine.rb:527:in `call' [afcabde1-e77a-4423-a6ca-c8df795845f6] unicorn (5.4.1) lib/unicorn/http_server.rb:606:in `process_client' [afcabde1-e77a-4423-a6ca-c8df795845f6] unicorn (5.4.1) lib/unicorn/http_server.rb:701:in `worker_loop' [afcabde1-e77a-4423-a6ca-c8df795845f6] unicorn (5.4.1) lib/unicorn/http_server.rb:549:in `spawn_missing_workers' [afcabde1-e77a-4423-a6ca-c8df795845f6] unicorn (5.4.1) lib/unicorn/http_server.rb:142:in `start' [afcabde1-e77a-4423-a6ca-c8df795845f6] unicorn (5.4.1) bin/unicorn_rails:209:in `<top (required)>' [afcabde1-e77a-4423-a6ca-c8df795845f6] /home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `load' [afcabde1-e77a-4423-a6ca-c8df795845f6] /home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `<main>'

該当のソースコード

routes.rb

Rails.application.routes.draw do devise_for :users, controllers: { registrations: "users/registrations", :sessions => 'users/sessions', } devise_scope :user do get "sign_in", :to => "users/sessions#new" get "sign_out", :to => "users/sessions#destroy" post 'users/guest_sign_in', to: 'users/sessions#new_guest' end root to: "posts#index" resources :posts do resources :comments, only: [:create, :destroy] collection do get 'search' end end resources :users, only: [:show, :update, :edit, :destroy] end

users_controller.rb

class UsersController < ApplicationController def show @user = User.find(params[:id]) @post = current_user.posts end def edit @user = User.find(params[:id]) end def update if current_user.update(user_params) redirect_to root_path else render :edit end end private def user_params params.require(:user).permit(:name, :email, :description, :age, :gender, :avatar) end end

posts_controller.rb

class PostsController < ApplicationController def index @posts = Post.all.order(created_at: 'desc') @posts = params[:tag_id].present? ? Tag.find(params[:tag_id]).posts : Post.all @tag_lists = Tag.all @user = current_user end def new @post = Post.new end def create @post = Post.new(post_params) tag_list = params[:post][:tag_ids].split(',') if @post.valid? @post.save @post.save_tags(tag_list) redirect_to root_path else render :new end end def show @post = Post.find(params[:id]) @comment = Comment.new @comments = @post.comments.includes(:user) @user = current_user end def destroy post = Post.find(params[:id]) post.destroy redirect_to root_path end def edit @post = Post.find(params[:id]) end def update post = Post.find(params[:id]) post.update(post_params) end def search @posts = Post.search(params[:keyword]) @user = current_user end private def post_params params.require(:post).permit(:title, :text, :image, tag_ids: []).merge(user_id: current_user.id) end end

application_controller.rb

class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? private def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) devise_parameter_sanitizer.permit(:account_update, keys: [:name, :description, :age, :gender, :avatar]) end end

試したこと

ローカルの環境では問題なく動くので、本番環境に問題があると過程
自動デプロイ化をするためcapistranoを導入
導入前までは動いていることを確認できていたため、自動デプロイ化の作業に問題があるとおもい、作業内容を見直してみたが、原因がわからず。

エラーログにroutingエラーと出ているのを見かけたのでそのあたり疑って調べてみたのですが、何もわかりませんでした。

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

環境
rails 6.0.0
ruby 2.6.5p114
mysql (>= 0.4.4)
unicorn (= 5.4.1)
nginx
capistrano 3.15.0

###あとがき
自動デプロイも問題はなさそうなのですが、一向に開いてくれず何が原因化わからないまま2~3日過ぎてしまったので、どなたかわかる方いましたらお力をおかしください。

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

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

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

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

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

oakbow

2021/02/10 10:52

ActionController::RoutingError (No route matches [GET] "/v2/all/markets") というエラ〜メッセージが出ています。 この相対URLに該当するものが routes.rb にも他のコードにも全く見受けられず、Railsのバージョンも違うのですが、別のコードを見ていないでしょうか?
gannbaritai

2021/02/11 07:58

お返事ありがとうございます。 見るべきところが違うのでは? とゆうことでしょうか? logはEC2-userのproduction.logをみていました。 他に見るべきところがありましたらぜひご指摘お願いしてもよろしいでしょうか?
oakbow

2021/02/11 08:26

いえ。ログの内容と提示されているソースコードや環境が噛み合っていないので、食い違っているのでは?という話です。 ログのエラーメッセージはご覧になっていますか? 「GET で /v2/all/markets ってURLにアクセスしているけどそんなルーティング設定されてないよ」って言ってます。 routes.rbを見ても、そういうURLがあるようには見えません。 エラーログを見る限り Rails6.0.3.4を使っているようなんですが、環境として Rails6.0.0 と書いているのでこれも違いそうです。なので異なるアプリケーションのコード見てるとかじゃないのかな、という話をしています。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問