Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I?m trying to setup CGit and NGINX. I'm almost there but I have a problem with the rewrite rule in my NGINX's conf file.

Currently I have this:

server {
    listen       80;
    index cgit.cgi;
    gzip off;

    root /usr/share/webapps/cgit;

    include fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME $document_root/cgit.cgi;

    location / {
        try_files $uri @cgit;

    location @cgit {
        auth_basic "Restricted";
        auth_basic_user_file /path/to/my/password_file;

        gzip off;
        rewrite ^/([^/]+/.*)?$ /cgit.cgi?url=$1 break;
        fastcgi_pass    fcgiwrap;

I understand that the URL when I'm looking at demo_repo_1.git should look like (or something similar?) but instead it looks like, and it doesn't work (as in cgit.cgi script can't read the correct data from the URL and can't show the right information about my repos.

Also, if I force the URL that I think it should be (copy&paste the "right" URL in my browser) the cgit.cgi script gets downloaded.

Can I get some help with that rewrite rule, please?

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.