网关代理
应用场景
反向代理proxy_pass
proxy_pass http://xxx.com
# 比如:
location / {
proxy_pass http://www.xiumubai.com; #注意:没有配置证书的话是不能配置https的地址
# root /www/ng-test/foo;
# index index.html index.htm;
}
负载均衡
代理到多台服务器
upstream httpd {
server http://www.xiumubai.com weight=8;
server http://interview.xiumubai.com weight=2 down bakcup;
}
location / {
proxy_pass httpd;
# root /www/ng-test/foo;
# index index.html index.htm;
}
weight-权重
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
upstream httpd {
server 127.0.0.1:8050 weight=10 down;
server 127.0.0.1:8060 weight=1;
server 127.0.0.1:8060 weight=1 backup;
}
- down:表示当前的server暂时不参与负载
- weight:默认为1.weight越大,负载的权重就越大。
- backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。
其他参数:
- ip_hash 根据客户端的ip地址转发同一台服务器,可以保持回话。
- least_conn 最少连接访问 url_hash 根据用户访问的url定向转发请求
- fair 根据后端服务器响应时间转发请求