Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Explain in detail the two ways of Nginx reverse proxy to achieve session persistence (session)

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Ip_hash:

Ip_hash uses the source address hashing algorithm to always send requests from the same client to the same back-end server unless the server is unavailable.

Ip_hash syntax:

Upstream backend {ip_hash; server backend1.example.com; server backend2.example.com; server backend3.example.com down; server backend4.example.com;}

Ip_hash is easy to use, but has the following problems:

When the back-end server goes down, session will be lost; clients from the same LAN will be forwarded to the same back-end server, which may lead to load imbalance; it is not suitable for CDN network and does not apply to the situation where there are agents in the front segment.

2. Sticky_cookie_insert:

Use sticky_cookie_insert to enable session kinship, which causes requests from the same client to be passed to a set of servers on the same server. Unlike ip_hash, it does not judge the client based on IP, but on cookie. Therefore, the load imbalance caused by the clients and front-segment agents from the same local area network in the above ip_hash can be avoided.

Syntax:

Upstream backend {server backend1.example.com; server backend2.example.com; sticky_cookie_insert srv_id expires=1h domain=toxingwang.com path=/;}

Description:

Expires: set the time to keep cookie in the browser domain: define the domain path of cookie: define the path for cookie

In addition, you can also use the back-end server itself to keep session synchronized through related mechanisms, which will be described in more detail later!

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report