[英]Rails5 app loses session after capistrano deploy to Passenger / Apache env, works fine on Rails 4
I manage a dozen or so Rails apps that all use Capistrano & Passenger.我管理着十几个使用 Capistrano & Passenger 的 Rails 应用程序。
I noticed that when I deploy an update to a Rails 5 app users get logged out, ie the session is lost.我注意到,当我将更新部署到 Rails 5 应用程序时,用户会注销,即 session 丢失了。 Apps that use Rails 4 or earlier don't, users stay logged in;使用 Rails 4 或更早版本的应用程序不会,用户保持登录状态; the session handling is all cookies in all cases (defaults).在所有情况下,session 处理都是 cookies(默认值)。
I this related to different versions of Rails or Passenger?我这与不同版本的 Rails 或乘客有关吗? Any ideas how to fix it?任何想法如何解决它?
Here is the deploy.rb piece:这是 deploy.rb 部分:
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :mkdir, '-p', "#{release_path}/tmp"
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
end
and I am using我正在使用
* capistrano (3.13.0)
* capistrano-bundler (1.6.0)
* capistrano-rails (1.1.8)
* capistrano-rails-console (2.3.0)
* capistrano-rvm (0.1.2)
To deploy: cap production deploy
部署: cap production deploy
Thanks in advance for your help.在此先感谢您的帮助。 Patrick帕特里克
I think my problem was due to a change in Rails 5.2, the introduction of master.key
and credentials.yml.enc
to take over from secrets.yml
我认为我的问题是由于 Rails 5.2 的变化,引入了master.key
和credentials.yml.enc
来接管secrets.yml
Because the Rails 5 app I created was using 5.2, the generator did not create a secrets.yml
file anymore - but also the master.key setting was not enabled:因为我创建的 Rails 5 应用程序使用的是 5.2,所以生成器不再创建secrets.yml
文件——而且 master.key 设置也没有启用:
# config.require_master_key = true
I assume that as a result of this Rails used some transient key to sign the cookies - which changed whenever the server was restarted.我假设由于这个原因,Rails 使用了一些临时密钥来签署 cookies - 只要服务器重新启动,它就会改变。
I have now re-added config/secrets.yml
to my project and from my testing it seems the problem has disappeared.我现在已经将config/secrets.yml
重新添加到我的项目中,从我的测试来看,问题似乎已经消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.