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。
