-
Nginx的 IP_Hash 策略
同⼀个客户端IP的请求都会被路由到同⼀个⽬标服务器,也叫做会话粘滞
在nginx的 niginx.conf 中 添加ip_hash
-
Spring Session+ Redis的Session共享应⽤
以SpringBoot中部署为例
1. 编入依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
2. application.properties中引入配置
spring.redis.host=localhost
spring.redis.database=0
spring.redis.port=6379
spring.redis.password=
spring.redis.connect-timeout=5000
3. 引入注解
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
@SpringBootApplication
@EnableCaching
@EnableRedisHttpSession
public class LoginprojectApplication {
public static void main(String[] args) {
SpringApplication.run(LoginprojectApplication.class, args);
}
}
4. nginx中转发配置