天天看點

nginx load balance

                                       nginx load balance配置

本文大概描述負載均衡的一般配置。關于upstream和sticky的問題可參看博文http://3006939.blog.51cto.com/2996939/1108527

安裝nginx:

  1. wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm  
  2. rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm  
  3. yum install nginx  
  1. upstream backend {  
  2.   sticky;  
  3.   check interval=5000 rise=2 fall=5 timeout=1000;  
  4.   check_http_send "GET /health.html HTTP/1.1\r\n\r\n";  
  5.   server        192.168.0.6:8080;  
  6.   server        192.168.2.130:8080;  
  7.   server        192.168.0.4:8080;  
  8.   server        192.168.0.5:8080;  
  9. }  
  10. server {  
  11.   listen 80;  
  12.   location /system/console {  
  13.     root /var/www/html/nginx/empty;  
  14.         client_max_body_size    300m;  
  15.   }  
  16.   location /libs {  
  17.     root /var/www/webstatic;  
  18.         client_max_body_size    300m;  
  19.   }  
  20.   location / {  
  21.     client_max_body_size 300m; #此處設定的數值決定了nginx上傳檔案大小的限制 
  22.     proxy_pass http://backend;  
  23.     proxy_set_header  X-Real-IP  $remote_addr;  
  24.     add_header X-Real-IP  $upstream_addr;  
  25.     proxy_buffering off;  
  26.   }  
  27. }  
  28. server  
  29. {  
  30.  listen 80;  
  31.  server_name test.abc.org abc.abc.org www.abc.com abc.com;  
  32.  access_log     /var/log/nginx/xuanran_acc.log;  
  33.  location / {  
  34.  root /home/abc/test;  
  35.  index index.html index.htm index.php;  
  36. }  
  37. }  
  38. server  
  39. {  
  40.  listen 80;  
  41.  server_name www.abc.org abc.org;  
  42.  access_log     /var/log/nginx/abc_acc.log;  
  43.   location / {  
  44.  root /home/abc/;  
  45.  index index.html index.htm index.php;  
  46. }  
  47. }  

繼續閱讀