本想用lua玩一把,但我发现我的要求很简单,直接用upstream的weight和backup就OK了。

于是,这样玩了一把。

作个记录。

1)、down 表示当前的server暂时不参与负载
2)、weight 默认为1.weight越大,负载的权重就越大。
3)、backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。

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

    sendfile        on;
    keepalive_timeout  65;

    upstream my_server { 
              server 1.2.3.4:7999 weight=10; 
              server 127.0.0.1:8888 backup; 
        }

    server {
        listen       8080;
        server_name  localhost;

        location / {
            proxy_pass http://my_server;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
    
    server {
        listen       8888;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

 

转载于:https://www.cnblogs.com/aguncn/p/10724717.html

更多推荐