【问题标题】:Openshift 500 internal server errorOpenshift 500 内部服务器错误
【发布时间】:2014-07-06 11:23:37
【问题描述】:

部署我的 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文件是一样的,只是生产是空的。

【问题讨论】:

  • 您的 secrets.yml 文件中有 secret_key_base 值吗?

标签: ruby-on-rails openshift


【解决方案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

【讨论】:

  • 谢谢,我检查了.gitignore,那个dile 不在里面。那么我该如何添加呢?
  • 那么您在本地计算机和服务器上都有这个文件吗?或者只是本地的,还是没有?
  • 我已经更新了我的问题,请查看我的.gitignore 文件。我不知道如何检查服务器上的文件。
  • 如果您可以在服务器上运行 rails 控制台,您可以执行system("cat #{Rails.root.join('config', 'secrets.yml')}") 它应该在服务器上显示此文件的内容,如果不存在则显示错误
  • 我再次更新了我的问题,我通过 SSH 检查了服务器上的该文件,并且生产密钥为空。我不知道为什么。
【解决方案2】:

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

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

与:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 2011-10-17
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多