先准备三台虚拟机,一台装nginx,另外两台装apache
安装之前都需关闭防火墙
两台apache:
yum -y install httpd
echo web1 > /var/www/html/index.html
systemctl start httpd
nginx:
yum -y install gcc pcre-devel zlib-devel openssl-devel
下载所需文件
tar zxf ····
cd nginx包
./configure && make && make install
/usr/loacl/nginx/sbin/nginx
下载完毕之后上传安装包并解压最后开启nginx服务
vim /usr/local/nginx/conf/nginx.conf
进入配置文件
location / {
proxy_pass http://webservers;
}
找到43行并修改如上(webservers可替换)
upstream webservers {
server 192.168.254.128:80;
server 192.168.254.129:80;
}
找空白位置写入加入的apache的ip,实现负载均衡
/usr/loacl/nginx/sbin/nginx -s reload
重启nginx