nginx反向代理内网yum

目的:解决内网服务器无法访问yum服务,而搭建内网yum代理服务器
一、安装配置Nginx服务(Nginx服务器上建议先关闭iptables/firewalld服务,待实验完成后再根据实际情况配置)
yum install nginx -y
cd /etc/nginx/conf.d/
vim proxy.conf

server{
listen 80;
server_name mirrors.cxsw.com;  
location  /centos/ {         #yum  base源代理配置
   proxy_pass http://mirrors.aliyun.com/centos/ ;
  }
location  /epel/ {          #yum epel源代理设置
   proxy_pass http://mirrors.aliyun.com/epel/ ;
  }
}

nginx -t #检查语法并重启

二、客户端配置yum源访问地址
/etc/yum.repos.d/CentOS-Base.repo #配置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 - mirrors.cxsw.com
failovermethod=priority
baseurl=http://mirrors.cxsw.com/centos/$releasever/os/$basearch/
              http://mirrors.cxswcs.com/centos/$releasever/os/$basearch/
              http://mirrors.cloud.cxswcs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cxsw.com/centos/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.cxsw.com
failovermethod=priority
baseurl=http://mirrors.cxsw.com/centos/$releasever/updates/$basearch/
        http://mirrors.cxswcs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.cxswcs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cxsw.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.cxsw.com
failovermethod=priority
baseurl=http://mirrors.cxsw.com/centos/$releasever/extras/$basearch/
        http://mirrors.cxswcs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.cxswcs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cxsw.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.cxsw.com
failovermethod=priority
baseurl=http://mirrors.cxsw.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cxswcs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.cxswcs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.cxsw.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.cxsw.com
failovermethod=priority
baseurl=http://mirrors.cxsw.com/centos/$releasever/contrib/$basearch/
              http://mirrors.cxswcs.com/centos/$releasever/contrib/$basearch/
              http://mirrors.cloud.cxswcs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.cxsw.com/centos/RPM-GPG-KEY-CentOS-7

/etc/yum.repos.d/epel.repo #配置epel.repo源

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

三、设置本机hosts解析
vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.233.3 mirrors.cxsw.com

四、测试

[root@localhost yum.repos.d]# ping mirrors.cxsw.com
PING mirrors.cxsw.com (192.168.233.3) 56(84) bytes of data.
64 bytes from mirrors.cxsw.com (192.168.233.3): icmp_seq=1 ttl=64 time=0.316 ms
64 bytes from mirrors.cxsw.com (192.168.233.3): icmp_seq=2 ttl=64 time=0.763 ms
64 bytes from mirrors.cxsw.com (192.168.233.3): icmp_seq=3 ttl=64 time=0.788 ms
64 bytes from mirrors.cxsw.com (192.168.233.3): icmp_seq=4 ttl=64 time=0.313 ms
64 bytes from mirrors.cxsw.com (192.168.233.3): icmp_seq=5 ttl=64 time=0.322 ms
^C
--- mirrors.cxsw.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4010ms
rtt min/avg/max/mdev = 0.313/0.500/0.788/0.225 ms


yum clean all
yum makecache
[root@localhost nginx]# tail -f /var/log/nginx/access.log
192.168.233.4 - - [06/Feb/2023:14:20:10 +0800] "GET /epel/7/x86_64/repodata/a9c7a8cbffb5e5c07cbf31397bf11d9f7755e96c72ce897e04dba556dd4cc0eb-comps-Everything.x86_64.xml.gz HTTP/1.1" 200 100956 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:20:13 +0800] "GET /centos/7/os/x86_64/repodata/d6d94c7d406fe7ad4902a97104b39a0d8299451832a97f31d71653ba982c955b-filelists.sqlite.bz2 HTTP/1.1" 200 7508416 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:20:16 +0800] "GET /epel/7/x86_64/repodata/b8ab124ce8b2ecc0afaa1248f05f72f3d2a830decced09ca13bd58538a32d5ba-updateinfo.xml.bz2 HTTP/1.1" 200 1091701 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:20:17 +0800] "GET /epel/7/x86_64/repodata/d9dac75e0d44976e326df0b694bb515726ea2f32f9b207a0e6aadae66b1cdeea-prestodelta.xml.gz HTTP/1.1" 200 1821 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:20:24 +0800] "GET /centos/7/os/x86_64/repodata/ecaab5cc3b9c10fefe6be2ecbf6f9fcb437231dac3e82cab8d9d2cf70e99644d-other.sqlite.bz2 HTTP/1.1" 200 2676918 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:21:02 +0800] "GET /epel/7/x86_64/repodata/806ac38a1d133072220213748cab12566d1902a91f04e8b150bb2fea9c0c06eb-primary.sqlite.bz2 HTTP/1.1" 200 7332715 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:21:04 +0800] "GET /centos/7/extras/x86_64/repodata/511a574b4c3f907f9acfe5603566958fb6f09137292c5cd5d5d57c298864790f-primary.sqlite.bz2 HTTP/1.1" 200 255402 "-" "urlgrabber/3.10 yum/3.4.3" "-"

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,367评论 6 512
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,959评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 166,750评论 0 357
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,226评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,252评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,975评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,592评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,497评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,027评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,147评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,274评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,953评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,623评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,143评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,260评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,607评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,271评论 2 358

推荐阅读更多精彩内容

  • 1.nginx介绍1.1 nginx的特点nginx的基本特性 对静态资源高速高并发访问及缓存可使用反向代理加速,...
    Joening阅读 614评论 0 1
  • 奔着装nginx 安装 yum 的一些记录 之前在aliyun的ECS上 直接可以看到nginx 在新服务器上查看...
    QTong阅读 2,387评论 1 1
  • 介绍: Nginx是一个HTTP和反向代理的服务器,也是一个IMAP/POP/SMTP服务器 安装过程 环境:ub...
    hlchengzi阅读 242评论 0 1
  • 国密Nginx容器实战 1.背景 目前国密SSL(TLCP)已经逐步开始推广并实际使用,国密SSL实验室(www....
    坤_3ea8阅读 712评论 0 0
  • 本文介绍一些负载均衡和反向代理的一些基本概念,然后介绍如何基于nginx实现,包括两种安装nginx的方法:yum...
    Michael_Zhou阅读 408评论 0 7