4

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;
}
4

2 回答 2

1

virtual-root=//etc/cgitrc 中的设置为我解决了这个问题。

于 2014-03-22T16:06:57.653 回答
0

这与 Nginx 无关,生成 URL 的代码中存在错误。

在页面http://git.example.org/foo你有一个链接写成:

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

它对于服务器应该是绝对的:

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

或相对于当前目录为:

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

大概在你初始化 cgit 的代码中的某个地方,你正在foo传递你应该传递的地方/foo

于 2013-04-25T14:59:15.637 回答