如果我要将Play Framework应用程式部署到多台伺服器,该怎么办? [英] What should I do if I want to deploy Play Framework app to multiple servers?

查看:150
本文介绍了如果我要将Play Framework应用程式部署到多台伺服器,该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想使用Play Framework 2.x将我的应用程序部署到多个服务器,那么需要关心的是什么?

If I would like to deploy my application using Play Framework 2.x to multiple servers, what are the things I need to care about?


  1. 如果我正在使用(内置)会话,所有节点是否可以使用它们,因为它们存储在浏览器端?

  1. If I am using (built-in) sessions, will it be available to all the nodes since they are stored in browser side?

如何共享应用范围内的变量,除非将它们存储在数据库中?

How can I share variables application-wide except for storing them in the database?


推荐答案

将生产中的Play应用程序放到多个服务器节点时,您应该检查以下步骤:

When putting a Play application in production to multiple server nodes, you should check following steps:


  • 确保应用程序的秘密加密和签名会话 cookie)在每个节点上都是相同的,因为您将无法向哪个节点发送HTTP响应。

  • 确保您没有使用内置缓存系统(ehcache)来存储用户特定的信息(缓存存储在服务器的内存中)。

  • Ensure the application secret (that encrypts and signs the session cookie) IS THE SAME on every node, as you won't be able to which node will send the HTTP response.
  • Ensure that you did not use the built in cache system (ehcache) to store user specific information (as the cache is stored in server's memory).

这就是...

所以对于answe你的其他要点:

So to answer your other points:


  1. 如果你使用(内置)会话,存储在会话中的信息 cookie将可用于每个服务器节点(来自客户端)。只要记住,一些旧版浏览器(IE6)中的Cookie限制在4kb,所以请仔细阅读您在会话中输入的信息数量。

  2. 如果您要共享其他应用程序广泛的变量:

  1. If you're using (built-in) sessions, information stored in the session cookie will be available to every server node (as it comes from the client). Just remember that a cookie is limited to 4kb in some old browsers (IE6), so be carefull about the quantity of information you put in the session.
  2. If you want to share other application wide variables:


  • 如果信息是用户特定的,您还可以将它们存储在会话或另一个Cookie。例如,如果要保存当前用户的主题: response()。setCookie(theme,blue); 。然后,您可以使用 Http.Request.current()。cookie.get(theme)检索存储的信息。您可以深入了解播放会话和Cookie

  • if the information is user specific, you can also store them on the session, or in another cookie. For instance if you want to save current user's theme: response().setCookie("theme", "blue");. Then you can retrieve the stored information with Http.Request.current().cookies.get("theme"). You can have a deeper look into play sessions and cookie.

如果要跨多个节点共享其他变量,则必须使用分布式缓存解决方案,如 memcached ,或者像你建议的数据库。

If you want to share other variables across multiple nodes, you'll have to use distributed cache solutions like memcached or, your database like you suggested.

如果尚未完成,您应该查看如何部署播放生产

If not already done, you should have a look into how to deploy play to production

这篇关于如果我要将Play Framework应用程式部署到多台伺服器,该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆