Git推送大量内容导致http 413错误

Git推送大量内容导致服务端HTTP 413错误

问题描述

使用git push 大量变更内容(超过60M)时报 http 413错误,详细错误信息:

Compressing objects: 100% (2907/2907), done.
Writing objects: 100% (6760/6760), 64.18 MiB | 1.18 GiB/s, done.
Total 6760 (delta 2480), reused 6760 (delta 2480), pack-reused 0
error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
Everything up-to-date

原因分析

HTTP 413错误表明请求体太大(Request Entity Too Large),服务器无法处理。这种错误通常与服务器设置有关,限制了可以接受的请求大小。在Git中,如果你尝试推送过大的内容,可能会遇到这个问题。

解决方法

服务端如果配置了Nginx来管理Web请求,则可通过client_max_body_size配置项来设置客户端请求体的大小。参考nginx官网的介绍:

Syntax: 	client_max_body_size size;
Default: 	client_max_body_size 1m;
Context: 	http, server, location

Sets the maximum allowed size of the client request body. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

如上所述,修改nginx配置,在server节点下,增加:client_max_body_size 100m;,将默认的1m放宽到100m,再执行nginx -s reload重新加载配置文件,问题解决。

当然,也可以主动减少推送文件大小,尝试改为分批推送。

另外,不使用http协议,改为git ssh协议来推送,也可以避免413错误。

参考

  • HTTP 413 curl 22 The requested URL returned error: 413解决方案
  • 【Nginx】解决413错误

你可能感兴趣的:(Linux,#,ubuntu,git,nginx)