nginx负载均衡

环境准备

nginx服务器 192.168.134.166
web服务器 192.168.134.167
web服务器

192.168.134.168

1、安装nginx服务器

yum install nginx -y

2、web服务器配置并写实例

yum install httpd -y
echo " web test page, ip is `hostname -I`." >> /var/www/html/index.html
systemctl start httpd

3、写nginx配置文件,做负载均衡

cd /etc/nginx/conf.d/
vim vhost.conf
cat vhost.conf

upstream web_pools {
  server 192.168.134.168 weight=2;
  server 192.168.134.167 weight=1;
}

server {
  listen 80;
  server_name www1.test.cn;
  
  location / {
    proxy_pass http://web_pools;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

nginx -t # 检查
systemctl start nginx # 重启服务

还要记得做一下端口映射,在/etc/hosts文件中写:192.168.134.166 www1.test.cn 

你可能感兴趣的:(lvs)