1.首先在Mac下安装Nginx(可参考我的另一篇随笔http://www.cnblogs.com/malcolmfeng/p/6896703.html)。
2.安装Tomcat,下载后,解压,bin目录设置到环境变量里。(可参考我的另一篇随笔http://www.cnblogs.com/malcolmfeng/p/6902569.html)。
3.启动tomcat,同时局域网下的另一台主机也需要启动tomcat(内网地址 192.168.0.108 tomcat端口号也设置为8080 )。
4.配置nginx配置文件, 文件路径 /usr/local/etc/nginx/nginx.conf 打开后在http中设置如下
http {
# 实现负载均衡
upstream dis{
server 192.168.0.108:8080 weight=1;
server 127.0.0.1:8080 weight=1;
}
server{
listen 9090;
server_name localhost;
location / {
proxy_pass http://dis;
}
}
}
其中weight为权重,设置的数字越大分发到的几率也就越大。
5.启动tomcat:将bin目录中的startup.sh文件拖到终端,回车 即可启动tomcat
启动nginx: 终端执行 brew services start nginx (终止nginx 为: brew services stop nginx)
6.这样,在本机 访问 localhost:9090到时候,nginx会分发到 dis中的两台服务器中的tomcat。