CentOS中實現Nginx負載平衡和反向 Proxy

來源:互聯網
上載者:User

標籤:style   http   os   io   檔案   cti   工作   line   

一、安裝必要軟體

  負載平衡伺服器:IP設定為192.168.1.10

  Web伺服器1:安裝Apache或者Nginx,IP設定為192.168.1.11;

  Web伺服器2:安裝Apache或者Nginx,IP設定為192.168.1.12。

二、配置負載平衡伺服器

  1、在Nginx的conf目錄下建立extra檔案夾,並在其下邊編輯產生一個設定檔,比如t_servers.conf

  upstream test_servers {

  server 192.168.1.11:80 weight=5;
  server 192.168.1.12:80 weight=5;
  }
  server {
  listen 80;
  server_name 192.168.1.10;
  location / {
  proxy_pass http://test_servers;
  }
  }

  2、編輯Nginx的conf目錄下的nginx.conf檔案,只保留下邊一些必要配置,在最後一行include下上邊儲存的設定檔。

 

  worker_processes 1;

  events {

  worker_connections 1024;
  }

  http {
  include mime.types;
  default_type application/octet-stream;

  sendfile on;

  keepalive_timeout 65;

  include extra/t_servers.conf;
  }

三、重啟Nginx伺服器

  每次訪問192.168.1.10時,都會自動在Web伺服器1和2之間進行切換,實現負載平衡和反向 Proxy。如果其中一台Web伺服器宕機,訪問時,則會自動跳轉到正常工作的Web伺服器上。如果Nginx宕機,則報502錯誤。

  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.