Cgit and Nginx URL rewrite

2.2k views Asked by At

Wired URL rewriting issues

while I goto

http://git.example.org/foo

it works fine, repos shows up. However the links on that page appended /foo again i.e.

http://git.example.org/foo/foo/commit

When I goto URL like

http://git.example.org/foo/commit?id=123123

It works, but each links on that page looks like

http://git.example.org/foo/commit/foo/snapshot/foo/4f0be51d35fe3160a9122894723b69df69a6fb7e.zip?id=4f0be51d35fe3160a9122894723b69df69a6fb7e

Here is my nginx.conf, did I miss something?

server {
    listen 80;
    server_name git.example.org;
    root /var/www/htdocs/cgit;
    index cgit.cgi;

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

    if ($request_filename = cgit.cgi){
        rewrite ^/([^/]+/.*)$ /cgit.cgi?url=$1 last;
    }

    location / {
        try_files $uri @cgit;
    }

    location @cgit {
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_param SCRIPT_FILENAME $document_root/cgit.cgi;
        fastcgi_param HTTP_HOST $server_name;
        fastcgi_param PATH_INFO $uri;
        include fastcgi_params;

    }
    access_log /var/log/nginx/cgit_access.log;
    error_log /var/log/nginx/cgit_error.log warn;
}

Update, SOLVED

it's cgit setting of virtual-root=/ And I updated my nginx.conf too, urls rewrite works now!!

server {
        listen 80;
        server_name git.mengzhuo.org;
        root /var/www/htdocs/cgit;

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


        location / {
                index cgit.cgi;
                fastcgi_param SCRIPT_FILENAME $document_root/cgit.cgi;
                fastcgi_pass unix:/var/run/fcgiwrap.socket;
                fastcgi_param HTTP_HOST $server_name;
                fastcgi_param PATH_INFO $uri;
                fastcgi_param QUERY_INFO $uri;
                include "fastcgi_params";

        }
        access_log /var/log/nginx/cgit_access.log;
        error_log /var/log/nginx/cgit_error.log warn;
}
2

There are 2 answers

1
Danack On BEST ANSWER

This isn't anything to do with Nginx, there's a bug in the code generating your URLs.

On the page http://git.example.org/foo you have a link written as:

<a href="foo/commit">Click to commit</a>

It should either be absolute to the server as:

<a href="/foo/commit">Click to commit</a>

Or relative to the current directory as:

<a href="commit">Click to commit</a>

Presumably somewhere in the code where you init cgit you are pasing in foo where you should be passing in /foo.

0
AudioBubble On

Setting virtual-root=/ in /etc/cgitrc fixed the issue for me.