nginx反向代理进行yum配置的步骤详解

 更新时间:2018年12月30日 09:13:45   作者:偏执可破顽石  
这篇文章主要给大家介绍了关于nginx反向代理进行yum配置的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

part.0 使用背景

公司内网服务器不能直接通过Internet上网,但为了与外网通信和同步时间等,会指定那么几台服务器可以访问Internet。这里就是通过能上网的机器作为代理,制作内网使用的yum仓库。

part.1 环境

内网dns(推荐,非必须,因为可使用IP代替)

一台能上Internet的服务器A

不能上Internet的服务器能与A服务器通信

part.2 nginx安装

在可连接外网的A中安装nginx

yum install nginx

part.3 nginx配置

在主机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 源

修改无法连接外网的主机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 主机IP 和后面的反向代理地址

part.6 配置iptables

ping mirrors.yourdomain.com
#报错 没有到主机的路由

此时查看B主机中的iptables信息,发现无法访问80,可以在最前添加一条规则。

$ 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主机中进行,yum makecache操作。来判断是否能进行yum操作。

$ yum clean all
$ yum makecache

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。

相关文章

  • 在Nginx服务器下配置StartSSL和SSL的教程

    在Nginx服务器下配置StartSSL和SSL的教程

    这篇文章主要介绍了在Nginx服务器下配置StartSSL和SSL的教程,其中申请证书的步骤确实比较麻烦一些,不过出于安全考虑:p需要的朋友可以参考下
    2015-07-07
  • 一文弄懂Nginx的location匹配的实现

    一文弄懂Nginx的location匹配的实现

    这篇文章主要介绍了一文弄懂Nginx的location匹配的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-02-02
  • nginx实现负载均衡与实例解读

    nginx实现负载均衡与实例解读

    这篇文章主要介绍了nginx实现负载均衡与实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2025-04-04
  • nginx 与后台端口冲突的解决

    nginx 与后台端口冲突的解决

    这篇文章主要介绍了nginx 与后台端口冲突的解决,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-03-03
  • Nginx 配置过程的具体步骤

    Nginx 配置过程的具体步骤

    这篇文章主要介绍了Nginx 配置过程的详细介绍的相关资料,希望通过本文能帮助到大家,让大家掌握如何配置Nginx,需要的朋友可以参考下
    2017-10-10
  • Nginx反代Mogilefs分布式储存示例详解

    Nginx反代Mogilefs分布式储存示例详解

    这篇文章主要给大家介绍了关于Nginx反代Mogilefs分布式储存的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Nginx具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-11-11
  • nginx超时设置详细介绍

    nginx超时设置详细介绍

    这篇文章主要介绍了nginx超时设置详细介绍的相关资料,需要的朋友可以参考下
    2017-05-05
  • 定期删除OpenResty/Nginx大日志文件的方法

    定期删除OpenResty/Nginx大日志文件的方法

    这篇文章主要介绍了定期删除OpenResty/Nginx大日志文件的方法,文中通过代码示例给大家讲解的非常详细,对大家的学习或工作有一定的帮助,需要的朋友可以参考下
    2024-05-05
  • nginx服务器access日志中大量400 bad request错误的解决方法

    nginx服务器access日志中大量400 bad request错误的解决方法

    这篇文章主要介绍了nginx服务器access日志中大量400 bad request错误的解决方法,本文结论是空主机头导致的大量400错误日志,关闭默认主机的日志记录就可以解决问题,需要的朋友可以参考下
    2015-01-01
  • 使用 nginx 搭建代理服务器(正向代理 https 网站)的详细步骤

    使用 nginx 搭建代理服务器(正向代理 https 网站)的详细步骤

    这篇文章主要介绍了使用 nginx 搭建代理服务器(正向代理 https 网站)指南的相关操作,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧
    2024-08-08

最新评论