使用nginx+apache搭建负载均衡

搭建环境:

两台centos。

主机一:192.168.1.6  安装nginx以及apche

主机二:192.168.1.7 安装apache

主机一配置:

配置阿里云的yum源:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum makecache

安装epel源

yum -y install epel*

安装nginx、apache

[root@6 yum.repos.d]# yum -y install nginx  httpd

写一个访问页面:

[root@6 ~]# echo "<h1>我是主机一。</h1>" > /var/www/html/index.html

root@6 ~]# systemctl restart httpd.service

访问:

[root@6 ~]# curl 192.168.1.6
<h1>我是主机一。</h1>

配置nginx:

[root@6 ~]# vim /etc/nginx/nginx.conf

[root@6 nginx]# systemctl restart nginx

主机二配置:

安装apache:

[root@7 ~]# yum -y install httpd

写一个访问页面:

[root@7 ~]# echo "<h1>我是主机二。</h1>" > /var/www/html/index.html
[root@7 ~]# systemctl restart httpd

访问是没问题的:

[root@7 ~]# curl 192.168.1.7

<h1>我是主机二。</h1>

测试:

刷新网页

猜你喜欢

转载自www.cnblogs.com/meml/p/12443120.html