阅读更多
nginx负载均衡
http
{
#include conf/mime.types;
include mime.types;
default_type application/octet-stream;
include vhost/*.conf;
keepalive_timeout 120;
tcp_nodelay on;
upstream www.samson.com {
server 127.0.0.1:8080;
# server 192.168.1.3:80;
# server 192.168.1.4:80;
# server 192.168.1.5:80;
}
server
{
listen 80;
server_name www.samson.com;
location / {
proxy_pass http://www.samson.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;
}
log_format www_samson_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/www.log www_samson_com;
}
}
在http节点里添加:
#定义负载均衡设备的 Ip及设备状态
upstream myServer {
server 127.0.0.1:9090 down;
server 127.0.0.1:8080 weight=2;
server 127.0.0.1:6060;
server 127.0.0.1:7070 backup;
}
在需要使用负载的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机器。所以这台机器压力会最轻。