windows服务器 Nginx 、tomcat集群搭建及session共享解决

1、软件准备

Nginx(代理服务器) 下载 http://nginx.org/en/download.html

tomcat(应用服务器)下载 https://tomcat.apache.org/download-80.cgi

tomcat-redis-session-manager(session共享)下载https://github.com/ran-jit/tomcat-cluster-redis-session-manager/releases/tag/3.0.3 下的tomcat-cluster-redis-session-manager.zip

 第一步 下载Nginx (注:确保目录文件中不能有中文)

编辑配置文件 nginx.conf

worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

upstream wgf.com{

#应用服务器1
server 127.0.0.1:8081;

#应用服务器2
server 127.0.0.1:8088;
}

server {
listen 80;

#访问路径
server_name localhost;

location / {
root html;
index index.html index.htm;

#映射真实服务器路径
proxy_pass http://wgf.com/;
proxy_redirect default;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}
}

扫描二维码关注公众号,回复: 7121089 查看本文章

第二步:部署应用至tomcat修改tomcat配置文件

tomcatA:

server.xml

<Connector port="8088" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

tomcaB:

server.xml

<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

此时启动tomcatA 和tomcat B 后启动Nginx 

浏览器输入:http://localhost/项目名 即可访问成功,有问题可留言

第三步:session 共享

解压tomcat-cluster-redis-session-manager.zip 该文件 

将lib 文件中的jar包拷入tomcatA和tomcatB的lib文件夹下

并将redis-data-cache.properties 配置文件拷入tomcatA和tomcatB的conf文件夹下

eg:

redis.hosts=127.0.0.1:6379
redis.cluster.enabled=false

此时再次启动tomcatA、tomcatB 之后启动Nginx即可成功实现session共享。

浏览器输入:http://localhost/项目名 即可访问成功,有问题可留言

以上是自学总结。有借鉴前辈帖子望见谅。不足之处请多多指教 

猜你喜欢

转载自www.cnblogs.com/yixingzhou/p/11425735.html
今日推荐