2013-04-24 74 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=/解決了我的問題。