[英]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服务器的环境变量的一些讨论。
sudo a2enmod env
rake secret
... outputs a big long string ...
somewhere in /etc/apache2/sites-available/*.conf /etc/apache2/sites-available/*.conf中的某处
<VirtualHost ...>
SetEnv SECRET_KEY_BASE "thebiglongstringgeneratedbyrakesecret"
</VirtualHost>
apache2ctl -t
Syntax OK
apache2ctl restart
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.