worker321 发表于 2018-11-11 13:04:19

nginx load balance

                                       nginx load balance配置
  本文大概描述负载均衡的一般配置。关于upstream和sticky的问题可参看博文http://3006939.blog.51cto.com/2996939/1108527
  安装nginx:
  


[*]wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
[*]rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm
[*]yum install nginx
  

  vim /etc/nginx/conf.d/balance.conf
  


[*]upstream backend {
[*]sticky;
[*]check interval=5000 rise=2 fall=5 timeout=1000;
[*]check_http_send "GET /health.html HTTP/1.1\r\n\r\n";
[*]server      192.168.0.6:8080;
[*]server      192.168.2.130:8080;
[*]server      192.168.0.4:8080;
[*]server      192.168.0.5:8080;
[*]}
[*]
[*]server {
[*]listen 80;
[*]location /system/console {
[*]    root /var/www/html/nginx/empty;
[*]      client_max_body_size    300m;
[*]}
[*]location /libs {
[*]    root /var/www/webstatic;
[*]      client_max_body_size    300m;
[*]}
[*]
[*]location / {
[*]    client_max_body_size 300m; #此处设置的数值决定了nginx上传文件大小的限制
[*]    proxy_pass http://backend;
[*]    proxy_set_headerX-Real-IP$remote_addr;
[*]    add_header X-Real-IP$upstream_addr;
[*]    proxy_buffering off;
[*]}
[*]}
[*]server
[*]{
[*] listen 80;
[*] server_name test.abc.org abc.abc.org www.abc.com abc.com;
[*] access_log   /var/log/nginx/xuanran_acc.log;
[*] location / {
[*] root /home/abc/test;
[*] index index.html index.htm index.php;
[*]}
[*]}
[*]server
[*]{
[*] listen 80;
[*] server_name www.abc.org abc.org;
[*] access_log   /var/log/nginx/abc_acc.log;
[*]location / {
[*] root /home/abc/;
[*] index index.html index.htm index.php;
[*]}
[*]}
  



页: [1]
查看完整版本: nginx load balance