SemiFixed:“生产"环境缺少“secret_key_base" [英] SemiFixed: Missing `secret_key_base` for 'production' environment

查看:23
本文介绍了SemiFixed:“生产"环境缺少“secret_key_base"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从头开始创建了一个 rails 应用程序(Rails 4.1.0),但遇到了一个我无法解决的问题.我已经安装并配置了 Apache 乘客模块,它工作正常.每当我尝试访问虚拟主机时,都会收到错误 500:

I've created a rails app (Rails 4.1.0) from scratch and I am getting a problem that I am not able to solve. I have installed and configured Apache Passenger Module, it works fine. Any time I try to access the virtual host I get an error 500:

Missing secret_key_base for 'production' environment, set this value in config/secrets.yml

secret.yml 文件包含以下配置:

The secret.yml file contains the following configuration:

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

即使不推荐我这样做:

    production:
  secret_key_base: XXXXXXXXXXXXXXXXXXXXXXXXXXXX (random key)

但 Apache 日志显示:

But Apache logs show this:

# tailf /etc/httpd/logs/error_log
[Tue May 06 12:56:18 2014] [error] [client 192.168.3.1] Premature end of script headers:
App 4405 stderr: [ 2014-05-06 12:56:18.5763 4421/0x9d48bdc(Worker 1) utils.rb:68 ]: *** Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) (process 4421, thread 0x9d48bdc(Worker 1)):
App 4405 stderr:        from /usr/local/rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/application.rb:440:in `validate_secret_key_config!'
App 4405 stderr:        from /usr/local/rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/application.rb:195:in `env_config'
App 4405 stderr:        from /usr/local/rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/engine.rb:510:in `call'
App 4405 stderr:        from /usr/local/rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/application.rb:144:in `call'
App 4405 stderr:        from /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
App 4405 stderr:        from /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
App 4405 stderr:        from /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
App 4405 stderr:        from /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/lib/phusion_passenger/request_handler.rb:448:in `block (3 levels) in start_threads'

我该如何解决这个错误?如何进入开发环境?我的意思是如何编写代码、在浏览器中进行测试然后部署到 Heroku 或仅在生产环境中进行测试?

How I can fix this error? How do I access the development enviroment? I mean how I can write code, test in my browser and then deploy to Heroku or just test in production enviroment?

更新

我设法通过在 VirtualHost 上设置 RailsEnv development 来修复上述错误,但现在我遇到了另一个错误:

I manage to fix the error above by setting RailsEnv development on VirtualHost but now I get this other error:

SQLite3::CantOpenException 无法打开数据库文件Rails.root:/var/www/html/moviedb

SQLite3::CantOpenException unable to open database file Rails.root: /var/www/html/moviedb

我正在尝试使用这个 GEM 来查询 TheMovieDB 网站并获得结果.关于这个新错误有什么建议吗?

I'm trying to use this GEM for make queries to TheMovieDB website and get results. Any advice on this new error?

推荐答案

我所做的:在我的生产服务器上,我为 Thin(我正在使用它)创建了一个配置文件 (confthin.yml) 并添加以下信息:

What I did : On my production server, I create a config file (confthin.yml) for Thin (I'm using it) and add the following information :

环境:生产用户:www-data组:www-dataSECRET_KEY_BASE:mysecretkeyproduction

environment: production user: www-data group: www-data SECRET_KEY_BASE: mysecretkeyproduction

然后我用

thin start -C/whereeveristhefieonprod/configthin.yml

thin start -C /whereeveristhefieonprod/configthin.yml

像魅力一样工作,然后不需要在版本控制上拥有密钥

Work like a charm and then no need to have the secret key on version control

希望它会有所帮助,但我相信 Unicorn 和其他公司也可以做同样的事情.

Hope it could help, but I'm sure the same thing could be done with Unicorn and others.

这篇关于SemiFixed:“生产"环境缺少“secret_key_base"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆