A
A
Anton Misyagin2015-08-17 10:49:37
Nginx
Anton Misyagin, 2015-08-17 10:49:37

Missing `secret_token` and `secret_key_base` for production?

ubuntu server 14, rails 4.2, nginx

secrets.yml

development:
  secret_key_base: b44613bb3b3d5e5468d0c7e06903ea10f97044ac96b302882ad964e440945ccc20de8b1fe491ebcdd4a4a2feaaea7e52941b98b80c5094987a832d565d8e4de3

test:
  secret_key_base: cfb792181c7847dd953179f1916ee2f77a0938c148608ab37c0a934eb330dd39457918928d061457d5f10e278b9ea093ff1debbd3e906b4ce692fb54047cfedc

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

nginx/errors.log

App 1641 stderr: [ 2015-08-17 09:23:33.7944 1717/0x00000000a026e8(Worker 1) utils.rb:85 ]: *** Exception RuntimeError in Rack application object (Missing `secret_token` and `secret_key_base` for 'production' environment, set these values in `config/secrets.yml`) (process 1717, thread 0x00000000a026e8(Worker 1)):
App 1641 stderr: 	from /home/brainy_code/test_app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/application.rb:534:in `validate_secret_key_config!'
App 1641 stderr: 	from /home/brainy_code/test_app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/application.rb:246:in `env_config'
App 1641 stderr: 	from /home/brainy_code/test_app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/engine.rb:514:in `call'
App 1641 stderr: 	from /home/brainy_code/test_app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/application.rb:164:in `call'
App 1641 stderr: 	from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:94:in `process_request'
App 1641 stderr: 	from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:149:in `accept_and_process_next_request'
App 1641 stderr: 	from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
App 1641 stderr: 	from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads'
App 1641 stderr: 	from /usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:111:in `block in create_thread_and_abort_on_exception'
[ 2015-08-17 09:23:33.7965 1611/7f9617502700 age/Cor/Req/Utils.cpp:95 ]: [Client 1-1] Sending 502 response: application did not send a complete response

copied from test to production - everything worked.
secret_key_base:
cfb792181c7847dd953179f1916ee2f77a0938c148608ab37c0a934eb330dd39457918928d061457d5f10e278b9ea093ff1debbd3e906b4ce692fb54047cfedc

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mirilaczvili, 2015-08-17
@2ord

1. When ENV["SOMETHING"] is specified, it means to pass the SOMETHING parameter on the command line when starting the server. Since the environment variables were not set, the result is natural.
2. Pay attention to the foreman program
3. Reading the nginx documentation

N
Nikolai Markov, 2015-08-17
@manameiz

Never store security tokens in configs in a repository. You need to set them when starting the server via SECRET_TOKEN_BASE=<your token> <command to start the server>. For example: `SECRET_KEY_BASE=181c784 rails s`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question