测试环境windows7+nginx1.11.3(windows版本)+ tomcat7
一。
下载地址:1.nginx https://nginx.org/en/docs/windows.html
2.tomcat https://tomcat.apache.Z喎?/kf/ware/vc/" target="_blank" class="keylink">vcmcvPGJyIC8+DQo8aW1nIGFsdD0="这里写图片描述" src="/uploadfile/Collfiles/20160730/20160730092443261.png" title="\" />
二。
解压nginx
解压tomcat并复制一份
1.打开tomcat1的conf文件找到server.xml
2.修改tomcat2的 server.xml 端口号不能和tomcat1一样
3.修改nginx 配置文件
*servername localhost 表示本机
# 静态请求的转发
location ~* .(gif"jpg|jpeg|html|png|js)$ {
root data;
expires 20d; } * root data 表示请求的url中如果带有静态资源相关的后缀都到这个文件夹下面去找。 * expires 20d #过期20天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。 # 动态请求的转发 location ~ .*.jsp$ { proxy_pass https://mysite; client_max_body_size 1000m; proxy_set_header Host $host; } *https://mysite 和upstream里面的mysite要一一对应weight表示权重 数值越大。优先得到请求
upstream mysite {
server localhost:8081 weight=1 ;
server localhost:8082 weight=1 ;
}
4.创建一个jsp 。名称index.jsp
这个放在tomcat1 下面的root目录
引入的图片要放在nginx data 目录如果没有新建一个

5.在创建一个jsp名称index.jsp

这个放在tomcat2 下面的root目录
同样也需要吧图片放在这里

6.启动nginx .启动tomcat1 tomcat2.
7.启动浏览器。输入localhost/index.jsp 然后按F5 。可以看到请求在tomcat1和tomcat2中来回的变换。不停的做分发。


动静分离。负载均衡已经实现。更细致的配置可以参考nginx手册。