公司的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. 小程序点击按钮清空input

    大致的思路是先给标签input设置一个value <input value="{{value}}" placeholder="最大输入长度10"/> ...

  2. nodeJS文件操作

    让前端觉得如获神器的不是NodeJS能做网络编程,而是NodeJS能够操作文件.小至文件查找,大至代码编译,几乎没有一个前端工具不操作文件.换个角度讲,几乎也只需要一些数据处理逻辑,再加上一些文件操作 ...

  3. Python全栈之路----数据类型—列表

    1.列表是一个数据的集合,集合内可以放任何数据类型,可对集合进行方便的增删改查操作.列表里面的数可以重复. L1 = [ ] #定义空列表 L2 = [ 'a' , 'b' , 'c' , 'd' ] ...

  4. 五分钟带你走入MP

    一.MyBatis-Plus简介 1.1MyBatis-Plus是什么? MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化 ...

  5. 概念:dependency injection, IOC, vs callback

    callback function as a dependency of the object that it is being passed into. DI is the process of p ...

  6. DL服务器主机环境配置(ubuntu14.04+GTX1080+cuda8.0)解决桌面重复登录

    DL服务器主机环境配置(ubuntu14.04+GTX1080+cuda8.0)解决桌面重复登录 前面部分是自己的记录,后面方案部分是成功安装驱动+桌面的正解 问题的开始在于:登录不了桌面,停留在重复 ...

  7. java 偏向锁、轻量级锁及重量级锁synchronized原理

    Java对象头与Monitor java对象头是实现synchronized的锁对象的基础,synchronized使用的锁对象是存储在Java对象头里的. 对象头包含两部分:Mark Word 和 ...

  8. Guava 1:概览

    一.引言 都说java是开源的,但是除了JDK外,能坚持更新且被广泛认可的开源jar包实在是不可多得.其中最显眼的自然是guava了,背靠google自然底气十足,今天就来解开guava的面纱,初探一 ...

  9. golang http proxy反向代理

    本文介绍golang中如何进行反向代理. 下面例子中, proxy server接收client 的 http request,转发给true server,并把 true server的返回结果再发 ...

  10. zip()函数,max()和min(),built-in function,import模块,read(),readlines(),write(),writelines(),with..as..文件处理方式

    zip()函数:将可迭代对象作为参数,将对象中的对应元素打包成一个个元组. #map()普通的输出例子 print(list(zip(('a','n','c'),(1,2,3)))) print(li ...