1.负载均衡
upstream imooc { server 116.62.103.228:8001; server 116.62.103.228:8002; server 116.62.103.228:8003; } server { listen 80; server_name localhost jeson.t.imooc.io; #charset koi8-r; access_log /var/log/nginx/test_proxy.access.log main; resolver 8.8.8.8; location / { proxy_pass http://imooc;(默认是轮训) include proxy_params; }
upstream imooc { server 116.62.103.228:8001 down; server 116.62.103.228:8002 backup; server 116.62.103.228:8003 max_fails=1 fail_timeout=10s; } server { listen 80; server_name localhost jeson.t.imooc.io; #charset koi8-r; access_log /var/log/nginx/test_proxy.access.log main; resolver 8.8.8.8; location / { proxy_pass http://imooc; include proxy_params; }
1.加权
upstream imooc { server 116.62.103.228:8001; server 116.62.103.228:8002 weight=5(加权轮训); server 116.62.103.228:8003; } server { listen 80; server_name localhost jeson.t.imooc.io; #charset koi8-r; access_log /var/log/nginx/test_proxy.access.log main; resolver 8.8.8.8; location / { proxy_pass http://imooc; include proxy_params; }
2.ip分配
upstream imooc { ip_hash;(ip分配) server 116.62.103.228:8001; server 116.62.103.228:8002; server 116.62.103.228:8003; } server { listen 80; server_name localhost jeson.t.imooc.io; #charset koi8-r; access_log /var/log/nginx/test_proxy.access.log main; resolver 8.8.8.8; location / { proxy_pass http://imooc; include proxy_params; }
3.hash
upstream imooc { hash $request_uri; server 116.62.103.228:8001; server 116.62.103.228:8002; server 116.62.103.228:8003; } server { listen 80; server_name localhost jeson.t.imooc.io; #charset koi8-r; access_log /var/log/nginx/test_proxy.access.log main; resolver 8.8.8.8; location / { proxy_pass http://imooc; include proxy_params; }