Vanlin Study Club

          Java Js Flex

          Nginx 0.8.x跟tomcat組合實(shí)現(xiàn)均衡(我就當(dāng)它是把80跟其他端口組合起來(lái)):)

          Nginx ("engine x") 是一個(gè)高性能的 HTTP 和 反向代理 服務(wù)器,也是一個(gè) IMAP/POP3/SMTP 代理服務(wù)器 。 Nginx 是由 Igor Sysoev 為俄羅斯訪問(wèn)量第二的Rambler.ru 站點(diǎn)開發(fā)的,它已經(jīng)在該站點(diǎn)運(yùn)行超過(guò)四年多了。Igor 將源代碼以類BSD許可證的形式發(fā)布。自Nginx 發(fā)布四年來(lái),Nginx 已經(jīng)因?yàn)樗姆€(wěn)定性、豐富的功能集、 示例配置文件和低系統(tǒng)資源的消耗而聞名了。目前國(guó)內(nèi)各大門戶網(wǎng)站已經(jīng)部署了Nginx,如新浪、網(wǎng)易、騰訊等;國(guó)內(nèi)幾個(gè)重要的視頻分享網(wǎng)站也部署了Nginx,如六房間、酷6等。 新近發(fā)現(xiàn)Nginx 技術(shù)在國(guó)內(nèi)日趨火熱,越來(lái)越多的網(wǎng)站開始部署Nginx。

          這么好的東西不用用不行啊,,,來(lái)看官方的文檔。
          NginxChsHttpUpstreamModule
          Edit section: 摘要 摘要

          這個(gè)模塊提供一個(gè)簡(jiǎn)單方法來(lái)實(shí)現(xiàn)在輪詢和客戶端IP之間的后端服務(wù)器負(fù)荷平衡。

          配置范例:

          upstream backend  {
            server backend1.example.com weight
          =5;
            server backend2.example.com:8080;
            server unix:/tmp/backend3;
          }
           
          server {
            location / {
              proxy_pass  http://backend
          ;
            }
          }

          配置指導(dǎo)
          Edit section: ip_hash ip_hash

          syntax: ip_hash

          default: none

          context: upstream

          This directive causes requests to be distributed between upstreams based on the IP-address of the client. The key for the hash is the class-C network address of the client. This method guarantees that the client request will always be transferred to the same server. But if this server is considered inoperative
          , then the request of this client will be transferred to another server. This gives a high probability clients will always connect to the same server.

          范例:

          upstream backend {
            ip_hash
          ;
            server   backend1.example.com;
            server   backend2.example.com;
            server   backend3.example.com  down;
            server   backend4.example.com;
          }

          Edit section: server server

          syntax: server name 
          [parameters]

          default: none

          context: upstream 

          看不出名堂?不要緊看我的 配置最直觀 nginx.conf

          #user  nobody
          ;
          worker_processes  1;

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

          #pid        logs/nginx.pid
          ;


          events {
              worker_connections  
          1024;
          }


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

              #log_format  main  '$remote_addr - $remote_user 
          [$time_local] "$request" '
              #                  '$status $body_bytes_sent 
          "$http_referer" '
              #                  '
          "$http_user_agent" "$http_x_forwarded_for"';

              #access_log  logs/access.log  main
          ;
              upstream vanlin.imblog.in { 
                server 
          127.0.0.1:8080; 
          #這里才是實(shí)現(xiàn)均衡的地方,一般做法 Nginx 對(duì)外, 內(nèi)部對(duì)應(yīng)多臺(tái) server 有點(diǎn)像映射。。。
              }
              
              sendfile        on
          ;
              #tcp_nopush     on;

              #keepalive_timeout  
          0;
              keepalive_timeout  65;

              #gzip  on
          ;

              server {
                  listen       
          80;
                  server_name  vanlin.imblog.in;

                  #charset koi8-r
          ;

                  #access_log  logs/host.access.log  main
          ;

                  location / {
                      proxy_pass http://vanlin.imblog.in
          ;
                      proxy_set_header Host $host;
                      proxy_set_header X-Real-IP $remote_addr;
                      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  }

                  #error_page  
          404              /404.html;

                  # redirect server error pages to the static page /50x.html
                  #
                  error_page   
          500 502 503 504  /50x.html;
                  location = /50x.html {
                      root   html
          ;
                  }
          #這里配置過(guò)php,,好像。。 需要 php_cgi  的支持
                  # proxy the PHP scripts to Apache listening on 
          127.0.0.1:80
                  #
                  #location ~ \.php$ {
                  #    proxy_pass   http://
          127.0.0.1;
                  #}

                  # pass the PHP scripts to FastCGI server listening on 
          127.0.0.1:9000
                  #
                  #location ~ \.php$ {
                  #    root           html
          ;
                  #    fastcgi_pass   127.0.0.1:9000;
                  #    fastcgi_index  index.php;
                  #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                  #    include        fastcgi_params;
                  #}

                  # deny access to .htaccess files
          , if Apache's document root
                  # concurs with nginx's one
                  #
                  #location ~ /\.ht {
                  #    deny  all
          ;
                  #}
              }


              # another virtual host using mix of IP-
          , name-, and port-based configuration
              #
              #server {
              #    listen       
          8000;
              #    listen       somename:8080;
              #    server_name  somename  alias  another.alias;

              #    location / {
              #        root   html
          ;
              #        index  index.html index.htm;
              #    }
              #}


              # HTTPS server
              #
              #server {
              #    listen       
          443;
              #    server_name  localhost;

              #    ssl                  on
          ;
              #    ssl_certificate      cert.pem;
              #    ssl_certificate_key  cert.key;

              #    ssl_session_timeout  5m
          ;

              #    ssl_protocols  SSLv2 SSLv3 TLSv1
          ;
              #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
              #    ssl_prefer_server_ciphers   on;

              #    location / {
              #        root   html
          ;
              #        index  index.html index.htm;
              #    }
              #}

          }

          posted on 2009-10-14 11:05 vanlin 閱讀(391) 評(píng)論(0)  編輯  收藏 所屬分類: server


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 平泉县| 宁津县| 奈曼旗| 安徽省| 常宁市| 红安县| 来凤县| 任丘市| 莆田市| 高陵县| 东乌| 阜平县| 昔阳县| 镇原县| 沧州市| 肇东市| 麟游县| 独山县| 根河市| 曲阳县| 蒲城县| 精河县| 易门县| 天全县| 三门峡市| 乐陵市| 德惠市| 洛浦县| 加查县| 新邵县| 乌海市| 剑阁县| 临沭县| 宁河县| 信宜市| 木兰县| 增城市| 安平县| 高安市| 云南省| 汽车|