配置nginx负载均衡

实验环境准备:

主机:192.168.199.142

两个服务端:192.168.199.150(服务1)

                      192.168.199.148(服务2)

1,配置服务1和2
[root@localhost nginx]# find / -name html
/var/www/html
/usr/share/doc/pam-1.1.8/html
/usr/share/doc/pcre-devel-8.32/html
/usr/share/nginx/html
[root@localhost nginx]# cd /usr/share/nginx/html
[root@localhost html]# ls
50x.html  index.html
[root@localhost html]# cp index.html index.html.bak
[root@localhost html]# ls
50x.html  index.html  index.html.bak
[root@localhost html]# vim index.html

 

2,修改Nginx配置文件
[root@localhost ~]# find / -name nginx
/etc/logrotate.d/nginx
/etc/nginx
/var/log/nginx
/var/cache/nginx
/usr/sbin/nginx
/usr/lib64/nginx
/usr/share/nginx
/usr/libexec/initscripts/legacy-actions/nginx
[root@localhost ~]# cd /etc/nginx
[root@localhost nginx]# ls
conf.d          mime.types  nginx.conf   uwsgi_params
fastcgi_params  modules     scgi_params
[root@localhost nginx]# vim nginx.conf
[root@localhost nginx]# systemctl restart nginx

3,自定义http的模块的权重
  upstream webServer {
      server 192.168.199.150:80 weight=3;
      server 192.168.199.148:80 weight=7;

}
    server{
        listen 80;
        server_name 192.168.199.142
        location / {
                proxy_pass http://webServer;
}
}

任意测试一个

 

你可能感兴趣的:(nginx,负载均衡,服务器)