Session共享

  1.Nginx通过负载均衡IP地址固定绑定,解决Session共享

upstream backserver { 
    ip_hash;
    server 127.0.0.1:8080; 
    server 127.0.0.1:8090;
}

server {
    isten       80;
    server_name  www.wdksoft.com;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
                    
    proxy_pass http://backserver;
    index index.html index.htm;
                    
    }
}

  2.Spring-session+Redis解决Session共享
    2.1 保证Redis启动
    2.2 导入依赖

<!--spring boot 与redis应用基本环境配置 -->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-redis</artifactId>
                </dependency> <!--spring session 与redis应用基本环境配置,需要开启redis后才可以使用,不然启动Spring boot会报错 -->
                <dependency>
                    <groupId>org.springframework.session</groupId>
                    <artifactId>spring-session-data-redis</artifactId>
                </dependency>
            

    2.3 配置大配置文件

server:
     port: 8090

    #redis配置
    spring:
        redis:
        password: redis
原文地址:https://www.cnblogs.com/ws1149939228/p/12298958.html