Fatal: protocol error: bad line length character: <htm

This error occurs when I use nginx reverse proxy gitea to execute git push. The problem is restored when I don’t use reverse proxy
gitealog

Nov 14 21:46:37 lingling gitea[27307]: 2022/11/14 21:46:37 [637246bd] router: completed GET /lingling/text66.git/info/refs?service=git-receive-pack for 2.56.255.82:0, 401 Unauthorized in 3.3ms @ repo/http.go:532(repo.GetInfoRefs)
Nov 14 21:46:37 lingling gitea[27307]: 2022/11/14 21:46:37 ...dules/git/command.go:153:Run() [D] [637246bd-2] /var/lib/gitea/data/gitea-repositories/lingling/text66.git: /usr/bin/git -c credential.helper= -c filter.lfs.required= -c filte
Nov 14 21:46:37 lingling gitea[27307]: 2022/11/14 21:46:37 [637246bd-2] router: completed GET /lingling/text66.git/info/refs?service=git-receive-pack for 2.56.255.82:0, 200 OK in 26.1ms @ repo/http.go:532(repo.GetInfoRefs)

nginx log

attempt to set status 403 via ngx.exit after sending out the response status 200

git error

Enumerating objects: 492, done.
Counting objects: 100% (492/492), done.
Delta compression using up to 12 threads
Compressing objects: 100% (414/414), done.
Writing objects: 100% (492/492), 229.61 KiB | 229.61 MiB/s, done.
Total 492 (delta 59), reused 492 (delta 59), pack-reused 0
fatal: protocol error: bad line length character: <htm
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly

What’s your nginx configuration?

my nginx conf

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

Did you ever get this fixed? I’m seeing the same issue with caddy as a reverse proxy.

@jham. Likewise. That’s exactly why I stopped using caddy.

I just figured out my problem, I was using an older git client on my Mac, 2.39.3 (Apple Git-146) from /usr/bin. I updated homebrew and changed my PATH to use it’s version, which is 2.46.0, and everything worked.