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 xxxx;  
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 源

# 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 - xxxx
failovermethod=priority
baseurl=http://xxxx/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://xxxx/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.qiangungun.com
failovermethod=priority
baseurl=http://xxxx/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://xxxx/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.qiangungun.com
failovermethod=priority
baseurl=http://xxxx/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://xxxx/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://xxxx/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://xxxx/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.qiangungun.com
failovermethod=priority
baseurl=http://xxxx/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://xxxx/centos/RPM-GPG-KEY-CentOS-7
vim /etc/yum.repos.d/CentOS-Base.repo

配置epel源

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://xxxx/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://xxxx/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://xxxx/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
vim /etc/yum.repos.d/epel-7.repo

#以上操作主要为将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.90.98 xxxx   #172.16.90.98 为Nginx服务器地址  xxxx 为Nginx代理配置的server_name 该域名还需要和repo文件中域名保持一致

四、测试

[root@rsync-client yum.repos.d]# ping xxxx         #测试hosts配置
[root@rsync-client yum.repos.d]# yum makecache                 #测试yum请求
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值