正向代理:代表客户端(用户、h5、pc、app)访问web服务器.
反向代理:代表web服务器(多台服务器)给客户端提供服务。
upstream tuling {### 失败次数3 失败超时时间30s 权重 5server 127.0.0.1:8080 max_fails=3 fail_timeout=30s weight=5;server 127.0.0.1:8081 max_fails=3 fail_timeout=30s weight=5;server 127.0.0.1:8082 backup;### backup 关键字 默认不对外提供服务,当其他服务器不可用时,会启用当前服务。}http {server {**location / {root html;index index.html;proxy_pass http://tuling;}}}
用途
- 分担整体服务器的压力(网站功能相同)
- 分配到不同的服务(网站功能不同)
负载均衡
- 轮询
- 权重
- iphash
- 最少连接
- fair
upstream aaa {server location:8081;server location:8082;}upstream aaa {server location:8081 weight=3; //通过计数器,访问该3次后在访问文下面一次server location:8082 weight=1;}upstream aaa {ip_hash;server location:8081;server location:8082;}upstream aaa {least_conn;server location:8081;server location:8082;}upstream aaa {server location:8081;server location:8082;fair;}
