secret_key_base missing and nginx restart fails

June 13, 2015 715 views
Nginx Ruby on Rails Deployment Ubuntu

I followed this guide: to set up my application.

Now I have a few errors:

1)When I do service nginx restart, it fails. When I do sudo nginx -t it says everything is fine.

2)When I go to my website, I get Incomplete response received from application.

When I looked into the logs, it says that secret_key_base is missing. However, I have hard coded in shared/config/secrets.yml the secret key so I'm not sure what is going on.


1 Answer

The first step to debugging the Nginx issue is to check the error logs. You can see the most recent entries with:

  • tail /var/log/nginx/error.log

By default, Rails project will hard code the secret_key_base for the test and development environments in config/secrets.yml The value for production is stored as the SECRET_KEY_BASE environmental variable:

  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

Have you hardcoded it for production as well? The first thing I'd double check is what environment the application is starting in. If you are using Unicorn as your application server with an init script to start and stop it, a common practice is to set the RAILS_ENV in /etc/default/unicorn which the init script sources.

Have another answer? Share your knowledge.