nginx 负载均衡的三种参数设置
1、
usernobody; worker_processes4;//一般是CPU的核心数 events{ worker_connections1024; } http{ upstreammypro{ server182.13.32.12; server213.11.23.24; } server{ listen8080; location/{ proxy_passhttp://mypro; } } }
2、加入ip_hash,让同一个用户落到同一台机器上
usenobody; worker_processes4;//一般是CPU的核心数 events{ worker_connections1024; } http{ upstreammypro{ ip_hash; server182.13.32.12; server213.11.23.24; } server{ listen8080; location/{ proxy_passhttp://mypro; } } }
3、加入权重
usenobody; worker_processes4;//一般是CPU的核心数 events{ worker_connections1024; } http{ upstreammypro{ server182.13.32.12weight=2;//被访问到的概率 server213.11.23.24; } server{ listen8080; location/{ proxy_passhttp://mypro; } } }
负载均衡的进程可以单独启动
/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/fzjh.conf