58
55

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

production環境でsecret_tokenをセットする(rails)

Last updated at Posted at 2016-06-12

config/secrets.ymlにてsecret_key_baseを設定しないと
『app error: Missing secret_token and secret_key_base for 'production' environment, set these values in config/secrets.yml (RuntimeError)』
と怒られる。

production環境でsecret_key_baseをセットする方法

config/secrets.ymlの中身

secrets.yml
# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.

# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.

development:
  secret_key_base: aca69c863386b8b18bea7baef237fc1f5c7328d4765abf04de32119de7c6c5f1b7880a7bc259a455fd9659494c2b2a799ba285b4e5581322f919cc2f5d544354

test:
  secret_key_base: 47df8937b0b175ae7c5e297c69153c7cb0e675e6ad485039cbd9313b8ba39a41259d4ccef4f5c8033db20b643ab0dd687808bc8503750c6c87968711ca4

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

keyを生成

$ bundle exec rake secret
qnaiglfmugm82487yfam7y4qixm8734pt7bfdac6622iou9x74pof904r77ed64ba5a8c4r3qoi5u948x3q7n0q98q7089qm398

環境変数に設定

$export SECRET_KEY_BASE=
qnaiglfmugm82487yfam7y4qixm8734pt7bfdac6622iou9x74pof904r77ed64ba5a8c4r3qoi5u948x3q7n0q98q7089qm398

これでOK

58
55
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
58
55

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?