3

Like many times, I used a virtual machine to test something. This is the reason why the configuration is maybe a bit dirty. I just try to get cgit running with nginx.

I created a directory /git (owner: www-data:www-data) which contains a git repository. My cgit configuration (/etc/cgitrc) is:

virtual-root=/htdocs/cgit/
css=/htdocs/cgit/cgit.css
logo=/htdocs/cgit/cgit.png
scan-path=/git

And I added the follwoing section to the default server in /etc/nginx/sites-available/default:

    location ~* ^.+\.(css|png|ico)$ {
        expires 30d;
    }

    location /htdocs/cgit/ {
        index cgit.cgi
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  /var/www/htdocs/cgit/cgit.cgi;
        fastcgi_pass   unix:/var/run/fcgiwrap.socket;
        fastcgi_param    PATH_INFO $uri;
        fastcgi_param    QUERY_STRING  $args;
        fastcgi_param  QUERY_STRING       $query_string;
        fastcgi_param  REQUEST_METHOD     $request_method;
        fastcgi_param  CONTENT_TYPE       $content_type;
        fastcgi_param  CONTENT_LENGTH     $content_length;
        fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
        fastcgi_param  REQUEST_URI        $request_uri;
        fastcgi_param  DOCUMENT_URI       $document_uri;
        fastcgi_param  DOCUMENT_ROOT      $document_root;
        fastcgi_param  SERVER_PROTOCOL    $server_protocol;
        fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
        fastcgi_param  SERVER_SOFTWARE    nginx;
        fastcgi_param  REMOTE_ADDR        $remote_addr;
        fastcgi_param  REMOTE_PORT        $remote_port;
        fastcgi_param  SERVER_ADDR        $server_addr;
        fastcgi_param  SERVER_PORT        $server_port;
        fastcgi_param  SERVER_NAME        $server_name;
        fastcgi_param  REMOTE_USER        $remote_user;
    }

If I open the browser now and open https://192.168.80.129/htdocs/cgit/, I can see the cgit interface. But there are no repositories. There is only a message no repository found.

Probably my configuration is not perfect, but it almost works. If I open the command line and execute su www-data -c /var/www/htdocs/cgit/cgit.cgi then I can see the repository which i created in /git:

[...]
</form></td></tr></table>
<div class='content'><table summary='repository list' class='list nowrap'><tr class='nohover'><th class='left'><a href='/htdocs/cgit/?s=name'>Name</a></th><th class='left'><a href='/htdocs/cgit/?s=desc'>Description</a></th><th class='left'><a href='/htdocs/cgit/?s=owner'>Owner</a></th><th class='left'><a href='/htdocs/cgit/?s=idle'>Idle</a></th></tr>
<tr><td class='toplevel-repo'><a title='yolo' href='/htdocs/cgit/yolo/'>yolo</a></td><td><a href='/htdocs/cgit/yolo/'>Unnamed repository; edit this file 'description' to name the repository.
</a></td><td>www-data</td><td><span class='age-mins'>9 min.</span></td></tr>
</table></div> <!-- class=content -->
<div class='footer'>generated  by cgit v0.9.1-27-gd5a4 at 2014-08-21 23:02:37 (GMT)</div>
</div> <!-- id=cgit -->
[...]

I thought maybe the "nginx-cgit" doesn't read the configuration file (/etc/cgitrc), but if I change the logo setting the logo in the webpage is also changed.

Unfortunately there is no information about this problem in /var/log/nginx/error.log and /var/log/nginx/access.log.

Thank you for any ideas.

--EDIT--

I tried and tried, but now i just installed gitphp (http://www.gitphp.org/) which seems to work without any problems.

Thanks:)

Kevin Meier
  • 131
  • 5
  • Are all the directories under `/git` owned by `www-data:www-data`? It also looks like that you are running some kind of FastCGI wrapper for the CGI script. Does the FastCGI wrapper run with `www-data` userid? – Tero Kilkanen Aug 22 '14 at 11:09
  • Yes, `fcgiwrap` runs with `www-data` and also `/git` and all subdirectories are owned by `www-data`. But now i just installed http://www.gitphp.org/, which seems to work fine. – Kevin Meier Aug 22 '14 at 11:52

1 Answers1

0

The problem is caused by fastcgi_param PATH_INFO $uri;. Suppose you visit http://example.com/htdocs/cgit/myrepo/ in an attempt to view your "myrepo" Git repository in cgit. $uri will be /htdocs/cgit/myrepo/. cgit sees that PATH_INFO is /htdocs/cgit/myrepo/. Since you have no Git repository named "htdocs", cgit will display "No repositories found". The correct PATH_INFO is supposed to be /myrepo/. In other words, you need to remove the /htdocs/cgit prefix from the $uri.

Nginx has a useful fastcgi_split_path_info directive that can help us here. In your case, replace the incorrect fastcgi_param PATH_INFO $uri; with the following:

fastcgi_split_path_info ^(/htdocs/cgit)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;

Credits:

Flux
  • 103
  • 4