Nginx反向代理YUM请求
一、安装配置Nginx服务(Nginx服务器上建议先关闭iptables/firewalld服务,待实验完成后再根据实际情况配置)
[root@localhost ~]# yum install nginx -y #安装Nginx
[root@localhost ~]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# vim proxy.conf #配置代理规则
server{
listen 80;
server_name mirrors.qiangungun.com;
location /centos/ { #yum base源代理配置
proxy_pass http://mirrors.aliyun.com/centos/ ;
}
location /epel/ { #yum epel源代理设置
proxy_pass http://mirrors.aliyun.com/epel/ ;
}
}
#如果有其他YUM需要代理参照以上配置即可
[root@localhost conf.d]# nginx -t #检查语法并重启
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost conf.d]# systemctl restart nginx
二、客户端配置yum源访问地址
配置base 源
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - mirrors.qiangungun.com
failovermethod=priority
baseurl=http://mirrors.qiangungun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.qiangungun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.qiangungun.com
failovermethod=priority
baseurl=http://mirrors.qiangungun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.qiangungun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.qiangungun.com
failovermethod=priority
baseurl=http://mirrors.qiangungun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.qiangungun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.qiangungun.com
failovermethod=priority
baseurl=http://mirrors.qiangungun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.qiangungun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.qiangungun.com
failovermethod=priority
baseurl=http://mirrors.qiangungun.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.qiangungun.com/centos/RPM-GPG-KEY-CentOS-7
配置epel源
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.qiangungun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.qiangungun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.qiangungun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
#以上操作主要为将repo文件中指定的域名替换为Nginx代理的server_name 在当前实验环境中,即: mirrors.qiangungun.com
三、设置本机hosts解析
[root@rsync-client yum.repos.d]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.150.131 mirrors.qiangungun.com #172.16.150.131为Nginx服务器地址 mirrors.qiangungun.com 为Nginx代理配置的server_name 该域名还需要和repo文件中域名保持一致
四、测试
[root@rsync-client yum.repos.d]# ping mirrors.qiangungun.com #测试hosts配置
[root@rsync-client yum.repos.d]# yum makecache #测试yum请求
抄自于:https://www.jb51.net/article/153773.htm
"一劳永逸" 的话,有是有的,而 "一劳永逸" 的事却极少