負載均衡是我們大流量網站要做的一個東西,下面我來給大家介紹在nginx伺服器上進行負載均衡配置方法。
測試環境
測試域名 :www.threegroup.space
a伺服器ip :123.56.255.173 (主)
b伺服器ip :101.200.159.138
c伺服器ip :123.56.255.53
部署思路
a伺服器做為主伺服器,域名直接解析到a伺服器(123.56.255.173)上,由a伺服器負載均衡到b伺服器(101.200.159.138)與c伺服器(123.56.255.53)上。
開始配置nginx負載均衡
① 打開nginx.conf,檔案位置在nginx安裝目錄的conf目錄下。
在http段加入以下代碼 :
如截圖所示
從截圖上看到
和 123.56.255.53:8080 的ip上
最後 儲存重新開機nginx
② 工作伺服器配置方法
我們要在 b、c伺服器nginx.conf設定如下
打開nginx.confi,在http段加入以下代碼
儲存重新開機nginx
③ 測試
當通路www.threegroup.space的時候,為了區分是轉向哪台伺服器處理我分别在b、c伺服器下寫一個不同内容的index.html檔案,以作區分。
打開浏覽器通路www.threegroup.space結果,重新整理會發現所有的請求均分别被主伺服器(a) 配置設定到 b伺服器(101.200.159.138)與c伺服器(123.56.255.53)上,實作了負載均衡效果。
推薦學習網站
<a target="_blank" href="http://blog.csdn.net/libinemail/article/details/51074866">http://blog.csdn.net/libinemail/article/details/51074866</a>
<a target="_blank" href="http://www.php100.com/html/program/nginx/2013/0905/5525.html">http://www.php100.com/html/program/nginx/2013/0905/5525.html</a>
<a target="_blank" href="http://www.cnblogs.com/liping13599168/archive/2011/04/15/2017369.html">http://www.cnblogs.com/liping13599168/archive/2011/04/15/2017369.html</a>