nginx负载均衡

第一步:下载nginx
╭─root@zxw ~
╰─➤ yum install nginx -y
第二步:编写负载均衡规则
─root@zxw ~
╰─➤ vim /etc/nginx/nginx.conf
# for more information.
include /etc/nginx/conf.d/*.conf;
upstream zhao {
server 192.168.126.6 weight=6 max_fails=2 fail_timeout=2;
server 192.168.126.7 weight=2 max_fails=2 fail_timeout=2;
}
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
proxy_pass http://zhao;
}
第三步:检查并重启
╭─root@zxw ~
╰─➤ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
╭─root@zxw ~
╰─➤ systemctl restart nginx

访问网站

原文地址:https://www.cnblogs.com/itzhao/p/11249938.html