2013-04-24 95 views
3

有线URL重写问题CGT文件和Nginx的URL重写

而我转到

http://git.example.org/foo

它工作正常,回购协议显示出来。但是该网页上的链接附加/富再次 即

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

当我转到URL像

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

更新,解决了

这是虚拟的root =/ 的CGT文件设置和我更新了我的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; 
} 

回答

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你是pasin g在foo你应该通过/foo

+0

我已经通过在cgit中设置virtual-root = /解决了这个问题,现在一切正常。 – 2013-04-26 02:01:51

+0

然后随时接受答案。 – Danack 2013-04-26 16:23:45

1

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