vim /usr/local/tomcat/webapps/test/index.jsp<!DOCTYPE html><%@ page language=34;java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ page import="java.util.Date" %><%@ page import="java.text.SimpleDateFormat" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/ html14/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>动态页面</title></head><body><div>动态页面</div><img src="22.jpg"width=250> //添加</body></html>
9.6 验证 图片验证动静分离访问静态页面http://192.168.75.166访问动态页面http://192.168.75.166/test/index.jsp
图片验证动静分离
10 . 实验二:负载均衡10.1 实验环境Nginx 192.168.75.166 作为负载均衡做事器Tomcat1 192.168.75.134Tomcat 2 192.168.75.144 作为后端web做事器以Nginx作为负载均衡器,Tomcat作为运用做事器10.2 Tomcat 2 192.168.75.144 配置安装Tomcat 做事像之前Tomcat1 一样的步骤,详情看Tomcat1由于之前Tomcat1已经支配Tomcat,以是只须要支配Tomcat2 做事器内容详情如下mkdir -pv /web/webapp1cd /web/webapp1vim index.jsp<!DOCTYPE html><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ page import="java.util.Date" %><%@ page import="java.text.SimpleDateFormat" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/ html14/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>web web web web web webb !!!!</title></head><body><div>web web web web web webb !!!!</div></body></html>修正配置文件 vim /usr/local/tomcat/conf/server.xml <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context docBase="/web/webapp1" path="" reloadable="false"> //添加 </Context> //添加 <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> -->
10.3 Nginx做事器配置192.168.75.166支配Nginx 详情看目录9.1
vim /usr/local/nginx/conf/nginx.conf在http的全局添加 upstream tomcat_server { server 192.168.75.134:8080 weight=1; server 192.168.75.144:8080 weight=5; //权重越高越优先 }在server中添加 location / { root html; index index.html index.htm; proxy_pass http://tomcat_server; //添加 }
10.4 验证192.168.75.166