Openshift 500内部服务器错误

时间:2014-05-18 12:24:09

标签: ruby-on-rails openshift

部署后我的rails应用程序(应用程序在本地机器上工作正常),我收到500内部服务器错误,我不知道有什么问题。我运行了rhc tail -a appname,因此会生成以下日志:

[ pid=422497 thr=12099720 file=utils.rb:176 time=2014-05-18 08:19:34.762 ]: *** Exception RuntimeError in Rack application object (Missing `secret_key
_base` for 'production' environment, set this value in `config/secrets.yml`) (process 422497, thread #<Thread:0x00000001714110>):
        from /var/lib/openshift/537858e95004463ce80005be/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/railties-4.1.0/lib/rails/application.rb:4
40:in `validate_secret_key_config!'
        from /var/lib/openshift/537858e95004463ce80005be/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/railties-4.1.0/lib/rails/application.rb:1
95:in `env_config'
        from /var/lib/openshift/537858e95004463ce80005be/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/railties-4.1.0/lib/rails/engine.rb:510:in
 `call'
        from /var/lib/openshift/537858e95004463ce80005be/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/railties-4.1.0/lib/rails/application.rb:1
44:in `call'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/rack/request_handler.rb:97:in `process_request'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/abstract_request_handler.rb:521:in `accept_and_process_ne
xt_request'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler
'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/rack/application_spawner.rb:79:in `block in spawn_applica
tion'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/utils.rb:470:in `safe_fork'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/rack/application_spawner.rb:64:in `spawn_application'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/spawn_manager.rb:264:in `spawn_rack_application'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
        from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.21/helper-scripts/passenger-spawn-server:102:in `<main>'
[Sun May 18 08:19:34 2014] [error] [client 127.12.212.1] Premature end of script headers:
[ pid=422225 thr=140352120211424 file=ext/apache2/Hooks.cpp:841 time=2014-05-18 08:19:34.762 ]: The backend application (process 422497) did not send
a valid HTTP response; instead, it sent nothing at all. It is possible that it has crashed; please check whether there are crashing bugs in this appli
cation.

173.244.197.108 - - [18/May/2014:08:19:34 -0400] "GET / HTTP/1.1" 500 631 "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/34.0.1847.137 Safari/537.36"
173.244.197.108 - - [18/May/2014:08:19:40 -0400] "GET /favicon.ico HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like G
ecko) Chrome/34.0.1847.137 Safari/537.36"

我的.gitignore文件:

# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp

secrets.yml本地文件:

# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.

# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.

development:
  secret_key_base: 374b50a3e7af4ac3c8805c7706a239c32e6885a9e0b4331ce0930e341f740c4a700b932166a473ff129cfdcfbbb156b2b75911fafac71

test:
  secret_key_base: 6bb2c6ac59f9857f5ed5bb11e42cfdacb29f91e8e80fd27362ff7eb06e0e53590be74a8f515ca7c3a6820904d75f55c56d12f2d4f1f7f2

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

secrets.yml文件是相同的,只是生产是空的。

2 个答案:

答案 0 :(得分:4)

尝试替换config/secrets.yml中的以下行:

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

使用:

 secret_key_base: <%=ENV['OPENSHIFT_SECRET_TOKEN']%>

答案 1 :(得分:1)

事实证明,您的secrets.yml需要在生产环境变量中设置secret_key_base

您可以在OpenShift指南之后执行此操作:https://www.openshift.com/developers/openshift-environment-variables

由于我不使用OpenShift,你必须自己解决这个问题。

编辑:另请查看此博文https://www.openshift.com/blogs/taking-advantage-of-environment-variables-in-openshift-php-apps