Harbor HTTP 使用Nginx代理为HTTPS

编程教程 > Docker Case (35) 2025-02-23 11:05:41

最终看起来像这样 nginx (host,ssl) -> harbor-nginx (non-ssl) -> harbor。

说明
首先服务上安装有 nginx,且配置了 SSL,现在可能在本机或者内网的其他机器上安装有 Harbor,需要反向代理到本机映射出去。

harbor.yml
首先需要注释掉 https 相关的配置,并添加 external_url 的配置项。

# .........忽略其他..............
# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
external_url: https://docker.example.com
# .........忽略其他..............

配置完成后重启harbor

sudo ./install.sh

 

nginx 配置文件  harbor.conf
在 nginx 的 vhost 中新增相关配置,必须要配置 X-Forwarded-Proto $scheme,client_max_body_size 按需配置。

server {
    listen       80;
    server_name  hub.example.cn;
    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen       443 ssl http2;
    server_name  docker.example.com;

    ssl_certificate      /usr/local/openresty/nginx/conf/ssl/hub.example.cn.crt;
    ssl_certificate_key  /usr/local/openresty/nginx/conf/ssl/hub.example.cn.key;

    client_max_body_size 500m;

    location / {
        proxy_pass http://192.168.1.2:5080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

配置完成后重新加载nginx配置

sudo nginx -s reload

或者docker版nginx

sudo docker exec -it nginx(容器id/名称) nginx -s reload

常见问题

docker login 出现 unauthorized: authentication required

harbor 内没有配置 external_url。

访问 hub.example.cn 会重定向到某个端口

harbor 内需要取消 https 的配置。

docker push 出现 400 The plain HTTP request was sent to HTTPS port

反向代理 nginx 中没有配置 X-Forwarded-Proto $scheme。

 

 

 


评论
User Image
提示:请评论与当前内容相关的回复,广告、推广或无关内容将被删除。

相关文章
最终看起来像这样 nginx (host,ssl) -&gtl; harbor-nginx (non-ssl) -&gtl; harbor。说明首先服务上安装有 nginx,且
下载harbor离线版打开GitHub上的harbor仓库地址https://github.com/goharbor/harbor/下载最新稳定离线版本上传harbor到服务器服务器创建目录/o...
接上一篇harbor2.10.x离线安装-xqlee(blog.xqlee.com)安装了http版本,禁用了https,然后发现使用的时候没有https各种不方便。随即研究了下https的处理
概述接前几篇harbor 2.10.x离线安装Harbor 镜像复制后,这里简述docker配合harbor私服镜像pull(拉取)和push(上传)操作示例。
接上一篇harbor安装,这里讲解如何上传镜像到harbor。因上篇安装的是基于http,所以在上传端的docker需要添加一个配置。 情况一 没有/etc/d
项目开发,各种中间件各种密码,简单了怕破解,复杂了根本记不住,那就忘了它,记录如何找回密码吧。这里讲harbor 2.0组件管理员admin密码找回办法。
项目设置清理策略进入harbor项目。 清理策略配置:保留7天拉取的镜像 规则生成说明:应用到仓库匹配**, 保留最近7天被拉取过的 artifacts基于条件
创建仓库登录管理员账户,仓库管理添加要去复制的仓库,例如:创建目标仓库访问id/访问密码根据目标仓库情况设定。添加完成后可以点击测试连接试试。创建镜像复制任务以
Nginx 安装Nginx 安装参考:Linux yum nginx安装和nginx入门配置方法-XQLEE'BlogAlpine Linux nginx安装配
Nginx 配置日志nginx默认的日志配置在nginx.conf配置文件。
前置说明,项目配置了个全局PATH,估计是为了方便复杂环境单容器多项目部署用的老项目配置方式var PATH = [[${#httpServletRequest.getScheme() + ":...
问题描述最近网站被运营商劫持很严重,忍受不了,全站上了HTTPS
nginx常规使用时作为http协议的反向代理,这里要讲的是非http的Mysql端口代理,理论支持其他协议nginx.conf配置如下:user nginx; worker_process...
nginx配置文件检查命令正确命令:nginx -t -c /etc/nginx/nginx.conf错误命令:nginx -t -c /etc/nginx/conf.d/example.con...
部署目录结构tree -a ././├── conf.d #nginx 自定义配置映射目录│ ├── default.conf #存放一些通用配置(可选)│ ├