免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

LNMP架構中Nginx反向代理負載均衡如何配置

這篇文章主要介紹LNMP架構中Nginx反向代理負載均衡如何配置,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

創新互聯建站于2013年開始,先為太和等服務建站,太和等地企業,進行企業商務咨詢服務。為太和企業網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。

1、配置環境介紹

系統環境:

[root@centos6 conf]# cat /etc/redhat-release 

CentOS release 6.5 (Final)

[root@centos6 conf]# uname -r

2.6.32-431.el6.x86_64

nginx版本:

[root@centos6 conf]# /application/nginx/sbin/nginx -v

nginx version: nginx/1.10.1

LNMP架構中Nginx反向代理負載均衡如何配置

LNMP架構中Nginx反向代理負載均衡如何配置

配置二臺虛擬主機,用來做后續測試



2、整體邏輯圖

LNMP架構中Nginx反向代理負載均衡如何配置


說明:當用戶訪問時,其實訪問的是負載均衡器對外提供的地地址,然后由它來根據相應的規則進行轉發給后端后服務器


3、配置過程

[root@centos6 conf]# vi nginx.conf

worker_processes  1;    

events {                          

    worker_connections  1024;    

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65; 

include /application/nginx/conf/extra/upstream01.conf;

  }

增加上述配置即可


接下來配置upstream01.conf


[root@centos6 extra]# vi upstream01.conf

#####config to nginx 

upstream test_servers {      #定義主機池

server 172.16.1.235:8081 weight=5;  #按權重的方式進行輪詢

server 172.16.1.235:8080 weight=5; 

server 172.16.1.235:80 weight=15;

      }

server { 

listen 80; 

server_name www.mingonge.com;

location / { 

 proxy_pass http://test_servers;     #將監聽到請求轉發到這個虛擬主機池

}  

 }


更多關于upstream模塊的介紹,請參考官方文檔

http://nginx.org/en/docs/http/ngx_http_upstream_module.html


4、重啟服務并測試

重啟nginx服務

[root@centos6 extra]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.10.1/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.10.1/conf/nginx.conf test is successful

[root@centos6 extra]# /application/nginx/sbin/nginx -s reload

linux本地客戶端測試

[root@centos6 extra]# curl http://172.16.1.235

welcont to mingongge's blog stie

[root@centos6 extra]# curl http://172.16.1.235

welcont to mingongge's bbs stie

[root@centos6 extra]# curl http://172.16.1.235

welcont to mingongge's blog stie

用戶客戶端用域名測試

本地客戶端需要將域名正確解析,www.mingongge.com------>172.16.1.235

LNMP架構中Nginx反向代理負載均衡如何配置

LNMP架構中Nginx反向代理負載均衡如何配置


從上面的測試結果來看,的確兩次訪問分配的服務器是不同的,為了測試效果,所以將顯示的內容配置成不同,實際生產環境中,所有的訪問顯示內容都是一樣的,實現服務器宕機但不會影響用戶的體驗度



5、模擬測試真實環境

我們這里將兩臺虛擬機首頁內容配置成相同顯示內容來模擬真實生產環境

[root@centos6 ~]# echo "welcome to mingongge's web site" >/www/bbs/index.html

[root@centos6 ~]#  echo "welcome to mingongge's web site" >/www/blog/index.html

[root@centos6 ~]# cat /www/bbs/index.html 

welcome to mingongge's web site

[root@centos6 ~]# cat /www/blog/index.html 

welcome to mingongge's web site

linux客戶端測試

[root@centos6 ~]# curl http://172.16.1.235

welcome to mingongge's web site

[root@centos6 ~]# curl http://172.16.1.235

welcome to mingongge's web site


停止其中一臺虛擬的WEB服務功能來模擬故障,由于是用的nginx本身的虛擬主機,這里我們就修改配置文件,將包含配置文件注釋掉

#include  /application/nginx/conf/extra/vhosts/bbs.conf;

如果測試用三臺服務器,可以配置不同的http服務,模擬服務器宕機(停止WEB服務),來測試負載均衡的效果更加貼近現實環境


[root@centos6 ~]# curl http://www.mingongge.com       

welcome to mingongge's web site

[root@centos6 ~]# curl http://www.mingongge.com

welcome to mingongge's web site

LNMP架構中Nginx反向代理負載均衡如何配置
客戶端仍然可以訪問 ,表明負載均衡的功能是生效的,當其中的服務器出現宕機情況,也不會影響用戶的最終訪問

以上是“LNMP架構中Nginx反向代理負載均衡如何配置”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注創新互聯行業資訊頻道!

網頁標題:LNMP架構中Nginx反向代理負載均衡如何配置
本文地址:http://m.newbst.com/article30/gcecpo.html

成都網站建設公司_創新互聯,為您提供全網營銷推廣網站營銷網站維護網站制作App設計靜態網站

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都seo排名網站優化