SemiFixed: Missing `secret_key_base` for 'production' environment

后端 未结 3 1926
無奈伤痛
無奈伤痛 2021-01-05 02:18

I\'ve created a rails app (Rails 4.1.0) from scratch and I am getting a problem that I am not able to solve. I have installed and configured Apache Passenger Module, it work

相关标签:
3条回答
  • 2021-01-05 02:29

    Rails app secret key via bash

    If you have access to the bashconsole of the user that is running the rails app, and if you are not using thin, then you could provide the environment variable via the users ~/.bashrc

    just add the following:

    export SECRET_KEY_BASE=`MY_SECRET_KEY`
    

    Note: MY_SECRET_KEY could be anything but it would be secure to generate a key with rake secret on the bash console substitute that key with "MY_SECRET_KEY" from the example.

    Once you have done that you should see a SECRET_KEY_BASE variable in the hash which is returned when you call ENV in your rails console.

    Last but not least, reboot your rails app and the error should disappear.

    Rails app secret key per rbenv-vars

    Further, if you are using rbenv, you can use the rbenv-vars plugin to achive a per rails app secret key environment variable.

    A good read on this would be here!

    Using god (godrb.com): thanks hlcs

    You need to god terminate and then start again.

    0 讨论(0)
  • 2021-01-05 02:35

    What I did : On my production server, I create a config file (confthin.yml) for Thin (I'm using it) and add the following information :

    environment: production user: www-data group: www-data SECRET_KEY_BASE: mysecretkeyproduction

    I then launch the app with

    thin start -C /whereeveristhefieonprod/configthin.yml

    Work like a charm and then no need to have the secret key on version control

    Hope it could help, but I'm sure the same thing could be done with Unicorn and others.

    0 讨论(0)
  • 2021-01-05 02:53

    I solved a similar situation with this (perhaps only useful in Ubuntu-like environment). See: Missing secret key base for production environment. Hope it helps.

    0 讨论(0)
提交回复
热议问题