1、在磁盘新建两个目录 tomcat1 tomcat2
2、修改tomcat2的端口
3、代理单个服务器方式:修改 conf
目录下的 nginx.conf
文件
代码如下:
location / {
root html;
index index.html index.htm;
proxy_pass http://localhost:8080;
}
4、代理集群(即代理多个服务器):修改 conf
目录下的 nginx.conf
文件
代码如下:
#gzip on;
upstream server_xxx{
#通过 weight 属性可设置被代理服务器权重,值越大权重越高,越容易被访问(可省略)
server 127.0.0.1:8080 weight=1;
server 127.0.0.1:8081 weight=2;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
#代理单个服务器
#proxy_pass http://localhost:8080;
#代理集群
proxy_pass http://server_xxx;
}
#error_page 404 /404.html;
5、session共享问题
解决方式1:只能在 windows
下使用
web服务器解决(广播机制:tomcat下性能低)
解决方式1:
-
修改
tomcat
的server.xml
支持共享即将server.xml中的<Engine name="Catalina" defaultHost="localhost">
标签下的<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
注释去掉。 -
修改项目的配置文件即在
web.xml
中添加一个节点:<distributable/>
解决方式2:
- 可以将
session
的id
放入redis
中
解决方式3:
- 保证一个ip地址永远的访问一台web服务器,就不存在session共享问题了,在linux因此在nginx的配置文件中
upstream
中添加ip_hash;
PS: 内容整理自网络