为docker私有registry配置nginx反向代理
公司的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时碰到了同样的问题,希望这篇博客能帮到你,:)
- 顶
- 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时碰到了同样的问题,希望这篇博客能帮到你,:)
- 顶
- 0
- 踩
- 0
为docker私有registry配置nginx反向代理的更多相关文章
- CentOS 7 学习(二) 配置Nginx反向代理
CentOS 7 学习(二) 配置Nginx反向代理 Nginx可以通过php-fpm来运行PHP程序,也可以转向apache,让apache调用php程序来运行. 不过对于Nginx来说,其反向代理 ...
- 使用SSL配置Nginx反向代理的简单指南
反向代理是一个服务器,它接收通过Web发出的请求,即http和https,然后将它们发送到后端服务器(或服务器).后端服务器可以是单个或一组应用服务器,如Tomcat,wildfly或Jenkins等 ...
- 配置LANMP环境(7)-- 配置nginx反向代理,与配置apache虚拟主机
一.配置nginx反向代理 1.修改配置文件 vim /etc/nginx/nginx.conf 在35行http下添加一下内容: include /data/nginx/vhosts/*.conf; ...
- [亲测]ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问
前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...
- [亲测]七步学会ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问
前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...
- Centos 7.6配置nginx反向代理,直接yum安装
一,实验介绍 利用三台centos7虚拟机搭建简单的nginx反向代理负载集群, 三台虚拟机地址及功能介绍 192.168.2.76 nginx负载均衡器 192.168.2.82 web ...
- Linux 笔记 - 第二十章 配置 Nginx 反向代理和负载均衡
一.简介 由于 Nginx 的反向代理和负载均衡功能经常被提及,所以将这两个功能单独提出来进行讲解. Nginx 其实仅仅是作为 Nginx Proxy 反向代理使用的,因为这个反向代理功能表现的效果 ...
- node项目发布+域名及其二级域名配置+nginx反向代理+pm2
学习node的时候也写了一些demo.但是只是限于本地测试,从来没有发布.今天尝试发布项目. 需要准备的东西 node 项目:为了突出重点,说明主要问题.我只是拿express 写了很简单的demo. ...
- ASP.NET Core 2.0发布/部署到Ubuntu服务器并配置Nginx反向代理
原文链接https://www.linuxidc.com/Linux/2017-12/149557.htm ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用AS ...
随机推荐
- 自动化测试-16.selenium数据的分离之Excel的使用
前言 在自动化测试中,单纯写得测试脚本,数据往往是写死的,这样会给程序的可扩展性降低,以及成本的增加,将程序和数据进行剥离有利于提高代码的执行效率,提升工作量,因此将数据写入到Excel文件中,前置条 ...
- 如何用Python写一个每分每时每天的定时程序
1.计算生日是星期几 当你女朋友要过生日了,你肯定要定找家饭店订个餐庆祝一下,餐馆工作日会空一些,周末位置不好定,要是能知道她的生日是星期几就好了,下面这个程序就能搞定~~ 比如girl friend ...
- Sublime Keymap 设置
深深受 Emacs 组合键的影响,在编辑的时候使用组合键快速移动,而不比像 VIM 需要切换模式,但不得不吐槽 Emacs 的插件安装那个叫恶心,所以尝试了新生代产品 Sublime,但是还是离不开 ...
- Centos系统下 Gitolite安装与相关配置(git权限控制软件)
确保已经安装了最新版的git服务Git源码安装 Linux指定安装目录,并且创建了 用户名为git 的账户 修改.gitolite.rc #设置gitolite管理的仓库目录 GL_REPO_BAS ...
- [LeetCode&Python] Problem 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example ...
- github二次认证接收短信的问题
这两天登陆github都被提示说我账号的密码已经被归类,提醒我修改密码. 改密码的时候发现GitHub有个二次认证的功能,分别是app和sms短信认证.app这里就不讲了,我们讲一下github的短信 ...
- Linq分组查询统计
这里介绍Linq使用Group By和Count得到每个CategoryID中产品的数量,Linq使用Group By和Count得到每个CategoryID中断货产品的数量等方面. 学经常会遇到Li ...
- Linux服务安装配置总结
- 第二节《Git暂存区》
在上一节中我们的demo版本库经历了一次提交,我们可以使用git og --stat查看一下提交日志. [root@git demo]# git log --statcommit 986a1bd458 ...
- 【Python】hasattr() getattr() setattr() 使用方法详解
本文转自 https://www.cnblogs.com/cenyu/p/5713686.html hasattr(object, name)判断一个对象里面是否有name属性或者name方法,返回B ...