nginx 负载均衡
负载均衡
http://nginx.org/en/docs/http/load_balancing.html
轮询 (不写 directive )
upstream myapp1 { server srv1.example.com; server srv2.example.com; server srv3.example.com; }
最小活跃连接数
upstream myapp1 { least_conn; server srv1.example.com; server srv2.example.com; server srv3.example.com; }
哈希
upstream myapp1 { ip_hash; server srv1.example.com; server srv2.example.com; server srv3.example.com; }
反向代理
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
单个
location /name/ { proxy_pass http://127.0.0.1/remote/; }
群组
http { upstream myapp1 { server srv1.example.com; server srv2.example.com; server srv3.example.com; } server { listen 80; location / { proxy_pass http://myapp1; } } }