Cgit和Nginx URL重写

时间:2013-04-24 02:34:04

标签: nginx cgit

有线网址重写问题

我转到

  

http://git.example.org/foo

它工作正常,repos出现。但是,该页面上的链接再次附加/ foo 即

  

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

当我转到像

这样的网址时
  

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

它有效,但该页面上的每个链接都是

  

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

这是我的nginx.conf,我错过了什么吗?

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

更新,已解决

它的cgit设置为virtual-root = / 我也更新了我的nginx.conf,url重写现在正常工作!!

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 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

在页面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>

据推测,你在init {1}}的代码中某处你应该传入foo