负载均衡

60 阅读1分钟

1.负载均衡策略

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
	upstream httpds{
		server 127.0.0.1:8081 weight=8 down;
		server 127.0.0.1:8082 weight=2 ;
		server 127.0.0.1:8083 weight=1 backup;
	}
    server {
        listen       8080;
        server_name  localhost;
        location / {
			proxy_pass http://httpds;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
	server {
        listen       8081;
        server_name  localhost;
        location / {
            root   html/dist8081;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
	server {
        listen       8082;
        server_name  localhost;
        location / {
            root   html/dist8082;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
 

}

1. 权重:weight

  • 权重越大,转发到该台服务器上的机率越大

2. 上下线:down

  • 关闭该台服务器

4. 备用机:backup

  • 备用机配置