Nginx反向代理+redis实现session共享

        nginx ("engine x") 是一个高性能的HTTP和反向代理服务器;我们可以将同一个项目部署在多个服务器上,使用nginx来实现反向代理和负载均衡,同时使用redis来存储session信息,实现session的共享:


实现nginx方向代理的配置:

1.修改Nginx下的nginx-1.8.0\conf\nginx.conf文件.

2.配置服务器列表upstream server_list

3.将服务器列表配置到proxy_pass中,就能实现对server_list中服务器的方向代理;

页面上只需要输入nginx的地址就可以访问到台tomcat,nginx默认监听的是8080端口.

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
	keepalive_timeout  65;
	
	#实现反向代理配置
	upstream server_list{
	 server 192.168.25.139:8080 weight=10;
	 server 192.168.25.140:8080 weight=10;		
	}
	
	

    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
	    proxy_pass http://server_list;
            index  index.html index.htm;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
       
    }

实现nginx方向代理session共享:

1.将下面四个jar包,放导tomcat的lib目录下(每个tomcat都要放)

2.在tomcat/conf/context.xml文件中添加配置

<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve"/>
   <Manager className="com.radiadesign.catalina.session.RedisSessionManager"
        host="192.168.19.128"  <!--redis的ip地址-->
        port="6379"
        database="0"           <!-- 使用redis的哪个库-->
        maxInactiveInterval="60"   
	password="admin"
 />

猜你喜欢

转载自blog.csdn.net/kebo_china/article/details/79848587
今日推荐