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

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

新規登録して質問してみよう
ただいま回答率
85.48%
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、上で動作します。

VPS

VPS(バーチャル・プライベート・サーバ)は、仮想化されたサーバをレンタルするサービスで、共有サーバでありながら専門サーバと同等の機能を果たします。物理的な専門サーバより安価で提供できるメリットがあります。

Q&A

解決済

1回答

485閲覧

config/secrets.ymlについてご教授お願いいたします。

koume

総合スコア458

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、上で動作します。

VPS

VPS(バーチャル・プライベート・サーバ)は、仮想化されたサーバをレンタルするサービスで、共有サーバでありながら専門サーバと同等の機能を果たします。物理的な専門サーバより安価で提供できるメリットがあります。

0グッド

1クリップ

投稿2019/08/18 12:14

Railsアプリをデプロイしました。デプロイ自体は上手くいったのですが、
ページが表示されなかったのでunicorn.logをみたところ以下のようなエラ-がありました。

unicorn.log E, [2019-08-18T20:48:46.103173 #25913] ERROR -- : app error: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError) E, [2019-08-18T20:48:46.103988 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/railties-5.1.7/lib/rails/application.rb:510:in `validate_secret_key_config!' E, [2019-08-18T20:48:46.104156 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/railties-5.1.7/lib/rails/application.rb:247:in `env_config' E, [2019-08-18T20:48:46.104202 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/railties-5.1.7/lib/rails/engine.rb:692:in `build_request' E, [2019-08-18T20:48:46.104234 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/railties-5.1.7/lib/rails/application.rb:518:in `build_request' E, [2019-08-18T20:48:46.104277 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/railties-5.1.7/lib/rails/engine.rb:521:in `call' E, [2019-08-18T20:48:46.104338 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/unicorn-5.5.1/lib/unicorn/http_server.rb:605:in `process_client' E, [2019-08-18T20:48:46.104405 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/unicorn-5.5.1/lib/unicorn/http_server.rb:700:in `worker_loop' E, [2019-08-18T20:48:46.104446 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/unicorn-5.5.1/lib/unicorn/http_server.rb:548:in `spawn_missing_workers' E, [2019-08-18T20:48:46.104475 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/unicorn-5.5.1/lib/unicorn/http_server.rb:144:in `start' E, [2019-08-18T20:48:46.104523 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/gems/unicorn-5.5.1/bin/unicorn:128:in `<top (required)>' E, [2019-08-18T20:48:46.104553 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/bin/unicorn:23:in `load' E, [2019-08-18T20:48:46.104581 #25913] ERROR -- : /usr/share/nginx/html/shared/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'

productionのsecret_key_base が見つかりません。と言う内容でしたので
改めて作成しました。

config/secrets.yml production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> .env SECRET_KEY_BASE = XXXXXXXXXXXX4b631eb93ccc0a5c7df7bXXXXXXXXaadf39dbf8a1c77e0ffce6XXXXXXXXXXXXXXXX

そして再度アクセスしても同じエラーが発生してしまいます。
ほかに設定する項目等あるのでしょうか?
業ジュノほど、宜しくお願いいたします。

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

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

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

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

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

8zca

2019/08/18 13:19

.envから環境変数を読み込みされていますが、 dotenv-railsのgemはインストール済でしょうか?
koume

2019/08/18 13:39

ご返事ありがとうございます。 dotenv-railsのgemはインストール済です。 unicornの再起動などが必要なのでしょうか?
8zca

2019/08/18 13:47

そうですね、再起動しないとconfigを読み込み直してくれないので、再起動で直ると思いますよ。
koume

2019/08/18 13:53

回答ありがとうございます。 unicornを再起動しましたがエラーがでてしまいます。 # bin/rake unicorn:start rake aborted! Don't know how to build task 'unicorn:start' (See the list of available tasks with `rake --tasks`) (See full trace by running task with --trace) unicorn:startと言うタスクはありません。と言われてしまいます。 タスクを設定するにはどうしたらいいのでしょうか?
koume

2019/08/18 14:02

タスクの一覧を表示してみましたがその中にはありませんでした。 # bundle exec rake -T rake about # List versions of all Rails frameworks and the environment rake app:template # Applies the template supplied by LOCATION=(/path/to/template) or URL rake app:update # Update configs and some other initially generated files (or use just up... rake assets:clean[keep] # Remove old compiled assets rake assets:clobber # Remove compiled assets rake assets:environment # Load asset compile environment rake assets:precompile # Compile all the assets named in config.assets.precompile rake cache_digests:dependencies # Lookup first-level dependencies for TEMPLATE (like messages/show or com... rake cache_digests:nested_dependencies # Lookup nested dependencies for TEMPLATE (like messages/show or comments... rake db:create # Creates the database from DATABASE_URL or config/database.yml for the c... rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the cur... rake db:environment:set # Set the environment value for the database rake db:fixtures:load # Loads fixtures into the current environment's database rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog) rake db:migrate:status # Display status of migrations rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n) rake db:schema:cache:clear # Clears a db/schema_cache.yml file rake db:schema:cache:dump # Creates a db/schema_cache.yml file rake db:schema:dump # Creates a db/schema.rb file that is portable against any DB supported b... rake db:schema:load # Loads a schema.rb file into the database rake db:seed # Loads the seed data from db/seeds.rb rake db:setup # Creates the database, loads the schema, and initializes with the seed d... rake db:structure:dump # Dumps the database structure to db/structure.sql rake db:structure:load # Recreates the databases from the structure.sql file rake db:version # Retrieves the current schema version number rake dev:cache # Toggle development mode caching on/off rake initializers # Print out all defined initializers in the order they are invoked by Rails rake log:clear # Truncates all/specified *.log files in log/ to zero bytes (specify whic... rake middleware # Prints out your Rack middleware stack rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus) rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM rake restart # Restart app by touching tmp/restart.txt rake routes # Print out all defined routes in match order, with names rake secret # Generate a cryptographically secure secret key (this is typically used ... rake stats # Report code statistics (KLOCs, etc) from the application or engine rake test # Runs all tests in test folder except system ones rake test:db # Run tests quickly, but also reset db rake test:system # Run system tests only rake time:zones[country_or_offset] # List all time zones, list by two-letter country code (`rails time:zones... rake tmp:clear # Clear cache and socket files from tmp/ (narrow w/ tmp:cache:clear, tmp:... rake tmp:create # Creates tmp directories for cache, sockets, and pids rake yarn:install # Install all JavaScript dependencies as specified via Yarn
koume

2019/08/18 15:36

上手くいきませんが、たぶんunicornを再起動させることができれば 大丈夫だと思います。
8zca

2019/08/18 15:49

もし kill -HUP `cat /path/to/unicorn.pid` をそのまま実行されている場合の補足です。 再起動コマンドの/path/toのところは環境によって異なりますので、config/unicorn.rbを確認してみてください。
koume

2019/08/18 16:14

ご丁寧にありがとうございます。 config/unicorn/production.rbの設定です(抜粋) $app_dir = "/usr/share/nginx/html/current" $listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir なので kill -HUP `cat /usr/share/nginx/html/current/tmp/pids/unicorn.pid` で実行してみました。 なにも表示されませんでした。(これでいいのかわからずに再度アクセス) やはり変わらず同じエラーが出てしまいます。 いろいろなサイトで調べてみましたが、どれもnicornの再起動で上手くいきますと言うような内容でした。 unicornの再起動が上手くいっていないのが原因だとおもいますが、 kill -HUP `cat /usr/share/nginx/html/current/tmp/pids/unicorn.pid`がまちがっているのでしょうか?
8zca

2019/08/19 00:06

停止はちゃんとできますか? kill -QUIT `cat pidのファイルのパス` 停止されたかを確認(unicornが見つからないことを確認) ps -ef | grep unicorn | grep -v grep 起動 bundle exec unicorn -E production -c unicorn.rbのパス -D プロセスが立ち上がっていることを確認 ps -ef | grep unicorn | grep -v grep
koume

2019/08/19 00:14

回答ありがとうございます。 おかげさまでページの表示ができました。 今後とも宜しくお願いいたします。
guest

回答1

0

自己解決

8zca様のご教授により解決出来無事にページの表示ができました。
やったこと
一度unicornを停止し、停止しているか確認し、再度起動し、起動の確認です。
コードは以下になります。
$ kill -QUIT cat /usr/share/nginx/html/current//tmp/pids/unicorn.pid

$ ps -ef | grep unicorn | grep -v grep #停止確認

$ bundle exec unicorn -E production -c config/unicorn/production.rb -D #unicorn起動

$ ps -ef | grep unicorn | grep -v grep #プロセスの表示確認

アクセスしてみる。

これでページが表示できました。

投稿2019/08/19 00:26

koume

総合スコア458

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

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

8zca

2019/08/19 14:35

よかったですね!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問