0

I have successfully installed rails with Passenger+Nginx but am experiencing an Incomplete response error via the web browser:

http://tenklakes.northcentralus.cloudapp.azure.com/

I have tried rake secrets to generate a new secret_key_base for production in my secrets.yml file with no luck.

Secrets.yml :

development: secret_key_base:c70c590cfe799087c47528016ab49a1a8e57fe2eb851639e27e2ea66f92f241a0400b3d4247e3d61a6c82818dd3988825deeb66e783ba90cfccfbc0c500d6dbd

test: secret_key_base: 08b1ebf5defee2eb1ad196e9780ae118f256c9f40f40f76674451dac4dfb1c42b75f04d22ee264644711de4e547ac8f58031e88f09c5c7223834b99230fb205c

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

when I run curl http:0.0.0.0:3000 I receive the following from Passenger:

Started GET "/" for 127.0.0.1 at 2016-10-09 04:52:43 +0000 Processing by Rails::WelcomeController#index as */* Parameters: {"internal"=>true} Rendering /home/garrett/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb Rendered /home/garrett/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb (2.5ms) Completed 200 OK in 10ms (Views: 6.2ms | ActiveRecord: 0.0ms)

NGINX error.log :

[ 2016-10-09 04:49:44.8271 45647/7fe3b30d4700 age/Cor/Con/InternalUtils.cpp:112 ]: [Client 1-3] Sending 502 response: application did not send a complete response App 45674 stderr: [ 2016-10-09 04:49:56.0108 45754/0x0000000092d678(Worker 1) utils.rb:87 ]: *** Exception RuntimeError in Rack application object (Missing secret_key_base for 'production' environment, set this value in config/secrets.yml) (process 45754, thread 0x0000000092d678(Worker 1)): App 45674 stderr: from /home/garrett/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:513:in validate_secret_key_config!' App 45674 stderr: from /home/garrett/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:246:inenv_config' App 45674 stderr: from /home/garrett/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:693:in build_request' App 45674 stderr: from /home/garrett/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:521:inbuild_request' App 45674 stderr: from /home/garrett/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:521:in call' App 45674 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:inprocess_request' App 45674 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:152:in accept_and_process_next_request' App 45674 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:113:inmain_loop' App 45674 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:416:in block (3 levels) in start_threads' App 45674 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:inblock in create_thread_and_abort_on_exception'

I am out of ideas to get this working - is there anything else I should be checking?

EDIT: Here is what I get when running 'grep -r ENV *'

garrett@10klakes:~/lakemag$ grep -r ENV *
bin/bundle:ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
config/database.yml:  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
config/database.yml:#     url: <%= ENV['DATABASE_URL'] %>
config/database.yml:  password: <%= ENV['LAKEMAG_DATABASE_PASSWORD'] %>
config/puma.rb:threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
config/puma.rb:port        ENV.fetch("PORT") { 3000 }
config/puma.rb:environment ENV.fetch("RAILS_ENV") { "development" }
config/puma.rb:# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
config/environments/production.rb:  # config.secret_key_base =   ENV["SECRET_KEY_BASE"]
config/environments/production.rb:  config.secret_key_base = ENV["SECRET_KEY_BASE"]
config/environments/production.rb:  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config/environments/production.rb:  if ENV["RAILS_LOG_TO_STDOUT"].present?
config/boot.rb:ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
config/secrets.yml:  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

test/test_helper.rb:ENV['RAILS_ENV'] ||= 'test'

GarrettG
  • 44
  • 2
  • 9
  • To solve this issue check https://stackoverflow.com/questions/30395157/incomplete-response-received-from-application/47234911#47234911 – Hitesh Ranaut Nov 11 '17 at 06:02

2 Answers2

0

For production mode you have to set all ENV (environment) variables named in any ruby or config file. For example within secrets.yml Rails expects an environment variable SECRET_KEY_BASE. You didn't set this variable and now Rails does not start up in production mode.

You are using asure as hosting provider. So you can follow this post to setup environment variables for azure. In short:

Add a app setting in "App settings" section

You can use rake secret to generate a new key and use it for the environment variable.

One more hint. secrets.yml has its name for a reason. You should not post secrets from this file.

Community
  • 1
  • 1
slowjack2k
  • 2,566
  • 1
  • 15
  • 23
  • Thanks for the response, Jack! Would this still be the case if I am not running rails in a cloud instance, but in a standalone VM? – GarrettG Oct 10 '16 at 10:38
  • Yes, it's recommended for production to use environment variables for confidential settings. This way confidential settings don't go into your repo. Further more it has some advantages for deployment (have a look https://12factor.net/). If you want, you can replace all `ENV` entries within your code, but I would recommend against it. – slowjack2k Oct 10 '16 at 11:27
  • Hi Jack. Which files should I be looking at to remedy my problem? – GarrettG Oct 11 '16 at 20:38
  • I don't know. Try `grep -r ENV *` wihtin your `Rails.root`. – slowjack2k Oct 11 '16 at 20:45
  • It seems like you have to setup `ENV["SECRET_KEY_BASE"]` , `ENV['LAKEMAG_DATABASE_PASSWORD']` and maybe `ENV['PORT']` – slowjack2k Oct 24 '16 at 10:46
0

After much research the problem was in the hba_config file. md5 permissions needed to be set to "trust" instead.

I am not sure if this solution is a "complete" fix, but it worked in my case.

GarrettG
  • 44
  • 2
  • 9
  • Hey there! I'm having the same issue but I don't have hba_config file. Is that a generic file or did you create that file? Thank you in advance. – Rodrigo Ibarra Jul 04 '23 at 18:50