#定义负载均衡设备的 Ip及设备状态
在需要使用负载的Server节点下添加
proxy_pass http://myServer;
upstream 每个设备的状态:
down 表示单前的server暂时不参与负载
weight 默认为1.weight越大,负载的权重就越大。
max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误
fail_timeout:max_fails 次失败后,暂停的时间。
backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
upstream a.com{
# hash $cookie_jsessionid;
hash $remote_addr consistent;
server 192.168.142.128:8080 weight=3;
server 192.168.142.129:80 weight=10;
# hash $cookie_jsessionid;
# server 192.168.142.130:80;
# ip_hash;
# hash_again 1;
# consistent_hash $remote_addr:可以根据客户端ip映射
# consistent_hash $request_uri: 根据客户端请求的uri映射
# consistent_hash $args:根据客户端携带的参数进行映射
}
server{
listen 80;
server_name a.com;
location / {
index index.html;
root /usr/html;
proxy_pass http://a.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
原创文章,作者:1402239773,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/271418.html