💾 Archived View for ait.place › git_server.gmi captured on 2022-06-03 at 22:46:32. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-11-30)

-=-=-=-=-=-=-

How to setup a git server and serve trough https

There seems to not be a lot of documentaion on this topic on the internet. So here is a step by step guide to set up the server and let nginx/www-data and a git/ssh user pull form a directory.

I will NOT have the ability to push from https as I only really want ssh to be used for that. Find another guide if you want that ability.

Also I am currently writing this for Debian 11, but it should be similar on other distros.

Here is how to set up a git server and access it trough ssh. Follow this and come back:

https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

If the link does not work then what you want is basically the ability to clone the repo via ssh.

Dependencies

sudo apt install -y git nginx

Permissions

I presume that you have created a user named git. We want nginx to have access to the same folders that the git user have. We do so by adding nginx to the git group.

sudo usermod -a -G git www-data

Important to do

Cd into the git repo (examples /srv/git,/home/git) and run this command or else it won't work.

sudo git update-server-info

Setting up nginx

This is the most daunting, but interesting. How your nginx config will be very much depends on what your website looks like. I have a very uniqe setup, but I hope that you will be able to use some of it for your setup.

Here is a sample config that should do the job, but is not the one I use:

server {
	server_name ait.place www.ait.place

 	listen 80;
        listen [::]:80;

	# redirect .git links
        location ~ ^.*\.git($|/$) {
 		rewrite ^(.*)$ $1.git last;
        }

	# static repo files for cloning over https
	location ~ ^.*\.git(/.*$) {
                root /home/git;
                try_files $uri $uri/ =404;
        }
}

A "problem" with this solution is that the git repo/directory has to end in .git.

Also they have to use the .git extention when cloning.

Except for that, this seems like the best solution.

If you have any questions or it did not work. Then my E-Mail is open.