Varnish - 当在循环控制器中提供 cookie/会话时进行缓存
我是第一次配置清漆,我遇到了一个问题,到目前为止我还没有找到完整的答案。
我的配置简而言之:
server0 - varnish, be1-阿帕奇, be2 - apache
varnish 以循环方式从 2 个后端拉取。
我需要处理会话,因此我配置了一个简单的 php 脚本,该脚本在会话变量中设置当前时间,然后重定向到第二页,其中显示该会话变量和所使用的后端的 IP。
我已经成功地完成了这一半的工作。它正在传递我所看到的会话信息,但问题是 - 从后端返回的信息特定于生成它的后端。因此,返回的时间将取决于最后一次缓存调用的是 be1 还是 be2。
有没有一种方法可以让我正常工作,以便无论后端如何处理它,会话变量都是相同的?
I am configuring varnish for the first time, and I have come across an issue which I haven't been able to find a complete answer for so far.
My config in a nutshell:
server0 - varnish,
be1 - apache,
be2 - apache
varnish pulls from the 2 backends in a round robin.
I need to deal with sessions, so I have configured a simple php script which sets the current time in a session variable, then redirects to a 2nd page which displays that session variable and the ip of the backend that was used.
I have managed to get this half working. It is passing the session info from what i can see, but here is the problem - the info returned from the backend is specific to the backend it was generated on. So, the time returned will depend on whether be1 or be2 was called for the last cache.
Is there a way that I can get this working so that the session variable is the same regardless of the backend that processes it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是会话的普遍问题; cookie(随每个请求一起发送)包含会话的标识符。真实的会话数据存储在服务器或数据库中。有几种解决方案,例如:
寻找一些可以申请您的代码的库/可重用代码,祝您好运!
This is the general problem with sessions; a cookie (sent with every request) contains an identifier for the session. The real session data is stored on a server or in a database. There are several solutions for this, e.g.:
Look for some library/reusable code you can apply for your code and good luck!