Harbor - 413 Request Entity Too Large 问题
作者: ryan 发布于: 10/22/2025 更新于: 10/22/2025 字数: 0 字 阅读: 0 分钟
上传镜像出现413 Request Entity Too Large
bash
root@docker-proxy:~# docker push harbor-197.ceamg.cn/op/nginx:1.24.0
The push refers to repository [harbor-197.ceamg.cn/op/nginx]
6b5aaff44254: Pushing [===============> ] 65.69MB/209.2MB
53a0b163e995: Layer already exists
b626401ef603: Layer already exists
9b55156abf26: Pushing [==================================================>] 152MB/152MB
293d5db30c9f: Layer already exists
03127cdb479b: Layer already exists
9c742cd6c7a5: Pushing [==================================================>] 129.2MB
6b5aaff44254: Pushing [==================================================>] 209.2MB/209.2MB
unknown: <html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>openresty</center>
</body>
</html>
错误原因
该错误是由于 Harbor 底层使用的 openresty(基于 Nginx)默认限制了客户端请求体大小(仅 1MB) ,而 Docker 镜像层通常较大(如 6b5aaff44254 层为 209.2MB),导致推送失败。
解决方案
修改 Harbor 的 Nginx 配置文件
Harbor 通过 Nginx/openresty 代理请求,需在 Nginx 配置中增加 client_max_body_size 参数:
bash
# 进入 Harbor 的 Nginx 配置目录(使用 Docker 部署时)
# 通常在挂载的配置文件中,如 /harbor/nginx/conf/nginx.conf
# 在 http 或 server 块中添加:
http {
client_max_body_size 500M; # 设置为足够大的值(如 500MB 或 1G)
}
# 或在针对镜像推送的 location 块中:
location /v2/ {
client_max_body_size 0; # 0 表示无限制(谨慎使用)
proxy_pass http://registry:5000;
}重新加载 Nginx 配置
bash
# 若通过容器运行
docker exec harbor-nginx-container nginx -s reload
# 直接部署的 openresty
nginx -s reload
补充 Harbor 服务端限制调整
1. 修改 Harbor 核心配置 harbor.yml
在 Harbor 自身的配置中调整上传限制:
yaml
registry:
# 调整镜像层大小限制(单位字节)
maxblob: 500000000 # 500MB2. 重启 Harbor 服务
bash
docker-compose down && docker-compose up -d
