nginx 的负载均衡并不复杂 几行代码就能解决
ubuntu系统
1.进入 nginx 配置文件目录 新建一个conf文件
vim fzjh.conf
2. 写入代码
worker_processes 1;
events {
worker_connections 1024;
}
http{
upstream mypro{
# ip_hash; #如果开启 则 该ip的用户只能访问到第一次访问的地址 一般如果需要记录 用户的登录信息 则需开启
server 120.26.36.177 ;
server 60.205.235.128;
# server 后面必须为 ip地址
server{
listen 3000;
location / {
root /var/www/html/;
index index.html index.php;
proxy_pass http://mypro;
}
}
}
3.保存文件之后 重启nginx
killall -9 nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/fzjh.conf #-c 后面加上的是 新写的 配置文件的地址 用于测试