公司网站开发费用大概多少,网页设计建设网站模板,龙元建设集团有限公司网站,无锡百度公司王东访问静态和动态页面分开
实现动态的静态页面负载均衡
实验一
准备阶段#xff1a;三台虚拟机
nginx代理服务器 #xff1a;20.0.0.40
tomcat1 #xff1a;20.0.0.50
tomcat2#xff1a;20.0.0.51
配置关闭虚拟机防火墙和安全机制
systemctl stop firewalld
setenf…访问静态和动态页面分开
实现动态的静态页面负载均衡
实验一
准备阶段三台虚拟机
nginx代理服务器 20.0.0.40
tomcat1 20.0.0.50
tomcat220.0.0.51
配置关闭虚拟机防火墙和安全机制
systemctl stop firewalld
setenforce 0 配置nginx代理服务器 conf/nginx
upstream tomcat {server ip1:8080 weight2;server ip2:8080 weight3;
}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作为代理服务器时会把所有经过的机器的IP以及代理地址的IP全部记录下来}
nginx -t 检测配置文件是否有错
systemctl restart nginx 重启服务
切换到html目录下 cd /html
html
body
h1this is Nginx static test !!h1
img src图片
/body
/html
配置后端tomcat
进入webapps目录下创建一个目录在目录下创建index.jsp
% page languagejava importjava.util.* pageEncodingUTF-8%
html
head
titletomcat01/title
/head
body
% out.println(tomcat01 running);%
/body
/html
进入主配置文件并做备份 conf/server.conf
#删除前面的 HOST 配置
Host namelocalhost appBasewebapps unpackWARstrue autoDeploytrue xmlValidationfalse xmlNamespaceAwarefalseContext docBase/usr/local/tomcat/webapps/test path reloadabletrue /
/Host
然后进入bin目录下启动tomcat
./shutdown.sh
./stratup.sh
查看8080端口是否启动
netstat -antp | grep 8080
同理tomcat也是上述操作
实验二
四层7层动静分离
五台服务器
1、代理服务器nginx1:20.0.0.40
2、静态页面和动态的请求转发服务器
20.0.0.41
20.0.0.42
3、后端服务器
tomcat1:20.0.0.50
tomcat2:20.0.0.51
配置代理服务器
stream {upstream static {server 20.0.0.50:80 weight1;server 20.0.0.60:80 weight1;}server {listen 80;proxy_pass static;}
}
转发服务器
upstream tomcat {server tomcatip1:8080 weight1;server tomcatip2:8080 weight2;
}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作为代理服务器时会把所有经过的机器的IP以及代理地址的IP全部记录下来}
配置静态页面的命令
html
body
h1this is Nginx static test !!h1
img src图片
/body
/html
同理nginx2也是一样的
tomcat不需要动实验一已经配置完毕
在浏览器上20.0.0.40可以查看静态
20.0.0.40/index.jsp查看动态