0x06 - Nginx load balancing session remains

Nginx load balancing session remains

background

Load balancing, if APP need to maintain a certain status, you must ensure that the same user session will be assigned to the same server.

Implementation

  1. Use cookie
    will be stored in the user's session cookie inside, when the user is assigned to a different server, the server first determines whether the user's session exist, if not first cookie inside sessoin into the server to achieve session session remains. The disadvantage is stored in the cookie are security risks.
  2. Use cache
    use memcache, Redis features such as distributed caching, session can be generated for all servers stored in the same cache servers, the realization of session sharing. Such security is relatively high, and when reading the session from the memory faster than the speed read from a file.
  3. Use ip_hash
    If nginx server load balancing can be provided in the upstream ip_hash, each hash result to assign access request by ip mapped to a fixed server station. The disadvantage is likely to lead to load imbalance.
    upstream https_proxy {
        server 172.26.114.89:8443;
        server 172.26.114.93:8443;
        ip_hash;
    }

Note: ip_hash and weight can not be used together.
Note: use cases, using the Spring framework, Redis Sharing Session, page error when frequently switching nodes, sometimes leading to two corresponding nodes perform the same, then we need to start to fix ip_hash visitors.

Guess you like

Origin www.cnblogs.com/duchaoqun/p/11947141.html