动静分离:
访问静态和动态页面分开
实现动态和静态页面负载均衡
实验1:
准备三台虚拟机:
1台nginx代理服务器:
192.168.120.30
2台tomcat:
tomcat1:192.168.120.20
tomcat2:192.168.120.50
同时关闭防火墙和安全机制
进入代理服务器
vim /usr/local/nginx/conf/nginx.conf
upstream tomcat {
server 20.0.0.25:8080 weight=1;
server 20.0.0.26:8080 weight=2;
}
location ~* \.jsp$ {
proxy_pass http://tomcat;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
nginx -t
#检测一下
systemctl restart nginx
vim /usr/local/nginx/html/index.html
配置动态页面
进入tomcat1和tomcat2
vim /usr/local/tomcat/conf/server.xml
148行删除
添加
mkdir /usr/local/tomcat/webapps/test
vim /usr/local/tomcat/webapps/test/index.jsp
tomcat1:
tomcat2:
./shutdown.sh 关闭
./startup.sh 开启
实验2:
四层+七层+动静分离
192.168.120.30nginx1代理服务器
192.168.120.40 nginx七层代理
192.168.120.60 nginx2七层代理
192.168.120.20 tomcat1 动态网页
192.168.120.50 tomcat2 动态网页
进入代理服务器
vim /usr/local/nginx/conf/nginx.conf
systemctl restart nginx
vim /usr/local/nginx/html/index.html
Nginx1
vim /usr/local/nginx/conf/nginx.conf
vim /usr/local/nginx/html/index.html
Nginx2
vim /usr/local/nginx/conf/nginx.conf
vim /usr/local/nginx/html/index.html
Tomcat1
vim /usr/local/tomcat/conf/server.xml
148行删除
mkdir /usr/local/tomcat/webapps/test
vim /usr/local/tomcat/webapps/test/index.jsp
cd /usr/local/tomcat/bin
./startup.sh
tomcat2
vim /usr/local/tomcat/conf/server.xml
148行删除
mkdir /usr/local/tomcat/webapps/test
vim /usr/local/tomcat/webapps/test/index.jsp
cd /usr/local/tomcat/bin
./startup.sh