Nginx反向代理YUM請求

1、安裝配置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

2、客戶端配置yum源訪問地址

配置base 源nginx

# 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
vim /etc/yum.repos.d/CentOS-Base.repo

配置epel源vim

[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
vim /etc/yum.repos.d/epel-7.repo

#以上操做主要爲將repo文件中指定的域名替換爲Nginx代理的server_name  在當前實驗環境中,即: mirrors.qiangungun.comcentos

3、設置本機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文件中域名保持一致

4、測試

[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服務器

相關文章
相關標籤/搜索