服务器上的 Rails 会话

发布于 2024-07-06 10:27:33 字数 107 浏览 7 评论 0原文

我想让一些 Rails 应用程序在不同的服务器上共享同一个会话。 我可以在同一服务器内完成此操作,但不知道是否可以在不同服务器上共享。 有人已经做过或者知道怎么做吗?

谢谢

I'd like to have some rails apps over different servers sharing the same session. I can do it within the same server but don't know if it is possible to share over different servers. Anyone already did or knows how to do it?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我最亲爱的 2024-07-13 10:27:33

使用数据库会话存储。 它的缺点是:

要生成表,请在控制台运行

rake db:sessions:create 
  

在您的环境.rb中,包含此行

config.action_controller.session_store = :active_record_store 
  

Use the Database Session store. The short of it is this:

To generate the table, at the console, run

rake db:sessions:create

in your environment.rb, include this line

config.action_controller.session_store = :active_record_store
穿越时光隧道 2024-07-13 10:27:33

根据应用程序的设置方式,您可以通过将应用程序设置为使用相同的密钥,轻松共享来自同一域(foo.domain、bar.domain、domain)中的站点的 Cookie:
http://www.russellquinn.com/2008/01/30 /multiple-rails-applications/

现在,如果您有不同的站点,例如 sdfsf.com、dsfsadfsdafdsaf.com 等,您将不得不采取更多技巧,因为 cookie 的本质限制了它们特定域。 本质上,您想要做的是使用跨站点脚本,而不是劫持您的会话,而是从其他会话中读取它。

在这种情况下,结合使用相同的 cookie 秘密等,然后使用一些跨站点脚本,您可以手动提取会话信息并在每个站点上重新创建它(或者如果您使用 ActiveRecord 会话{或 NFS 会话目录},链接与现有的一致)。 这并不容易,但可以做到。

或者,技术含量较低的方法(我以前做过)只是让登录页面访问每个站点上特制的登录页面,该页面上设置了应用程序 cookie 并将您跳转到下一个站点。 这并不漂亮。

Depending on how your app is set up, you can easily share cookies from sites in the same domain (foo.domain, bar.domain, domain) by setting your apps up to use the same secret:
http://www.russellquinn.com/2008/01/30/multiple-rails-applications/

Now, if you have disparate sites, such as sdfsf.com, dsfsadfsdafdsaf.com, etc. you'll have to do a lot more tricks because the very nature of cookies restricts them to the specific domain. Essentially what you're trying to do is use cross-site scripting to, instead of hijack your session, read it from the other ones.

In that case, a combination of using the same cookie secret etc and then some cross-site scripting you can manually extract the session info and re-create it on each site (or if you use ActiveRecord session {or NFS session dir}, link up with the existing one). It's not easy, but it can be done.

Or, the low-tech way (which I've done before) is simply have the login page visit a specially crafted login page on each site that sets an app cookie on it and bounces you to the next one. It isn't pretty.

残疾 2024-07-13 10:27:33

尝试使用数据库支持的会话。

Try using database-backed sessions.

在你怀里撒娇 2024-07-13 10:27:33

在 Rails 2.0 中,现在有一个 CookieStore,它将所有会话数据存储在客户端计算机上的加密 cookie 中。

http ://izumi.plan99.net/blog/index.php/2007/11/25/rails-20-cookie-session-store-and-security/

In Rails 2.0 there is now a CookieStore that stores all session data in an encrypted cookie on the client's machine.

http://izumi.plan99.net/blog/index.php/2007/11/25/rails-20-cookie-session-store-and-security/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文