Question

Getting "Missing `secret_key_base` for 'production' environment" when trying to get Unicorn to work with Rails

Hi,

I’m tryihng to follow your tutorial for installing unicorn and getting it to work with nginx …

https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04

I have a file in ~/myproject/config/secrets.yml which contains

[code] development: secret_key_base: 547268978521e278fd572db969ce2d25cea9da7c6db4f7164942d02322177128704a4c76ed1f536dd7ac791b10ef0355b1928fb128077657bdef156472ad81

test: secret_key_base: c1aae665f8ed25da55a457870526dcac878d5a3734ab2fd29b4ec32b4b31bbe2f16d3b72bf0ca19286c1c88e4862d35f45c2c10140d990388e5e2184459cd23e

Do not keep production secrets in the repository,

instead read values from the environment.

production: secret_key_base: <%= ENV[“SECRET_KEY_BASE”] %>

[/code]

Yet when I restart nginx and unicorn and attempt to visit my web page, I get this error in my unicorn logs …

[code] E, [2017-04-09T22:37:34.736220 #11291] ERROR – : app error: Missing secret_key_base for ‘production’ environment, set this value in config/secrets.yml (RuntimeError) E, [2017-04-09T22:37:34.736414 #11291] ERROR – : /home/rails/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/application.rb:513:in validate_secret_key_config!' E, [2017-04-09T22:37:34.736462 #11291] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/application.rb:246:in env_config’ E, [2017-04-09T22:37:34.736491 #11291] ERROR – : /home/rails/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/engine.rb:693:in build_request' E, [2017-04-09T22:37:34.736515 #11291] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/application.rb:521:in build_request’ E, [2017-04-09T22:37:34.736541 #11291] ERROR – : /home/rails/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/engine.rb:521:in call' E, [2017-04-09T22:37:34.736646 #11291] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:562:in process_client’ E, [2017-04-09T22:37:34.736680 #11291] ERROR – : /home/rails/.gem/ruby/2.4.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:658:in worker_loop' E, [2017-04-09T22:37:34.736709 #11291] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:508:in spawn_missing_workers’ E, [2017-04-09T22:37:34.736738 #11291] ERROR – : /home/rails/.gem/ruby/2.4.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:132:in start' E, [2017-04-09T22:37:34.736767 #11291] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/unicorn-5.2.0/bin/unicorn:126:in <top (required)>’ E, [2017-04-09T22:37:34.736793 #11291] ERROR – : /home/rails/.gem/ruby/2.4.0/bin/unicorn:22:in load' E, [2017-04-09T22:37:34.736818 #11291] ERROR -- : /home/rails/.gem/ruby/2.4.0/bin/unicorn:22:in <top (required)>’ E, [2017-04-09T22:37:34.736842 #11291] ERROR – : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in load' E, [2017-04-09T22:37:34.736867 #11291] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in kernel_load’ E, [2017-04-09T22:37:34.736894 #11291] ERROR – : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:27:in run' E, [2017-04-09T22:37:34.736939 #11291] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:332:in exec’ E, [2017-04-09T22:37:34.736968 #11291] ERROR – : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in run' E, [2017-04-09T22:37:34.736996 #11291] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in invoke_command’ E, [2017-04-09T22:37:34.737021 #11291] ERROR – : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor.rb:359:in dispatch' E, [2017-04-09T22:37:34.737050 #11291] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:20:in dispatch’ E, [2017-04-09T22:37:34.737078 #11291] ERROR – : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/base.rb:440:in start' E, [2017-04-09T22:37:34.737106 #11291] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:11:in start’ E, [2017-04-09T22:37:34.737136 #11291] ERROR – : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/exe/bundle:34:in block in <top (required)>' E, [2017-04-09T22:37:34.737170 #11291] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:100:in with_friendly_errors’ E, [2017-04-09T22:37:34.737200 #11291] ERROR – : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/exe/bundle:26:in <top (required)>' E, [2017-04-09T22:37:34.737230 #11291] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/bin/bundle:22:in load’ E, [2017-04-09T22:37:34.737253 #11291] ERROR – : /usr/local/rvm/gems/ruby-2.4.0/bin/bundle:22:in <main>' E, [2017-04-09T22:37:34.737266 #11291] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in eval’ E, [2017-04-09T22:37:34.737280 #11291] ERROR – : /usr/local/rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>’ [/code]

What am I missing? What else do I need to do here?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @laredotornado6b

Did you following the Set Environment Variables? https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04#set-environment-variables

And please use the code-button in the toolbar to enclose code in three ticks - that makes it much easier to read.