nginx git folder request

652 Views Asked by At

Im using nginx and git-web and it works great. I access my site using www.mydomain.org to pull up gitweb. Here is my config file:

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

What I would like to do is have a git sub folder instead ex: www.mydomain.org/git to pull up gitweb main page. Im not quite sure how to change it and kinda stuck. Any advise or tips on how to accomplish this?

Thanks

Update

I figured it out by modify the following:

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

To

    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

There are 1 best solutions below

0
On

I listed my solution in my update in my original question. But will add it here also:

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