gitdockernginxgit-http-backend

fatal: repository not found, 404


Im trying do my own git server using git http backend. Im doing all of this using nginx and fcgiwrap. Im also using docker container not just host machine. So my nginx configuration looks like this:

        location /git {
            alias /srv/git;
            auth_basic "Restricted"; 
            auth_basic_user_file /etc/nginx/.gitpasswd; 
            fastcgi_pass unix:/var/run/fcgiwrap.socket;  
            include fastcgi_params; 
            fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
            fastcgi_param GIT_HTTP_EXPORT_ALL ""; 
            fastcgi_param GIT_PROJECT_ROOT /srv/git;  
            fastcgi_param PATH_INFO $uri;  

        }

My docker image in which nginx , git http backend and fcgiwrap work have Dockerfile and docker-entrypoint.sh for running fcgiwrap. They look like this:

Dockerfile

FROM ubuntu:24.04

RUN apt-get update && apt-get install -y \
    nginx \
    spawn-fcgi \
    fcgiwrap \
    git \
    git-core \
    libc6 \
    curl \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

docker-entrypoint.sh

#!/bin/bash

echo "Starting fcgiwrap..."
spawn-fcgi -s /var/run/fcgiwrap.socket /usr/sbin/fcgiwrap
if [ $? -ne 0 ]; then
    echo "Failed to start fcgiwrap" >&2
    exit 1
fi

ps aux | grep fcgiwrap

echo "Starting nginx..."
nginx -g "daemon off;"
if [ $? -ne 0 ]; then
    echo "Failed to start nginx" >&2
    exit 1
fi

Everything works perfectly when running. On my local machine im adding this remote url: https://user:password@domain.com/git/chatservice/ this is an example. And when trying to push im getting this error: fatal: unable to access 'https://user:password@domain.com/git/chatservice/' : repository not found 404.

I tried to check if git http-backend works yes it works, and i checked if wrapper runs it runs also, everything runs perfectly fine but nginx i think cant find route to this repository or it doesnt have permissions but i checked it does have but still not works i think. In nginx logs i see only that request with 404 made and thats it nothing else, not details.


Solution

  • I just added $1 instead of $uri in PATH info. Because when using reg exp git backend need only route to repository without /git/ so to directly take repo path i need to write $1