nginx反向代理進(jìn)行yum配置的步驟詳解
part.0 使用背景
公司內(nèi)網(wǎng)服務(wù)器不能直接通過Internet上網(wǎng),但為了與外網(wǎng)通信和同步時間等,會指定那么幾臺服務(wù)器可以訪問Internet。這里就是通過能上網(wǎng)的機(jī)器作為代理,制作內(nèi)網(wǎng)使用的yum倉庫。
part.1 環(huán)境
內(nèi)網(wǎng)dns(推薦,非必須,因為可使用IP代替)
一臺能上Internet的服務(wù)器A
不能上Internet的服務(wù)器能與A服務(wù)器通信
part.2 nginx安裝
在可連接外網(wǎng)的A中安裝nginx
yum install nginx
part.3 nginx配置
在主機(jī)A中添加nginx配置
$ cd /etc/nginx/conf.d $ vim proxy.conf
server { listen 80; #listen [::]:80; server_name mirrors.yourdomain.com; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/html; location /ubuntu/ { proxy_pass http://mirrors.aliyun.com/ubuntu/ ; } location /centos/ { proxy_pass http://mirrors.aliyun.com/centos/ ; } location /epel/ { proxy_pass http://mirrors.aliyun.com/epel/ ; } }
part.4 配置yum repo 源
修改無法連接外網(wǎng)的主機(jī)B 的repo文件。
$ cat /etc/yum.repos.d/CentOS-7.repo
[base] name=CentOS-$releasever - Base - mirrors.yourdomain.com failovermethod=priority baseurl=http://mirrors.yourdomain.com/centos/$releasever/os/$basearch/ http://mirrors.yourdomain.com/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=http://mirrors.yourdomain.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - mirrors.yourdomain.com failovermethod=priority baseurl=http://mirrors.yourdomain.com/centos/$releasever/updates/$basearch/ http://mirrors.yourdomain.com/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=http://mirrors.yourdomain.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - mirrors.yourdomain.com failovermethod=priority baseurl=http://mirrors.yourdomain.com/centos/$releasever/extras/$basearch/ http://mirrors.yourdomain.com/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=http://mirrors.yourdomain.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - mirrors.yourdomain.com failovermethod=priority baseurl=http://mirrors.yourdomain.com/centos/$releasever/centosplus/$basearch/ http://mirrors.yourdomain.com/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=http://mirrors.yourdomain.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - mirrors.yourdomain.com failovermethod=priority baseurl=http://mirrors.yourdomain.com/centos/$releasever/contrib/$basearch/ http://mirrors.yourdomain.com/centos/$releasever/contrib/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib gpgcheck=1 enabled=0 gpgkey=http://mirrors.yourdomain.com/centos/RPM-GPG-KEY-CentOS-7
part.5 配置hosts
$ cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.193 mirrors.yourdomain.com # 確保A 主機(jī)IP 和后面的反向代理地址
part.6 配置iptables
ping mirrors.yourdomain.com #報錯 沒有到主機(jī)的路由
此時查看B主機(jī)中的iptables信息,發(fā)現(xiàn)無法訪問80,可以在最前添加一條規(guī)則。
$ iptables -nvL 8155 28M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 11761 985K INPUT_direct all -- * * 0.0.0.0/0 0.0.0.0/0 11761 985K INPUT_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0 11761 985K INPUT_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate INVALID 11756 985K REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
$ iptables -I INPUT -p tcp --dport 80 -j ACCEPT
part.7 測試是否成功
在B主機(jī)中進(jìn)行,yum makecache操作。來判斷是否能進(jìn)行yum操作。
$ yum clean all $ yum makecache
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關(guān)文章
nginx搭建圖片服務(wù)器的過程詳解(root和alias的區(qū)別)
這篇文章主要介紹了nginx搭建圖片服務(wù)器(root和alias的區(qū)別)的過程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10Nginx 配置 ModSecurity 網(wǎng)絡(luò)應(yīng)用防火墻實現(xiàn)
這篇文章主要介紹了Nginx 配置 ModSecurity 網(wǎng)絡(luò)應(yīng)用防火墻實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-12-12Nginx geoip模塊實現(xiàn)地區(qū)性負(fù)載均衡
相信做過awstats的都用過開源的geoip.dat ip數(shù)據(jù)庫,剛好nginx wiki上有g(shù)eoip 模塊,這樣就可以實現(xiàn)地區(qū)性的負(fù)載均衡,但是maxmind 的ip數(shù)據(jù)庫對中國的支持不算太好,不過現(xiàn)在也不錯了~2010-12-12Nginx重定向后請求參數(shù)丟失的原因分析及解決方案
在日常開發(fā)和運維中,我們經(jīng)常會遇到需要使用 Nginx 進(jìn)行反向代理的場景,但在配置 proxy_pass 時,有時候可能會遇到請求參數(shù)丟失的問題,在這篇文章中,我們將會詳細(xì)探討這個問題并給出幾種解決方案,需要的朋友可以參考下2023-11-11nginx-proxy-manager初次登錄報錯502?bad?gateway解決
這篇文章主要給大家介紹了關(guān)于nginx-proxy-manager初次登錄報錯502?bad?gateway的解決辦法,502?Bad?Gateway服務(wù)器作為網(wǎng)關(guān)或者代理時,為了完成請求訪問下一個服務(wù)器,但該服務(wù)器返回了非法的應(yīng)答,需要的朋友可以參考下2024-04-04詳解Nginx 出現(xiàn) 403 Forbidden 的解決辦法
本篇文章主要介紹了詳解Nginx 出現(xiàn) 403 Forbidden 的解決辦法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08