公司的Docker私有registry已经搭建好了,用官方的registry image很容易就搭建好了。现在就是要用nginx的反向代理把它放出来,以便在外网可以访问。
我的上一篇blog 讲了如何配置nginx反向代理。所以本文主要是讲我在使用中遇到的问题及解决方法。

这是我最初的nginx配置

upstream my_docker_registry  {
server 192.168.100.48:8443; # registry.renhl.com
} ## START hub.renhl.com ##
server {
server_name registry.renhl.com; listen 80;
listen 443 ssl; ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key; root /usr/local/nginx/html;
index index.html; allow 111.206.238.12;
allow 111.206.238.94;
deny all; location / {
proxy_pass https://my_docker_registry;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
## END hub.renhl.com ##
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

然后我开始push image到这个registry上,发现报错了:

The push refers to a repository [hub.renhl.com/mediawiki] (len: 1)
unable to ping registry endpoint https://hub.renhl.com/v0/
v2 ping attempt failed with error: Get https://hub.renhl.com/v2/: x509: certificate is valid for renhl.com, not hub.renhl.com
v1 ping attempt failed with error: Get https://hub.renhl.com/v1/_ping: x509: certificate is valid for renhl.com, not hub.renhl.com
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

我已经把这个私有registry的ssl证书放在/etc/docker/certs.d下,应该不会出错呀。仔细看了这个配置后,我发现nginx的没有使用私有registry的ssl证书,而是使用了自己的证书/etc/nginx/ssl/nginx.crt。问题应该出在这儿,把nginx的ssl证书换成私有registry的ssl证书。

# 使用私有registry的ssl证书
ssl_certificate /opt/renhl_com_docker_registry/certs/registry_renhl_com.crt;
ssl_certificate_key /opt/renhl_com_docker_registry/certs/registry_renhl_com.key;
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

好,重启nginx再Push一下试试,又报错了:

The push refers to a repository [registry.renhl.com/mediawiki] (len: 1)
846b3100eaa8: Buffering to Disk
dial tcp: lookup my_docker_registry: no such host
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

原因很清楚,反向代理把my_docker_registry,做为host发到了客户端了,要让反向代理设置正确的host。把下面的一行加到nginx配置里。

proxy_set_header        Host            $host;
  • 1
  • 1

重启nginx push一下试试,还报错:

Error parsing HTTP response: invalid character '<' looking for beginning of value: "<html>\r\n<head><title>413 Request Entity Too Large</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>413 Request Entity Too Large</h1></center>\r\n<hr><center>nginx/1.4.6 (Ubuntu)</center>\r\n</body>\r\n</html>\r\n"
  • 1
  • 1

我push的imgage太大,被nginx拒绝了。问了Google以后,在nginx的配置加入下面的两行:

client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads
# required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
chunked_transfer_encoding on;
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

再push image,成功了!这是最后的配置:

upstream my_docker_registry  {
server 192.168.100.48:8443; # registry.renhl.com
} ## START registry.renhl.com ##
server {
server_name registry.renhl.com; listen 80;
listen 443 ssl; # 使用私有registry的ssl证书
ssl_certificate /opt/renhl_com_docker_registry/certs/registry_renhl_com.crt;
ssl_certificate_key /opt/renhl_com_docker_registry/certs/registry_renhl_com.key; root /usr/local/nginx/html;
index index.html; allow 111.206.238.12;
allow 111.206.238.94;
deny all; client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads # required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
chunked_transfer_encoding on; location / {
proxy_pass https://my_docker_registry;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
## END registry.renhl.com ##
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

如果你在配置docker的私有registry时碰到了同样的问题,希望这篇博客能帮到你,:)

参考资料:
http://stackoverflow.com/questions/31730319/how-to-push-docker-images-through-reverse-proxy-to-artifactory

 
0
0

公司的Docker私有registry已经搭建好了,用官方的registry image很容易就搭建好了。现在就是要用nginx的反向代理把它放出来,以便在外网可以访问。
我的上一篇blog 讲了如何配置nginx反向代理。所以本文主要是讲我在使用中遇到的问题及解决方法。

这是我最初的nginx配置

upstream my_docker_registry  {
server 192.168.100.48:8443; # registry.renhl.com
} ## START hub.renhl.com ##
server {
server_name registry.renhl.com; listen 80;
listen 443 ssl; ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key; root /usr/local/nginx/html;
index index.html; allow 111.206.238.12;
allow 111.206.238.94;
deny all; location / {
proxy_pass https://my_docker_registry;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
## END hub.renhl.com ##
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

然后我开始push image到这个registry上,发现报错了:

The push refers to a repository [hub.renhl.com/mediawiki] (len: 1)
unable to ping registry endpoint https://hub.renhl.com/v0/
v2 ping attempt failed with error: Get https://hub.renhl.com/v2/: x509: certificate is valid for renhl.com, not hub.renhl.com
v1 ping attempt failed with error: Get https://hub.renhl.com/v1/_ping: x509: certificate is valid for renhl.com, not hub.renhl.com
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

我已经把这个私有registry的ssl证书放在/etc/docker/certs.d下,应该不会出错呀。仔细看了这个配置后,我发现nginx的没有使用私有registry的ssl证书,而是使用了自己的证书/etc/nginx/ssl/nginx.crt。问题应该出在这儿,把nginx的ssl证书换成私有registry的ssl证书。

# 使用私有registry的ssl证书
ssl_certificate /opt/renhl_com_docker_registry/certs/registry_renhl_com.crt;
ssl_certificate_key /opt/renhl_com_docker_registry/certs/registry_renhl_com.key;
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

好,重启nginx再Push一下试试,又报错了:

The push refers to a repository [registry.renhl.com/mediawiki] (len: 1)
846b3100eaa8: Buffering to Disk
dial tcp: lookup my_docker_registry: no such host
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

原因很清楚,反向代理把my_docker_registry,做为host发到了客户端了,要让反向代理设置正确的host。把下面的一行加到nginx配置里。

proxy_set_header        Host            $host;
  • 1
  • 1

重启nginx push一下试试,还报错:

Error parsing HTTP response: invalid character '<' looking for beginning of value: "<html>\r\n<head><title>413 Request Entity Too Large</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>413 Request Entity Too Large</h1></center>\r\n<hr><center>nginx/1.4.6 (Ubuntu)</center>\r\n</body>\r\n</html>\r\n"
  • 1
  • 1

我push的imgage太大,被nginx拒绝了。问了Google以后,在nginx的配置加入下面的两行:

client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads
# required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
chunked_transfer_encoding on;
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

再push image,成功了!这是最后的配置:

upstream my_docker_registry  {
server 192.168.100.48:8443; # registry.renhl.com
} ## START registry.renhl.com ##
server {
server_name registry.renhl.com; listen 80;
listen 443 ssl; # 使用私有registry的ssl证书
ssl_certificate /opt/renhl_com_docker_registry/certs/registry_renhl_com.crt;
ssl_certificate_key /opt/renhl_com_docker_registry/certs/registry_renhl_com.key; root /usr/local/nginx/html;
index index.html; allow 111.206.238.12;
allow 111.206.238.94;
deny all; client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads # required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
chunked_transfer_encoding on; location / {
proxy_pass https://my_docker_registry;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
## END registry.renhl.com ##
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

如果你在配置docker的私有registry时碰到了同样的问题,希望这篇博客能帮到你,:)

参考资料:
http://stackoverflow.com/questions/31730319/how-to-push-docker-images-through-reverse-proxy-to-artifactory

 
0
0

为docker私有registry配置nginx反向代理的更多相关文章

  1. CentOS 7 学习(二) 配置Nginx反向代理

    CentOS 7 学习(二) 配置Nginx反向代理 Nginx可以通过php-fpm来运行PHP程序,也可以转向apache,让apache调用php程序来运行. 不过对于Nginx来说,其反向代理 ...

  2. 使用SSL配置Nginx反向代理的简单指南

    反向代理是一个服务器,它接收通过Web发出的请求,即http和https,然后将它们发送到后端服务器(或服务器).后端服务器可以是单个或一组应用服务器,如Tomcat,wildfly或Jenkins等 ...

  3. 配置LANMP环境(7)-- 配置nginx反向代理,与配置apache虚拟主机

    一.配置nginx反向代理 1.修改配置文件 vim /etc/nginx/nginx.conf 在35行http下添加一下内容: include /data/nginx/vhosts/*.conf; ...

  4. [亲测]ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问

    前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...

  5. [亲测]七步学会ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问

    前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...

  6. Centos 7.6配置nginx反向代理,直接yum安装

    一,实验介绍 利用三台centos7虚拟机搭建简单的nginx反向代理负载集群, 三台虚拟机地址及功能介绍 192.168.2.76    nginx负载均衡器 192.168.2.82    web ...

  7. Linux 笔记 - 第二十章 配置 Nginx 反向代理和负载均衡

    一.简介 由于 Nginx 的反向代理和负载均衡功能经常被提及,所以将这两个功能单独提出来进行讲解. Nginx 其实仅仅是作为 Nginx Proxy 反向代理使用的,因为这个反向代理功能表现的效果 ...

  8. node项目发布+域名及其二级域名配置+nginx反向代理+pm2

    学习node的时候也写了一些demo.但是只是限于本地测试,从来没有发布.今天尝试发布项目. 需要准备的东西 node 项目:为了突出重点,说明主要问题.我只是拿express 写了很简单的demo. ...

  9. ASP.NET Core 2.0发布/部署到Ubuntu服务器并配置Nginx反向代理

    原文链接https://www.linuxidc.com/Linux/2017-12/149557.htm ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用AS ...

随机推荐

  1. 自动化测试-11.selenium的下拉框处理类Select

    前言 最近由于工作原因,更新慢了一点,今天终于抽出一点时间给大家继续更新selenium系列,学习的脚本不能停止,希望小伙伴能多多支持. 本篇以百度设置下拉选项框为案例,详细介绍select下拉框相关 ...

  2. jQuery-2.DOM---节点的复制与替换

    DOM拷贝clone() 克隆节点是DOM的常见操作,jQuery提供一个clone方法,专门用于处理dom的克隆 .clone()方法深度 复制所有匹配的元素集合,包括所有匹配元素.匹配元素的下级元 ...

  3. SpringBoot配置SSL证书支持

    Spring Boot配置ssl证书 一.申请SSL证书 在各大云服务商都可以申请到SSL官方证书. 我这里是在阿里云上申请的,申请后下载,解压.如图:  二.用JDK中keytool是一个证书管理工 ...

  4. Parsing with Compositional Vector Grammars--paper

    这篇和2012年的区别: 1)Max-Margin Training Objective J中RNN变为了CVG 2012-两个词向量合并并打分,这个-两个(词向量,POS)合并并打分 2012年: ...

  5. LVS DR模式搭建、keepalived+lvs

    1.LVS DR模式搭建 条件: 即三台机器,在同一内网. 编辑脚本文件:/usr/local/sbin/lvs_dr.sh #! /bin/bashecho 1 > /proc/sys/net ...

  6. The Tower of Babylon(UVa 437)

    题意:有n种立方体,每种都有无穷多个.选一些正方体摞成一根尽量高的柱子(可以选择任意一条边做高),使得每个立方体的底面长宽分别严格小于它下方的立方柱的底面长宽. 题解:可以套用DAG最长路算法,可以使 ...

  7. 给大厨写的R数据分析代码

    ###************************************** 新老客户统计 ***************************************### dachu &l ...

  8. SpringBoot事务注解@Transactional

    SpringBoot提供了非常方便的事务操作,通过注解就可以实现事务的回滚,非常方便快捷,下面我们就说一下如何进行事务操作. 1. 事务说明 在Spring中,事务有两种实现方式,分别是编程式事务管理 ...

  9. py-day3-5 python 函数式编程

    # 函数式(方程式 y = 2*x+1) def calc(x): return 2*x+1 print('得出的结果:',calc(6)) 得出的结果: 13 # 面向过程 def calc(x): ...

  10. SpringData JPA框架使用时出现JSON循环依赖解决方案

    困扰许久的问题终于解决了,之前项目太赶,没有深入学习解决,不甘心,今天再次搭起架子试试,哈哈,终于解决! @ManyToOne(cascade={CascadeType.MERGE,CascadeTy ...