- 下载阿里云centos7的基础yum源文件:
Wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
- 获取到阿里的网络镜像文件后需要打开文件,将所有的http改为https,所有的gpgcheck=1改成gpgcheck=0
- Yum list | grep nginx
- 基于NGINX完成的负载均衡
- 配置nginx软件的yum源
【nginx-stable】
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signning.key
- 修改/etc/resolv.conf
nameserver 网关
- 安装nginx
yum install -y nginx
- 启动
systenctl start nginx
注意:nginx使用tcp80端口 ,注意与其他web服务冲突
- 配置反向代理的主机是谁
vi /etc/nginx/nginx.conf
http{
…
upstream backend{
server 192.168.200.100:80; apache1主机ip
server 192.168.200.200:80; apache2主机ip
}
}
6.配置nginx开启反向代理访问
vi /etc/nginx/conf.d/default.conf
server {
….
location / {
proxy_pass http://backend;
proxy_redirent default;
#设置代理
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}