1
votes

I have ubuntu server, Rails 5.0 and apache web server Also I have many sites on it

When I add new site, I have an error "Incomplete response received from application"

When I check apache log I see message:

App 14561 stderr: [ 2017-01-17 21:01:16.5804 14591/0x0000000064e100(Worker 1) utils.rb:85 ]: *** Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) (process 14591, thread 0x0000000064e100(Worker 1)):

My config/secrets.yml contains default value:

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

Also I have just setted env variable SECRET_KEY_BASE via writting in a file /etc/profile

I see than via command echo $SECRET_KEY_BASE

How to fix error Incomplete response received from application

4
Read this about environment in rails railsapps.github.io/rails-environment-variables.htmlrails_id

4 Answers

2
votes

First, note that /etc/profile is only sourced when invoking an interactive login shell, so any variables set in this file wouldn't ever get run by a web-server daemon on startup, which is why it didn't work as expected in your attempt.

Since you're using Apache + Phusion Passenger, you can set application-specific environment variables within your Apache configuration files using the SetEnv option of mod_env.

Otherwise, you could set your environment variables from your application code by reading configuration on your application server's filesystem. You could use a gem like dotenv to automate this pattern.

See Phusion Passenger's documentation About Environment Variables: Passenger-Served Apps for a documentation reference.

2
votes

Try restarting your server, it might need to be restarted to pick up new changes in your config files.

Your config/secrets.yml file should also have:

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
1
votes

Depending on how you are starting the server the ENV variables may not be visible.

Have you tried:

SECRET_KEY_BASE='foo' rails s

Some discussion on environment variables with Rails servers is discussed at How to start Rails server with environment variables set?

0
votes

Check you have mod_env

sudo a2enmod env

From your rails app [anywhere, does not matter, it's just a random string] run

rake secret
... outputs a big long string ...

Then add to your Apache Virtual Host definition.

somewhere in /etc/apache2/sites-available/*.conf

<VirtualHost ...>
  SetEnv SECRET_KEY_BASE "thebiglongstringgeneratedbyrakesecret"
</VirtualHost>

Check your work

apache2ctl -t
Syntax OK

restart apache

apache2ctl restart

check it from the command line

curl https://my-server-url -I # or http 

Leave a comment if that does do the trick.