实验环境:
客户端:物理机浏览器
Nginx:22.233.23.128 安装nginx
Tomcat:22.233.23.129/22.233.23.130 安装tomcat
1、配置tomcat
在tomcat/webapps下新建一个test目录,在test目录下将自己的IP写到index.html中
启动tomcat服务
浏览器测试一下
2、配置nginx
编辑/usr/local/nginx/conf/nginx.conf
添加upstream模块
监听nginx地址22.233.23.128
负载均衡,反向代理到129和130的8080端口上
3、启动nginx或重新加载nginx配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
4、测试
使用浏览器访问 http://22.233.23.128:9001/test/index.html
多次刷新,会显示不同的内容,说明请求被转发到了不同的tomcat上
(浏览器工作机制不同,有的可能达不到测试效果)