nginx git文件夹请求

时间:2016-02-21 00:58:52

标签: git nginx gitweb nginx-location

我使用的是nginx和git-web,效果很好。我使用www.mydomain.org访问我的网站以获取gitweb。这是我的配置文件:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name www.mydomain.org;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name www.mydomain.org;

    ssl on;
    ssl_certificate /etc/nginx/ssl/mydomain_org/www_mydomain_org.crt;
    ssl_certificate_key /etc/nginx/ssl/mydomain_org/www_mydomain_org.key;
    ssl_session_timeout 5m;
    #enables all versions of TLS, but not SSLv2 or 3 which are weak and now deprecated.
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    #Disables all weak ciphers
    ssl_ciphers "Cut it out cause it was very long in question";
    ssl_prefer_server_ciphers on;

    root /var/www/html;

    auth_basic           "Restricted";
    auth_basic_user_file git_access_list;

    location /html {
        root /var/www;
        index index.html;
        access_log off;
        expires max;
    }

    # static repo files for cloning over https
    location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ {
        root /media/drive1/gitrepo/;
    }

    # requests that need to go to git-http-backend
    location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
        root /media/drive1/gitrepo;

        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_param SCRIPT_FILENAME   /usr/lib/git-core/git-http-backend;
        fastcgi_param PATH_INFO         $uri;
        fastcgi_param GIT_PROJECT_ROOT  /media/drive1/gitrepo;
        fastcgi_param GIT_HTTP_EXPORT_ALL "";
        fastcgi_param REMOTE_USER $remote_user;
        include fastcgi_params;
    }

    # send anything else to gitweb if it's not a real file
    try_files $uri @gitweb;
    location @gitweb {
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_param SCRIPT_FILENAME   /usr/share/gitweb/gitweb.cgi;
        fastcgi_param PATH_INFO         $uri;
        fastcgi_param GITWEB_CONFIG     /etc/gitweb.conf;
        include fastcgi_params;
    }

    location /index.cgi {
        root /usr/share/gitweb;
        include fastcgi_params;
        gzip off;
        fastcgi_param SCRIPT_NAME $uri;
        fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }

    location / {
        root /usr/share/gitweb/;
        index index.cgi;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }
}

我想做的是有一个git子文件夹而不是ex: www.mydomain.org/git拉起gitweb主页。我不太确定如何改变它,有点卡住了。有关如何完成此任务的任何建议或提示?

由于

更新

我通过修改以下内容来解决这个问题:

    location /index.cgi {
        root /usr/share/gitweb;
        include fastcgi_params;
        gzip off;
        fastcgi_param SCRIPT_NAME $uri;
        fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }

    location / {
        root /usr/share/gitweb/;
        index index.cgi;
    }

    location /git/static/ {
            alias /usr/share/gitweb/static/;
    }

    location /git/ {

            auth_basic "Restricted";
            auth_basic_user_file git_access_list;

            alias /usr/share/gitweb/;
            fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/index.cgi;
            include fastcgi_params;
            gzip off;
            fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
            fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }

1 个答案:

答案 0 :(得分:1)

我在原始问题的更新中列出了我的解决方案。但是也会在这里添加:

location /git/static/ {
alias /usr/share/gitweb/static/;
}

location /git/ {

auth_basic "Restricted";
auth_basic_user_file git_access_list;

alias /usr/share/gitweb/;
fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/index.cgi;
include fastcgi_params;
gzip off;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}