公司的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. 详解Makefile 函数的语法与使用 (转)

    使用函数: 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函数的返回值可以当做变量来使 ...

  2. php网站速度性能优化(转)

    一个网站的访问打开速度至关重要,特别是首页的打开加载过慢是致命性的,本文介绍关于php网站性能优化方面的实战案例:淘宝首页加载速度优化实践 .想必很多人都已经看到了新版的淘宝首页,它与以往不太一样,这 ...

  3. JAVA高级篇(一、JVM基本概念)

    一.什么是JVM VM的中文名称叫Java虚拟机,它是由软件技术模拟出计算机运行的一个虚拟的计算机. JVM也充当着一个翻译官的角色,我们编写出的Java程序,是不能够被操作系统所直接识别的,这时候J ...

  4. 百度前端代码规范:CSS

    1.代码风格 1.1 文件 [建议] CSS 文件使用无 BOM 的 UTF-8 编码. 1.2 缩进 [强制] 使用 4 个空格做为一个缩进层级,不允许使用 2 个空格 或 tab 字符. 1.3 ...

  5. 20155208徐子涵 Exp5 MSF基础应用

    20155208徐子涵 Exp5 MSF基础应用 基础问题回答 用自己的话解释什么是exploit,payload,encode. Exploit:Exploit 的英文意思就是利用,它在黑客眼里就是 ...

  6. 1.Python

    一.Python基础:1.第一句python文件后缀名:文件后缀名是.py2.两种执行方式:(1)把文件地址交给python解释器,python解释器去找到这个文件读到内存执行(2)进入解释器:解释器 ...

  7. lucas 模板 洛古模板题

    #include<bits/stdc++.h> #define int long long using namespace std; ; int a[maxn]; int quick(in ...

  8. BAT批处理文件,脚本时间值%time:~0,2%%time:~3,2%%time:~6,2%的用法。

    最近公司的项目,需要部署一个oracle定时备份脚本,删除掉特定时间前的备份文件.BAT批处理文件结合windows系统(任务计划程序) 正常情况下我们的任务计划会有反馈数值,通过它可以判断这个任务计 ...

  9. C# 利用反射完成计算器可扩展功能

    一个主要的窗体程序,两个输入框,一个label using System; using System.Collections.Generic; using System.ComponentModel; ...

  10. 剑指offer 3. 链表 从尾到头打印链表

    题目描述 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList. 解题思路:利用栈先进后出的原理,依次把ArrayList的值入栈,再出栈即可逆序 import java.util.Arra ...