nginx做負載均衡和反向代理

nginx做負載均衡。

我們瞭解負載均衡的實現,一般有3種形式。第一種,默認方式是1:1輪巡,第二種,權重,第三種,哈希。

 

 

實驗的圖如下:

當然是首先要配置好系統和4個LNMP結構。我們這裏着重直說Nginx裏面負載均衡的配置。

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    error_log logs/error.log error;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    sendfile        on;
    keepalive_timeout  65;
    #nginx vhosts config
    include extra/www.conf;
    include extra/bbs.conf;
    include extra/blog.conf;
    include extra/status.conf;
}

 

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

這個是負載均衡器上的

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    error_log logs/error.log error;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
upstream bbs_server_pools{
    server 192.168.3.103 weight=3;

    server 192.168.3.104 weight=2;
}
    #nginx vhosts config
     include extra/lb_bbs.conf;
  }

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章