Nginx 簡單的負載平衡配置樣本

來源:互聯網
上載者:User
[ 2007-10-29 20:50 | by 張宴 ]    www.zyan.cc 和 blog.zyan.cc 網域名稱均指向 Nginx 所在的伺服器IP。

  使用者訪問 http://www.zyan.cc,將其負載平衡到192.168.1.2:80、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四台伺服器。

  使用者訪問 http://blog.zyan.cc,將其負載平衡到192.168.1.7伺服器的8080、8081、8082連接埠。

  以下為設定檔nginx.conf:

引用 user  www www;

worker_processes 10;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

#最大檔案描述符
worker_rlimit_nofile 51200;

events
{
      use epoll;

      worker_connections 51200;
}

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

      keepalive_timeout 120;

      tcp_nodelay on;

      upstream   www.zyan.cc  {
              server   192.168.1.2:80;
              server   192.168.1.3:80;
              server   192.168.1.4:80;
              server   192.168.1.5:80;
      }

      upstream  blog.zyan.cc  {
              server   192.168.1.7:8080;
              server   192.168.1.7:8081;
              server   192.168.1.7:8082;
      }

      server
      {
              listen  80;
              server_name   www.zyan.cc;

              location / {
                       proxy_pass         http://www.zyan.cc;
                       proxy_set_header   Host             $host;
                       proxy_set_header   X-Real-IP        $remote_addr;
                       proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
              }

              log_format  www_s135_com  '$remote_addr - $remote_user [$time_local] $request '
                                '"$status" $body_bytes_sent "$http_referer" '
                                '"$http_user_agent" "$http_x_forwarded_for"';
              access_log  /data1/logs/www.log  www_s135_com;
      }

      server
      {
              listen  80;
              server_name  blog.zyan.cc;

              location / {
                       proxy_pass         http://blog.zyan.cc;
                       proxy_set_header   Host             $host;
                       proxy_set_header   X-Real-IP        $remote_addr;
                       proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
              }

              log_format  blog_s135_com  '$remote_addr - $remote_user [$time_local] $request '
                                '"$status" $body_bytes_sent "$http_referer" '
                                '"$http_user_agent" "$http_x_forwarded_for"';
              access_log  /data1/logs/blog.log  blog_s135_com;
      }
}
  附:Nginx 的安裝方法可參照《 Nginx 0.5.31 + PHP 5.2.4(FastCGI)搭建可承受3萬以上並發串連數,勝過Apache 10倍的Web伺服器》文章的以下段落(僅做負載平衡,無需支援PHP的安裝方法):

   二、安裝PHP 5.2.4(FastCGI模式)
  4、建立www使用者和組,以及其使用的目錄:

  三、安裝Nginx 0.5.31
  1、安裝Nginx所需的pcre庫:
  2、安裝Nginx
  3、建立Nginx日誌目錄
  5、啟動Nginx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.