多个实例(服务器)网站上的网站表单 (POST) (Python Django / PHP)
假设我有一个 PHP / Python (Django) 网站。 该网站在多个实例服务器上运行。 这意味着网站的 URL 是 www.test.com,并且通过负载均衡器,它可以让客户端访问 www.server1.com 或 www.server2.com 等。
当网站上有一个表单,并且该表单的处理位于同一页面时: 是否存在以下情况? : - 用户访问 www.test.com - 在幕后,通过负载均衡器,他访问 www.server*1*.com。他填写了一张表格。 - 表单操作 (URL) 用于 www.test.com - 因此在幕后,通过负载均衡器,他可以访问 www.server*2*.com。 那么在这里,所需的表单数据(对于我的问题来说更重要)可能会丢失“请求”数据(如 Python Django 中的 request.SOMETHING)吗?因为它可能之前在会话中保存在 www.server*1*.com 上,但现在在 www.server*2*.com 上丢失了?
Suppose I have a PHP / Python (Django) website.
The website is running on multiple instances servers.
Meaning the URL for the website is www.test.com, and from a load balancer, it can get the client to www.server1.com or www.server2.com and so on.
When there is a form on the website, and the processing of this form is located on the same page:
Can the following situation exist ? :
- User go to www.test.com - behind the scenes, through the load balancer, he gets to www.server*1*.com. He fills a form.
- The form action (URL) is for www.test.com - so behind the scenes, through the load balancer, he gets to www.server*2*.com.
So here, will the needed form data, and more important for my question maybe - the 'request' data, (like request.SOMETHING at Python Django) will be missing ? Because maybe it was saved before on the session, at www.server*1*.com, and now it is missing at www.server*2*.com ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该请求将始终包含所有数据,因为这些数据被转发到边缘服务器。
request.POST
和request.GET
将拥有请求中的所有数据。然而,问题是会话数据可能在该边缘服务器上不可用。例如,您在 server1 上启动会话,然后从 server2 请求另一个页面。 server2 可能会分配一个新会话并禁止您访问某些内容。要解决此会话问题,您可以执行以下两种操作之一:
The request will always have all data, as that gets forwarded to the edge server.
request.POST
andrequest.GET
will have all the data from the request. The problem however, is that the session data might not be available at that edge server. Example, you started your session on server1, then request another page from server2. server2 might assign a new session and forbid you to access certain contents.To overcome this session problem, you can do one of two things:
是的,这是一个合理的担忧。由于 Web (HTTP) 的性质,其他请求可能最终到达其他服务器。这个问题称为持久性或粘性。
这里的解决方案是将所有这些信息保存在客户端(使用 cookie),而不是依赖于服务器端会话。因此,您可以使用 Python/Django 来实现它。使用客户端方法可提供最佳性能,并且应该是最容易实现的。
请记住,此解决方案对于中间人攻击具有相当大的安全风险,除非您使用 SSL/TSL(使用 HTTPS)加密连接,因为所有客户端数据都存储在 cookie 中,这可能会被被拦截。
Yes, this is a valid concern. Due to the nature of the Web (HTTP), the other request might end up on the other server. This issue is called persistence or stickiness.
The solution here would be to save all this information on the client side (using cookies) and not rely on server-side sessions. So it would be up to you to implement it like this using Python/Django. Using the client-side approach gives the best performance, and should be the easiest to implement.
Keep in mind that this solution bears quite a significant security risk for man-in-the-middle attacks, unless you encrypt the connection with SSL/TSL (using HTTPS), as all of the client data is stored in the cookies which could be intercepted.