Harbor 无法登录:解决'unauthorized: authentication required' 错误

根据报错信息,需要进行身份验证才能访问 Harbor,因此需要先登录 Harbor 才能进行 docker push 和 pull 操作。

您提供的 Harbor 配置文件中,http 端口设置为 30001,因此在登录时需要使用 harbor.my.cn:30001,而不是 harbor.my.cn。

另外,您提供的 Nginx 配置文件中,监听端口为 28000,但是在 Harbor 配置文件中并没有设置该端口。如果您想要使用 Nginx 作为代理服务器,需要将 Harbor 的 http 端口设置为 80 或者其他与 Nginx 监听端口相同的端口。

修改后的 Harbor 配置文件如下:

hostname: harbor.my.cn

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80

external_url: http://harbor.my.cn

修改后的 Nginx 配置文件如下:

server {
    listen 28000;
    server_name harbor.my.cn;

    error_page 497 http://$host$request_uri;

    location / {
        proxy_pass http://127.0.0.1:80;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect http:// $scheme://;
        client_max_body_size 0;
        proxy_next_upstream error timeout http_500;
    }
}

然后重新启动 Harbor 和 Nginx,使用以下命令登录 Harbor:

docker login harbor.my.cn:30001

输入用户名和密码即可登录成功。

Harbor 无法登录:解决'unauthorized: authentication required'错误