I set up all the needed components for a Git server on Nginx using FastCGI and followed the combined suggestions of a few tutorials to end up with this configuration:

server {
  listen 80;
  listen [::]:80;

  server_name example.com www.example.com;

  return 301 https://example.com$request_uri;

server {
  listen 443 ssl;
  listen [::]:443 ssl;

  root /path/to/site;
  index index.html;

  server_name example.com www.example.com;

  # ... Some ssl stuff here ...

  location ~ /git(/.*) {
    auth_basic "Access denied";
    auth_basic_user_file /path/to/auth;

    client_max_body_size 0;

    fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;

    include fastcgi_params;

    fastcgi_param GIT_HTTP_EXPORT_ALL "";
    fastcgi_param GIT_PROJECT_ROOT /path/to/site/git;
    fastcgi_param PATH_INFO $1;
    fastcgi_param REMOTE_USER $remote_user;

    fastcgi_pass unix:/var/run/fcgiwrap.socket;

Using the window git client however, attempting to do anything to the repository found at https://example.com/git/test.git results in the following error on the client:

fatal: repository 'https://example.com/git/test.git/' not found

And this error on the server:

2016/01/07 16:59:05 [error] 5155#0: *579 FastCGI sent in stderr: "Not a git repository: '/path/to/site/git/test.git'" while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: example.com, request: "GET /git/test.git/info/refs?service=git-receive-pack HTTP/1.1", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "example.com"

Which is odd, because in the /git/test.git folder I had ran the git init --bare command previously so the repository is definitely there. I also tried chmod 0777 test.git -R in case it wasn't able to read the repository or something, but that had no effect.

I have tried many variants of the sameish configuration but I just do not understand what is going wrong here, so any help would be appreciated.

  • Did you manage to solve this finally? I'm having the same issue, and cannot find the answer :( – Dmitry Sep 13 '18 at 16:35
  • Finally it worked for me. Made a stupid mistake in the directory name. LOL. – Dmitry Sep 13 '18 at 23:07

Try running this in your git project folder (/path/to/site/git/test.git)

git --bare init
git update-server-info

This should prep the git directory and create the necessary files. You are just missing the second step, I think.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.