首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cgit和Nginx URL重写

Cgit和Nginx URL重写
EN

Stack Overflow用户
提问于 2013-04-24 02:34:03
回答 2查看 2.1K关注 0票数 4

有线URL重写问题

当我去的时候

http://git.example.org/foo

效果很好,回复会出现。然而,该页面上的链接再次追加了/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,我错过了什么吗?

代码语言:javascript
复制
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=/的cgit设置,我也更新了我的nginx.conf,urls现在重写了!!

代码语言:javascript
复制
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;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-25 14:59:15

这与Nginx无关,在生成URL的代码中有一个bug。

http://git.example.org/foo页面上,有一个链接编写为:

代码语言:javascript
复制
<a href="foo/commit">Click to commit</a>

对于服务器来说,它应该是绝对的,因为:

代码语言:javascript
复制
<a href="/foo/commit">Click to commit</a>

或相对于当前目录,如:

代码语言:javascript
复制
<a href="commit">Click to commit</a>

大概是在代码中的某个地方,您插入了cgit,您正在foo中填充,您应该在其中传递/foo

票数 0
EN

Stack Overflow用户

发布于 2014-03-22 16:06:57

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16182421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档