简体   繁体   English

Rails-Elastic Beanstalk AWS-会话未维护

[英]Rails - Elastic Beanstalk AWS - sessions not maintained

I just deployed a Rails 3.2.17 app to AWS Elastic Beanstalk. 我刚刚将Rails 3.2.17应用程序部署到了AWS Elastic Beanstalk。

I was first unable to login to the application (we use Devise) and kept getting WARNING: Can't verify CSRF token authenticity in the logs. 我首先无法登录到该应用程序(我们使用Devise),并一直得到WARNING: Can't verify CSRF token authenticity在日志中WARNING: Can't verify CSRF token authenticity

Then when I tried to see the session in the Chrome developer tools, there was no cookies set for the application which is super weird. 然后,当我尝试在Chrome开发人员工具中查看该会话时,没有为该应用程序设置Cookie,这太奇怪了。

Then I tried printing out the session has from the ApplicationController and every time I got different session_id . 然后我尝试打印出ApplicationControllersession ,并且每次我获得不同的session_id

{"session_id"=>"e0f2ccf03d07f48def5c4fbb872f2c0c", "last_action_time"=>Wed, 23 Sep 2015 08:40:09 EDT -04:00, "test"=>"test"}
....
 {"session_id"=>"0f9ef3aaf150619ac408da2bac4f51ae", "last_action_time"=>Wed, 23 Sep 2015 08:43:24 EDT -04:00, "test"=>"test"}

This is in my session_store.rb : 这是在我的session_store.rb

MyApp::Application.config.session_store :cookie_store, key: ENV['SESSION_NAME'], domain: :all

Do I need to do anything else? 我还需要做其他事情吗? Thanks! 谢谢! This app works fine in a single EC2 instance (staging environment). 这个应用程式可以在一个EC2执行个体(暂存环境)中正常运作。

The domain: :all was the culprit. domain: :all是罪魁祸首。 It assumes TLD lenght is 1 and mine was not. 假设TLD长度为1,而我的不是。 Removed it and things went back to normal. 删除它,一切恢复正常。 If you want to maintain session across subdomains (the purpose for domain: :all ), you can specify the domain explicity. 如果要跨子域维护会话( domain: :all的目的domain: :all ),则可以指定域的显式性。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM