简体   繁体   English

Rails在生产中缺少SECRET_KEY_BASE

[英]Rails missing SECRET_KEY_BASE in production

I have ubuntu server, Rails 5.0 and apache web server Also I have many sites on it 我有ubuntu服务器,Rails 5.0和apache Web服务器,也有很多网站

When I add new site, I have an error "Incomplete response received from application" 添加新站点时,出现错误“从应用程序收到的响应不完整”

When I check apache log I see message: 当我检查apache日志时,我看到消息:

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: 我的config / secrets.yml包含默认值:

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

Also I have just setted env variable SECRET_KEY_BASE via writting in a file /etc/profile 我还通过写在文件/ etc / profile中设置了环境变量SECRET_KEY_BASE

I see than via command echo $SECRET_KEY_BASE 我比通过命令echo $SECRET_KEY_BASE看到

How to fix error Incomplete response received from application 如何修复错误, Incomplete response received from application

Try restarting your server, it might need to be restarted to pick up new changes in your config files. 尝试重新启动服务器,可能需要重新启动服务器才能在config文件中进行新更改。

Your config/secrets.yml file should also have: 您的config / secrets.yml文件还应具有:

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

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. 首先,请注意, /etc/profile仅在调用交互式登录shell时提供,因此在启动时该文件中设置的任何变量都不会由网络服务器守护程序运行,这就是为什么它无法按预期运行的原因在您的尝试中。

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 . 由于您使用的Apache +的Phusion客运,您可以使用您的Apache配置文件中设置应用程序特定的环境变量SetEnv的选项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. 您可以使用dotenv类的dotenv来自动执行此模式。

See Phusion Passenger's documentation About Environment Variables: Passenger-Served Apps for a documentation reference. 有关文档参考,请参见Phusion Passenger的关于环境变量的文档:乘客服务的应用程序

Depending on how you are starting the server the ENV variables may not be visible. 根据您启动服务器的方式,ENV变量可能不可见。

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? 如何在设置了环境变量的情况下启动Rails服务器,讨论了有关使用Rails服务器的环境变量的一些讨论

Check you have mod_env 检查你是否有mod_env

sudo a2enmod env

From your rails app [anywhere, does not matter, it's just a random string] run 从您的rails应用程序[无处不在,这只是一个随机字符串]运行

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

Then add to your Apache Virtual Host definition. 然后添加到您的Apache虚拟主机定义。

somewhere in /etc/apache2/sites-available/*.conf /etc/apache2/sites-available/*.conf中的某处

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

Check your work 检查你的工作

apache2ctl -t
Syntax OK

restart apache 重新启动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. 如果有帮助,请发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在rails生产中缺少secret_key_base - Missing secret_key_base in rails production rails 中缺少生产 secret_key_base - Missing production secret_key_base in rails Rails,在使用unicorn和nginx的Ubuntu上缺少“生产”的“ secret_key_base” - Rails, Missing `secret_key_base` for 'production' on Ubuntu with unicorn and nginx ruby on rails:heroku:“生产”环境缺少“secret_key_base” - ruby on rails: heroku: Missing `secret_key_base` for 'production' environment Rails:如何修复“生产环境中缺少 secret_key_base” - Rails: How to fix “Missing secret_key_base for 'production' environment” SECRET_KEY_BASE 缺少生产错误 - SECRET_KEY_BASE missing error on production 缺少&#39;secret_token`和`secret_key_base`用于&#39;生产&#39;环境 - Missing `secret_token` and `secret_key_base` for 'production' environment Ubuntu 18.04 服务器(Rails 6.0)上的“生产”环境缺少“secret_key_base”,尝试了多个主题 - Missing `secret_key_base` for 'production' environment on Ubuntu 18.04 server (Rails 6.0), multiple topics tried 如何解决错误“‘生产’环境缺少‘secret_key_base’”(Rails 4.1) - How to solve error “Missing `secret_key_base` for 'production' environment” (Rails 4.1) “缺少&#39;secret_key_base`为&#39;生产&#39;环境”Heroku上的错误 - “Missing `secret_key_base` for 'production' environment” error on Heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM