简体   繁体   English

使用Nginx进行HTTP负载平衡

[英]HTTP load balancing with nginx

I have a configuration like this. 我有这样的配置。

upstream servers{
                server localhost:port1;
                server localhost:port2;
                server localhost:port3;

}

server{
       listen nginx_port;
       server_name localhost 

       location{
                proxy_pass http//:servers;
}



}

Now what I want to know is how to keep a user's session alive while maintaining (I mean temporarily closing) one server. 现在,我想知道的是如何在维护(我的意思是暂时关闭)一台服务器的同时保持用户会话的活动状态。 Let say I have a 3 page registration now user is connected to localhost:port1 and working on page 2 in the meantime if I want to close the server(localhost:port1) and forward the user to next server(localhost:port2) keeping the session alive I mean the user should be able to complete his registration without any trouble then what i have to do in the nginx configuration file. 假设我有一个3页的注册,现在用户要连接到localhost:port1并同时在第2页上工作,如果我想关闭服务器(localhost:port1)并将用户转发到下一个服务器(localhost:port2)并保持会话还活着,我的意思是用户应该能够完成他的注册而没有任何麻烦,然后我必须在nginx配置文件中做什么。 is it possible? 可能吗?

You can't do this with nginx, as nginx is not what's providing the session functionality. 您无法使用nginx进行此操作,因为nginx不能提供会话功能。 You need to do this with your upstream servers by configuring them to use session storage that's sharable by all the servers (like a database or memcache) instead of server-specific session storage (like files in a temp dir on the local hard drive.) How you do that will vary based on whatever your upstream servers are. 您需要通过配置上游服务器来使用所有服务器都可以共享的会话存储(例如数据库或内存缓存),而不是特定于服务器的会话存储(例如本地硬盘驱动器上临时目录中的文件)来对上游服务器执行此操作。根据上游服务器的不同,您的操作方式也会有所不同。 For example, if you're using Zend, you might implement a database save handler . 例如,如果您使用的是Zend,则可以实现数据库保存处理程序

(I'm assuming here that your config is just an example and that you don't actually have three identical upstream servers on the same machine.) (我在这里假设您的配置只是一个示例,并且您实际上在同一台计算机上没有三个相同的上游服务器。)

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

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