1.添加两个tomcat应用, 分别是server1, server2css
修改server1和server2的端口号, 避免重复这里设置为18080, 18081html
2. 修改nginx.conf配置nginx
vim /usr/local/nginx/conf/nginx.confweb
在http{}里面新增配置, 这里使用轮询的方式, 固然仍是IP哈希, UR哈希等方式vim
upstream tomcats {
server 服务ip:18080;
server 服务ip:18081;
}缓存
在server{}中新增配置 tomcat
location / {
proxy_pass http://tomcats;
}服务器
继续配置静态资源, 静态资源目录本身建立, expires 10d表示客户端缓存10天, 也能够设置成10h表示10小时, 具体的时间根据本身须要设置.app
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /usr/local/nginx-static/resources;
expires 10d;
}webapp
3.执行wq退出并保存
4.cd到/usr/local/nginx/sbin目录执行./nginx -s reload从新加载, 配置文件生效
5. 访问服务器ip,默认nginx的端口是80,这时会跳转到tomcat默认页
若是要看到负载的效果, 能够将tomcat下webapps下的ROOT项目里面的index.jsp随便修改点类容即可以看到效果了.